Coverage Report - org.webslinger.commons.vfs.util.FileAttributeEntrySet
 
Classes in this File Line Coverage Branch Coverage Complexity
FileAttributeEntrySet
32%
8/25
40%
2/5
0
FileAttributeEntrySet$1
50%
1/2
N/A
0
 
 1  
 package org.webslinger.commons.vfs.util;
 2  
 
 3  
 import java.util.Collection;
 4  
 import java.util.Map;
 5  
 import java.util.Set;
 6  
 import java.lang.reflect.Array;
 7  
 
 8  
 import org.webslinger.lang.ObjectUtil;
 9  
 
 10  
 import org.apache.commons.vfs.FileObject;
 11  
 
 12  
 public class FileAttributeEntrySet<F extends FileObject, T> extends FileAttributeCollection<F, T> implements Set<T> {
 13  
     public FileAttributeEntrySet(FileAttributeMap<F> fam) {
 14  28
         super(fam, new IteratorRemover() {
 15  
             public boolean remove(Object o) {
 16  0
                 throw new UnsupportedOperationException("remove");
 17  
             }
 18  
         });
 19  28
     }
 20  
 
 21  
     public boolean add(T o) {
 22  0
         throw new UnsupportedOperationException("add");
 23  
     }
 24  
 
 25  
     public boolean addAll(Collection<? extends T> c) {
 26  0
         throw new UnsupportedOperationException("addAll");
 27  
     }
 28  
 
 29  
     public boolean contains(Object o) {
 30  0
         if (!(o instanceof Map.Entry)) return false;
 31  0
         Map.Entry entry = (Map.Entry) o;
 32  0
         if (!(entry.getKey() instanceof String)) return false;
 33  0
         String name = (String) entry.getKey();
 34  
         try {
 35  0
             if (!resolver.attributeExists(getFile(), name)) return false;
 36  0
         } catch (Exception e) {
 37  0
             return false;
 38  0
         }
 39  
         try {
 40  0
             return ObjectUtil.equalsHelper(entry.getValue(), resolver.getAttribute(getFile(), name));
 41  0
         } catch (Exception e) {
 42  0
             return false;
 43  
         }
 44  
     }
 45  
 
 46  
     public <T> T[] toArray(T[] array) {
 47  
         try {
 48  28
             String[] names = resolver.getAttributeNames(getFile());
 49  28
             if (array.length < names.length) array = (T[]) Array.newInstance(array.getClass().getComponentType(), names.length);
 50  28
             Object[] result = array;
 51  77
             for (int i = 0; i < names.length; i++) {
 52  49
                 result[i] = new FileAttributeEntry<F>(this, names[i]);
 53  
             }
 54  28
             return array;
 55  0
         } catch (RuntimeException e) {
 56  0
             throw e;
 57  0
         } catch (Exception e) {
 58  0
             return null;
 59  
         }
 60  
     }
 61  
 }
 62