1 19 package gnu.trove.decorator; 20 21 import gnu.trove.TByteHashSet; 22 import gnu.trove.TByteIterator; 23 import java.util.AbstractSet; 24 import java.util.Collection; 25 import java.util.Iterator; 26 import java.util.Set; 27 28 45 public class TByteHashSetDecorator extends AbstractSet implements Set, Cloneable { 46 47 protected TByteHashSet _set; 48 49 52 public TByteHashSetDecorator(TByteHashSet set) { 53 super(); 54 this._set = set; 55 } 56 57 64 public Object clone() { 65 try { 66 TByteHashSetDecorator copy = (TByteHashSetDecorator) super.clone(); 67 copy._set = (TByteHashSet) _set.clone(); 68 return copy; 69 } catch (CloneNotSupportedException e) { 70 throw new InternalError(); } 73 } 74 75 80 public boolean add(Object value) { 81 return _set.add(unwrap(value)); 82 } 83 84 91 public boolean equals(Object other) { 92 if (_set.equals(other)) { 93 return true; } else if (other instanceof Set) { 95 Set that = (Set)other; 96 if (that.size() != _set.size()) { 97 return false; } else { Iterator it = that.iterator(); 100 for (int i = that.size(); i-- > 0;) { 101 Object val = it.next(); 102 if (val instanceof Byte) { 103 byte v = unwrap(val); 104 if (_set.contains(v)) { 105 } else { 107 return false; } 109 } else { 110 return false; } 112 } 113 return true; } 115 } else { 116 return false; 117 } 118 } 119 120 123 public void clear() { 124 this._set.clear(); 125 } 126 127 133 public boolean remove(Object value) { 134 return _set.remove(unwrap(value)); 135 } 136 137 142 public Iterator iterator() { 143 return new Iterator() { 144 private final TByteIterator it = _set.iterator(); 145 146 public Object next() { 147 return wrap(it.next()); 148 } 149 150 public boolean hasNext() { 151 return it.hasNext(); 152 } 153 154 public void remove() { 155 it.remove(); 156 } 157 }; 158 } 159 160 164 public int size() { 165 return this._set.size(); 166 } 167 168 172 public boolean isEmpty() { 173 return (size() == 0); 174 } 175 176 182 protected Byte wrap(byte k) { 183 return new Byte(k); 184 } 185 186 192 protected byte unwrap(Object value) { 193 return ((Byte)value).byteValue(); 194 } 195 } | Popular Tags |