1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections.primitives;
18
19
20
21
22
23
24
25
26
27
28
29
30
31 public abstract class AbstractBooleanCollection implements BooleanCollection {
32 public abstract BooleanIterator iterator();
33 public abstract int size();
34
35 protected AbstractBooleanCollection() { }
36
37
38 public boolean add(boolean element) {
39 throw new UnsupportedOperationException(
40 "add(boolean) is not supported.");
41 }
42
43 public boolean addAll(BooleanCollection c) {
44 boolean modified = false;
45 for(BooleanIterator iter = c.iterator(); iter.hasNext(); ) {
46 modified |= add(iter.next());
47 }
48 return modified;
49 }
50
51 public void clear() {
52 for(BooleanIterator iter = iterator(); iter.hasNext();) {
53 iter.next();
54 iter.remove();
55 }
56 }
57
58 public boolean contains(boolean element) {
59 for(BooleanIterator iter = iterator(); iter.hasNext();) {
60 if(iter.next() == element) {
61 return true;
62 }
63 }
64 return false;
65 }
66
67 public boolean containsAll(BooleanCollection c) {
68 for(BooleanIterator iter = c.iterator(); iter.hasNext();) {
69 if(!contains(iter.next())) {
70 return false;
71 }
72 }
73 return true;
74 }
75
76 public boolean isEmpty() {
77 return (0 == size());
78 }
79
80 public boolean removeElement(boolean element) {
81 for(BooleanIterator iter = iterator(); iter.hasNext();) {
82 if(iter.next() == element) {
83 iter.remove();
84 return true;
85 }
86 }
87 return false;
88 }
89
90 public boolean removeAll(BooleanCollection c) {
91 boolean modified = false;
92 for(BooleanIterator iter = c.iterator(); iter.hasNext(); ) {
93 modified |= removeElement(iter.next());
94 }
95 return modified;
96 }
97
98 public boolean retainAll(BooleanCollection c) {
99 boolean modified = false;
100 for(BooleanIterator iter = iterator(); iter.hasNext();) {
101 if(!c.contains(iter.next())) {
102 iter.remove();
103 modified = true;
104 }
105 }
106 return modified;
107 }
108
109 public boolean[] toArray() {
110 boolean[] array = new boolean[size()];
111 int i = 0;
112 for(BooleanIterator iter = iterator(); iter.hasNext();) {
113 array[i] = iter.next();
114 i++;
115 }
116 return array;
117 }
118
119 public boolean[] toArray(boolean[] a) {
120 if(a.length < size()) {
121 return toArray();
122 } else {
123 int i = 0;
124 for(BooleanIterator iter = iterator(); iter.hasNext();) {
125 a[i] = iter.next();
126 i++;
127 }
128 return a;
129 }
130 }
131 }