| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 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.ShortCollection; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | 1978 | abstract class AbstractShortCollectionCollection implements Collection { |
| 31 | |
|
| 32 | |
public boolean add(Object element) { |
| 33 | 212 | return getShortCollection().add(((Number)element).shortValue()); |
| 34 | |
} |
| 35 | |
|
| 36 | |
public boolean addAll(Collection c) { |
| 37 | 954 | return getShortCollection().addAll(CollectionShortCollection.wrap(c)); |
| 38 | |
} |
| 39 | |
|
| 40 | |
public void clear() { |
| 41 | 14 | getShortCollection().clear(); |
| 42 | 14 | } |
| 43 | |
|
| 44 | |
public boolean contains(Object element) { |
| 45 | 1263 | return getShortCollection().contains(((Number)element).shortValue()); |
| 46 | |
} |
| 47 | |
|
| 48 | |
|
| 49 | |
public boolean containsAll(Collection c) { |
| 50 | 49 | return getShortCollection().containsAll(CollectionShortCollection.wrap(c)); |
| 51 | |
} |
| 52 | |
|
| 53 | |
public String toString() { |
| 54 | 14 | return getShortCollection().toString(); |
| 55 | |
} |
| 56 | |
|
| 57 | |
public boolean isEmpty() { |
| 58 | 3003 | return getShortCollection().isEmpty(); |
| 59 | |
} |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
public Iterator iterator() { |
| 69 | 9117 | return ShortIteratorIterator.wrap(getShortCollection().iterator()); |
| 70 | |
} |
| 71 | |
|
| 72 | |
public boolean remove(Object element) { |
| 73 | 318 | return getShortCollection().removeElement(((Number)element).shortValue()); |
| 74 | |
} |
| 75 | |
|
| 76 | |
public boolean removeAll(Collection c) { |
| 77 | 42 | return getShortCollection().removeAll(CollectionShortCollection.wrap(c)); |
| 78 | |
} |
| 79 | |
|
| 80 | |
public boolean retainAll(Collection c) { |
| 81 | 49 | return getShortCollection().retainAll(CollectionShortCollection.wrap(c)); |
| 82 | |
} |
| 83 | |
|
| 84 | |
public int size() { |
| 85 | 7068 | return getShortCollection().size(); |
| 86 | |
} |
| 87 | |
|
| 88 | |
public Object[] toArray() { |
| 89 | 3306 | short[] a = getShortCollection().toArray(); |
| 90 | 3306 | Object[] A = new Object[a.length]; |
| 91 | 52035 | for(int i=0;i<a.length;i++) { |
| 92 | 48729 | A[i] = new Short(a[i]); |
| 93 | |
} |
| 94 | 3306 | return A; |
| 95 | |
} |
| 96 | |
|
| 97 | |
public Object[] toArray(Object[] A) { |
| 98 | 35 | short[] a = getShortCollection().toArray(); |
| 99 | 35 | if(A.length < a.length) { |
| 100 | 21 | A = (Object[])(Array.newInstance(A.getClass().getComponentType(), a.length)); |
| 101 | |
} |
| 102 | 240 | for(int i=0;i<a.length;i++) { |
| 103 | 219 | A[i] = new Short(a[i]); |
| 104 | |
} |
| 105 | 21 | if(A.length > a.length) { |
| 106 | 7 | A[a.length] = null; |
| 107 | |
} |
| 108 | |
|
| 109 | 21 | return A; |
| 110 | |
} |
| 111 | |
|
| 112 | |
protected abstract ShortCollection getShortCollection(); |
| 113 | |
} |