Coverage Report - org.webslinger.commons.vfs.util.FileAttributeEntry
 
Classes in this File Line Coverage Branch Coverage Complexity
FileAttributeEntry
29%
10/35
17%
1/6
0
 
 1  
 package org.webslinger.commons.vfs.util;
 2  
 
 3  
 import java.util.Map;
 4  
 
 5  
 import org.apache.commons.vfs.FileObject;
 6  
 
 7  49
 public final class FileAttributeEntry<F extends FileObject> extends FileAttributeBaseWrapper<F> implements Map.Entry<String, Object> {
 8  
     private String name;
 9  
     private boolean removed;
 10  
 
 11  
     public FileAttributeEntry(FileAttributeBaseWrapper<F> wrapper, String name) {
 12  49
         super(wrapper);
 13  49
         this.name = name;
 14  49
     }
 15  
 
 16  
     public void removedFromIterator() {
 17  0
         removed = true;
 18  0
     }
 19  
 
 20  
     protected void checkRemoved() {
 21  98
         if (removed) throw new IllegalStateException("removed");
 22  98
     }
 23  
 
 24  
     public Object setValue(Object value) {
 25  0
         checkRemoved();
 26  
         try {
 27  0
             F file = getFile();
 28  0
             Object oldValue = resolver.getAttribute(file, name);
 29  0
             resolver.setAttribute(file, name, value);
 30  0
             return oldValue;
 31  0
         } catch (Exception e) {
 32  0
             throw (IllegalArgumentException) new IllegalArgumentException().initCause(e);
 33  
         }
 34  
     }
 35  
 
 36  
     public String getKey() {
 37  49
         checkRemoved();
 38  49
         return name;
 39  
     }
 40  
 
 41  
     public Object getValue() {
 42  49
         checkRemoved();
 43  
         try {
 44  49
             return resolver.getAttribute(getFile(), name);
 45  0
         } catch (Exception e) {
 46  0
             throw (IllegalArgumentException) new IllegalArgumentException().initCause(e);
 47  
         }
 48  
     }
 49  
 
 50  
     public boolean equals(Object o) {
 51  0
         checkRemoved();
 52  0
         if (!(o instanceof FileAttributeEntry)) return false;
 53  0
         FileAttributeEntry fae = (FileAttributeEntry) o;
 54  0
         if (name.equals(fae.name)) return true;
 55  0
         Object value = getValue();
 56  0
         Object otherValue = fae.getValue();
 57  0
         if (value == null) {
 58  0
             if (otherValue == null) return true;
 59  0
             return false;
 60  
         } else {
 61  0
             return value.equals(otherValue);
 62  
         }
 63  
     }
 64  
 
 65  
     public int hashCode() {
 66  0
         int hashCode = name.hashCode();
 67  0
         Object value = getValue();
 68  0
         if (value != null) hashCode ^= value.hashCode();
 69  0
         return hashCode;
 70  
     }
 71  
 }
 72