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