Coverage Report - org.webslinger.commons.vfs.util.FileAttributeMap
 
Classes in this File Line Coverage Branch Coverage Complexity
FileAttributeMap
7%
4/58
0%
0/6
0
 
 1  
 package org.webslinger.commons.vfs.util;
 2  
 
 3  
 import java.io.IOException;
 4  
 import java.util.Collection;
 5  
 import java.util.Map;
 6  
 import java.util.NoSuchElementException;
 7  
 import java.util.Set;
 8  
 
 9  
 import org.apache.commons.vfs.FileObject;
 10  
 
 11  0
 public final class FileAttributeMap<F extends FileObject> extends FileAttributeBaseWrapper<F> implements Map<String, Object> {
 12  
     public FileAttributeMap(F file, FileAttributeResolver<F> resolver) {
 13  7125
         super(file, resolver);
 14  7125
     }
 15  
 
 16  
     public void clear() {
 17  
         try {
 18  0
             F file = getFile();
 19  0
             for (String name: resolver.getAttributeNames(file)) {
 20  0
                 resolver.removeAttribute(file, name);
 21  
             }
 22  0
         } catch (Exception e) {
 23  0
         }
 24  0
     }
 25  
 
 26  
     public boolean containsKey(Object key) {
 27  
         try {
 28  0
             return resolver.attributeExists(getFile(), (String) key);
 29  0
         } catch (Exception e) {
 30  0
             return false;
 31  
         }
 32  
     }
 33  
 
 34  
     public boolean containsValue(Object value) {
 35  0
         throw new UnsupportedOperationException("containsValue");
 36  
     }
 37  
 
 38  
     public Set<Map.Entry<String, Object>> entrySet() {
 39  28
         return new FileAttributeEntrySet<F, Map.Entry<String, Object>>(this);
 40  
     }
 41  
 
 42  
     public boolean equals(Object other) {
 43  0
         if (!(other instanceof FileAttributeMap)) return false;
 44  0
         FileAttributeMap fam = (FileAttributeMap) other;
 45  0
         return resolver.equals(fam.resolver);
 46  
     }
 47  
 
 48  
     public Object get(Object key) {
 49  
         try {
 50  0
             return resolver.getAttribute(getFile(), (String) key);
 51  0
         } catch (Exception e) {
 52  0
             return null;
 53  
         }
 54  
     }
 55  
 
 56  
     public int hashCode() {
 57  0
         return getClass().hashCode() ^ resolver.hashCode();
 58  
     }
 59  
 
 60  
     public boolean isEmpty() {
 61  0
         return size() == 0;
 62  
     }
 63  
 
 64  
     public Set<String> keySet() {
 65  0
         return new FileAttributeKeySet<F, String>(this);
 66  
     }
 67  
 
 68  
     public Object put(String key, Object value) {
 69  
         try {
 70  0
             F file = getFile();
 71  0
             Object oldValue = resolver.getAttribute(file, key);
 72  0
             resolver.setAttribute(file, key, value);
 73  0
             return oldValue;
 74  0
         } catch (Exception e) {
 75  0
             return null;
 76  
         }
 77  
     }
 78  
 
 79  
     public void putAll(Map<? extends String, ? extends Object> map) {
 80  0
         F file = getFile();
 81  
         try {
 82  0
             for (Map.Entry<? extends String, ? extends Object> entry: map.entrySet()) {
 83  0
                 resolver.setAttribute(file, entry.getKey(), entry.getValue());
 84  
             }
 85  0
         } catch (IOException e) {
 86  0
         } catch (NoSuchElementException e) {
 87  
             // ignore
 88  0
         } catch (Exception e) {
 89  0
         }
 90  0
     }
 91  
 
 92  
     public Object remove(Object key) {
 93  
         try {
 94  0
             F file = getFile();
 95  0
             Object oldValue = resolver.getAttribute(file, (String) key);
 96  0
             resolver.removeAttribute(file, (String) key);
 97  0
             return oldValue;
 98  0
         } catch (Exception e) {
 99  0
             return null;
 100  
         }
 101  
     }
 102  
 
 103  
     public int size() {
 104  
         try {
 105  15
             return resolver.getAttributeNames(getFile()).length;
 106  0
         } catch (Exception e) {
 107  0
             return 0;
 108  
         }
 109  
     }
 110  
 
 111  
     public Collection<Object> values() {
 112  0
         return null;
 113  
     }
 114  
 
 115  
     public String toString() {
 116  
         try {
 117  0
             F file = getFile();
 118  0
             String[] names = resolver.getAttributeNames(file);
 119  0
             StringBuilder sb = new StringBuilder();
 120  0
             sb.append('{');
 121  0
             for (int i = 0; i < names.length; i++) {
 122  0
                 if (i != 0) sb.append(", ");
 123  0
                 sb.append(names[i]).append('=').append(resolver.getAttribute(file, names[i]));
 124  
             }
 125  0
             sb.append('}');
 126  0
             return sb.toString();
 127  0
         } catch (Exception e) {
 128  0
             throw (InternalError) new InternalError(e.getMessage()).initCause(e);
 129  
         }
 130  
     }
 131  
 }
 132