1 17 package org.apache.commons.collections.primitives.adapters; 18 19 import java.lang.reflect.Array ; 20 import java.util.Collection ; 21 import java.util.Iterator ; 22 23 import org.apache.commons.collections.primitives.FloatCollection; 24 25 30 abstract class AbstractFloatCollectionCollection implements Collection { 31 32 public boolean add(Object element) { 33 return getFloatCollection().add(((Number )element).floatValue()); 34 } 35 36 public boolean addAll(Collection c) { 37 return getFloatCollection().addAll(CollectionFloatCollection.wrap(c)); 38 } 39 40 public void clear() { 41 getFloatCollection().clear(); 42 } 43 44 public boolean contains(Object element) { 45 return getFloatCollection().contains(((Number )element).floatValue()); 46 } 47 48 49 public boolean containsAll(Collection c) { 50 return getFloatCollection().containsAll(CollectionFloatCollection.wrap(c)); 51 } 52 53 public String toString() { 54 return getFloatCollection().toString(); 55 } 56 57 public boolean isEmpty() { 58 return getFloatCollection().isEmpty(); 59 } 60 61 68 public Iterator iterator() { 69 return FloatIteratorIterator.wrap(getFloatCollection().iterator()); 70 } 71 72 public boolean remove(Object element) { 73 return getFloatCollection().removeElement(((Number )element).floatValue()); 74 } 75 76 public boolean removeAll(Collection c) { 77 return getFloatCollection().removeAll(CollectionFloatCollection.wrap(c)); 78 } 79 80 public boolean retainAll(Collection c) { 81 return getFloatCollection().retainAll(CollectionFloatCollection.wrap(c)); 82 } 83 84 public int size() { 85 return getFloatCollection().size(); 86 } 87 88 public Object [] toArray() { 89 float[] a = getFloatCollection().toArray(); 90 Object [] A = new Object [a.length]; 91 for(int i=0;i<a.length;i++) { 92 A[i] = new Float (a[i]); 93 } 94 return A; 95 } 96 97 public Object [] toArray(Object [] A) { 98 float[] a = getFloatCollection().toArray(); 99 if(A.length < a.length) { 100 A = (Object [])(Array.newInstance(A.getClass().getComponentType(), a.length)); 101 } 102 for(int i=0;i<a.length;i++) { 103 A[i] = new Float (a[i]); 104 } 105 if(A.length > a.length) { 106 A[a.length] = null; 107 } 108 109 return A; 110 } 111 112 protected abstract FloatCollection getFloatCollection(); 113 } 114 | Popular Tags |