1 19 package bak.pcj.adapter; 20 21 import bak.pcj.Adapter; 22 import bak.pcj.AbstractBooleanCollection; 23 import bak.pcj.BooleanIterator; 24 import bak.pcj.util.Exceptions; 25 import java.util.Collection ; 26 import java.util.AbstractCollection ; 27 import java.util.Iterator ; 28 29 64 public class CollectionToBooleanCollectionAdapter extends AbstractBooleanCollection { 65 66 67 protected Collection collection; 68 69 83 public CollectionToBooleanCollectionAdapter(Collection collection) { 84 this(collection, false); 85 } 86 87 111 public CollectionToBooleanCollectionAdapter(Collection collection, boolean validate) { 112 super(); 113 if (collection == null) 114 Exceptions.nullArgument("collection"); 115 this.collection = collection; 116 if (validate) 117 evalidate(); 118 } 119 120 public boolean add(boolean v) 121 { return collection.add(new Boolean (v)); } 122 123 public void clear() 124 { collection.clear(); } 125 126 public boolean contains(boolean v) 127 { return collection.contains(new Boolean (v)); } 128 129 public int hashCode() 130 { return collection.hashCode(); } 131 132 public BooleanIterator iterator() 133 { return new IteratorToBooleanIteratorAdapter(collection.iterator()); } 134 135 public boolean remove(boolean v) 136 { return collection.remove(new Boolean (v)); } 137 138 public int size() 139 { return collection.size(); } 140 141 150 public boolean validate() 151 { return Adapter.isBooleanAdaptable(collection); } 152 153 162 public void evalidate() { 163 if (!validate()) 164 Exceptions.cannotAdapt("collection"); 165 } 166 167 } | Popular Tags |