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.BooleanCollection;
24
25
26
27
28
29 abstract class AbstractBooleanCollectionCollection implements Collection {
30
31 public boolean add(Object element) {
32 return getBooleanCollection().add(((Boolean)element).booleanValue());
33 }
34
35 public boolean addAll(Collection c) {
36 return getBooleanCollection()
37 .addAll(CollectionBooleanCollection.wrap(c));
38 }
39
40 public void clear() {
41 getBooleanCollection().clear();
42 }
43
44 public boolean contains(Object element) {
45 return getBooleanCollection()
46 .contains(((Boolean)element).booleanValue());
47 }
48
49
50 public boolean containsAll(Collection c) {
51 return getBooleanCollection().containsAll(CollectionBooleanCollection.wrap(c));
52 }
53
54 public String toString() {
55 return getBooleanCollection().toString();
56 }
57
58 public boolean isEmpty() {
59 return getBooleanCollection().isEmpty();
60 }
61
62
63
64
65
66
67
68
69 public Iterator iterator() {
70 return BooleanIteratorIterator.wrap(getBooleanCollection().iterator());
71 }
72
73 public boolean remove(Object element) {
74 return getBooleanCollection().removeElement(
75 ((Boolean)element).booleanValue());
76 }
77
78 public boolean removeAll(Collection c) {
79 return getBooleanCollection()
80 .removeAll(CollectionBooleanCollection.wrap(c));
81 }
82
83 public boolean retainAll(Collection c) {
84 return getBooleanCollection().
85 retainAll(CollectionBooleanCollection.wrap(c));
86 }
87
88 public int size() {
89 return getBooleanCollection().size();
90 }
91
92 public Object[] toArray() {
93 boolean[] a = getBooleanCollection().toArray();
94 Object[] A = new Object[a.length];
95 for(int i=0;i<a.length;i++) {
96 A[i] = new Boolean(a[i]);
97 }
98 return A;
99 }
100
101 public Object[] toArray(Object[] A) {
102 boolean[] a = getBooleanCollection().toArray();
103 if(A.length < a.length) {
104 A = (Object[])(Array.newInstance(A.getClass().getComponentType(), a.length));
105 }
106 for(int i=0;i<a.length;i++) {
107 A[i] = new Boolean(a[i]);
108 }
109 if(A.length > a.length) {
110 A[a.length] = null;
111 }
112
113 return A;
114 }
115
116 protected abstract BooleanCollection getBooleanCollection();
117 }