1 19 package bak.pcj.adapter; 20 21 import bak.pcj.BooleanCollection; 22 import bak.pcj.util.Exceptions; 23 import java.util.Collection ; 24 import java.util.AbstractCollection ; 25 import java.util.Iterator ; 26 27 41 public class BooleanCollectionToCollectionAdapter extends AbstractCollection { 42 43 44 protected BooleanCollection collection; 45 46 56 public BooleanCollectionToCollectionAdapter(BooleanCollection collection) { 57 super(); 58 if (collection == null) 59 Exceptions.nullArgument("collection"); 60 this.collection = collection; 61 } 62 63 84 public boolean add(Object o) { 85 if (o == null) 86 Exceptions.nullElementNotAllowed(); 87 return collection.add(((Boolean )o).booleanValue()); 88 } 89 90 98 public void clear() 99 { collection.clear(); } 100 101 115 public boolean contains(Object o) { 116 try { 117 return collection.contains(((Boolean )o).booleanValue()); 118 } catch (ClassCastException cce) { 119 } catch (NullPointerException npe) { 120 } 121 return false; 122 } 123 124 129 public Iterator iterator() 130 { return new BooleanIteratorToIteratorAdapter(collection.iterator()); } 131 132 150 public boolean remove(Object o) { 151 try { 152 return collection.remove(((Boolean )o).booleanValue()); 153 } catch (ClassCastException cce) { 154 } catch (NullPointerException npe) { 155 } 156 return false; 157 } 158 159 184 public boolean removeAll(Collection c) { 185 if (c == null) 186 Exceptions.nullArgument("collection"); 187 return super.removeAll(c); 188 } 189 190 216 public boolean retainAll(Collection c) { 217 if (c == null) 218 Exceptions.nullArgument("collection"); 219 return super.retainAll(c); 220 } 221 222 229 public int size() 230 { return collection.size(); } 231 232 238 public int hashCode() 239 { return collection.hashCode(); } 240 241 } | Popular Tags |