61 |
|
|
62 |
public EnumSet<T> clone() |
public EnumSet<T> clone() |
63 |
{ |
{ |
64 |
EnumSet<T> r = super.clone(); |
try |
65 |
r.store = store.clone(); |
{ |
66 |
return r; |
EnumSet<T> r = (EnumSet<T>) super.clone(); |
67 |
|
r.store = (BitSet) store.clone(); |
68 |
|
return r; |
69 |
|
} |
70 |
|
catch (CloneNotSupportedException _) |
71 |
|
{ |
72 |
|
// Can't happen. |
73 |
|
return null; |
74 |
|
} |
75 |
} |
} |
76 |
|
|
77 |
public int size() |
public int size() |
121 |
public boolean addAll(Collection<? extends T> c) |
public boolean addAll(Collection<? extends T> c) |
122 |
{ |
{ |
123 |
boolean result = false; |
boolean result = false; |
124 |
if (c instanceof EnumSet<T>) |
if (c instanceof EnumSet) |
125 |
{ |
{ |
126 |
EnumSet<T> other = (EnumSet<T>) c; |
EnumSet<T> other = (EnumSet<T>) c; |
127 |
if (enumClass == other.enumClass) |
if (enumClass == other.enumClass) |
151 |
|
|
152 |
public boolean contains(Object o) |
public boolean contains(Object o) |
153 |
{ |
{ |
154 |
if (! (o instanceof Enum<T>)) |
if (! (o instanceof Enum)) |
155 |
return false; |
return false; |
156 |
Enum<T> e = (Enum<T>) o; |
Enum<T> e = (Enum<T>) o; |
157 |
if (e.getDeclaringClass() != enumClass) |
if (e.getDeclaringClass() != enumClass) |
161 |
|
|
162 |
public boolean containsAll(Collection<?> c) |
public boolean containsAll(Collection<?> c) |
163 |
{ |
{ |
164 |
if (c instanceof EnumSet<T>) |
if (c instanceof EnumSet) |
165 |
{ |
{ |
166 |
EnumSet<T> other = (EnumSet<T>) c; |
EnumSet<T> other = (EnumSet<T>) c; |
167 |
if (enumClass == other.enumClass) |
if (enumClass == other.enumClass) |
173 |
|
|
174 |
public boolean remove(Object o) |
public boolean remove(Object o) |
175 |
{ |
{ |
176 |
if (! (o instanceof Enum<T>)) |
if (! (o instanceof Enum)) |
177 |
return false; |
return false; |
178 |
Enum<T> e = (Enum<T>) o; |
Enum<T> e = (Enum<T>) o; |
179 |
if (e.getDeclaringClass() != enumClass) |
if (e.getDeclaringClass() != enumClass) |
185 |
|
|
186 |
public boolean removeAll(Collection<?> c) |
public boolean removeAll(Collection<?> c) |
187 |
{ |
{ |
188 |
if (c instanceof EnumSet<T>) |
if (c instanceof EnumSet) |
189 |
{ |
{ |
190 |
EnumSet<T> other = (EnumSet<T>) c; |
EnumSet<T> other = (EnumSet<T>) c; |
191 |
if (enumClass != other.enumClass) |
if (enumClass != other.enumClass) |
200 |
|
|
201 |
public boolean retainAll(Collection<?> c) |
public boolean retainAll(Collection<?> c) |
202 |
{ |
{ |
203 |
if (c instanceof EnumSet<T>) |
if (c instanceof EnumSet) |
204 |
{ |
{ |
205 |
EnumSet<T> other = (EnumSet<T>) c; |
EnumSet<T> other = (EnumSet<T>) c; |
206 |
if (enumClass != other.enumClass) |
if (enumClass != other.enumClass) |
236 |
// We can't just use `other.clone' since we don't want to make a |
// We can't just use `other.clone' since we don't want to make a |
237 |
// subclass. |
// subclass. |
238 |
EnumSet<T> r = new EnumSet<T>(); |
EnumSet<T> r = new EnumSet<T>(); |
239 |
r.store = other.store.clone(); |
r.store = (BitSet) other.store.clone(); |
240 |
r.cardinality = other.cardinality; |
r.cardinality = other.cardinality; |
241 |
r.enumClass = other.enumClass; |
r.enumClass = other.enumClass; |
242 |
return r; |
return r; |
244 |
|
|
245 |
public static <T extends Enum<T>> EnumSet<T> copyOf(Collection<T> other) |
public static <T extends Enum<T>> EnumSet<T> copyOf(Collection<T> other) |
246 |
{ |
{ |
247 |
if (other instanceof EnumSet<T>) |
if (other instanceof EnumSet) |
248 |
return copyOf((EnumSet<T>) other); |
return copyOf((EnumSet<T>) other); |
249 |
EnumSet<T> r = new EnumSet<T>(); |
EnumSet<T> r = new EnumSet<T>(); |
250 |
for (T val : other) |
for (T val : other) |
266 |
public static <T extends Enum<T>> EnumSet<T> complementOf(EnumSet<T> other) |
public static <T extends Enum<T>> EnumSet<T> complementOf(EnumSet<T> other) |
267 |
{ |
{ |
268 |
EnumSet<T> r = new EnumSet<T>(); |
EnumSet<T> r = new EnumSet<T>(); |
269 |
r.store = other.store.clone(); |
r.store = (BitSet) other.store.clone(); |
270 |
r.store.flip(0, r.store.size()); |
r.store.flip(0, r.store.size()); |
271 |
r.cardinality = r.store.size() - other.cardinality; |
r.cardinality = r.store.size() - other.cardinality; |
272 |
r.enumClass = other.enumClass; |
r.enumClass = other.enumClass; |