Methods Summary |
---|
public boolean | add(E element)
if (!isValidType(element.getDeclaringClass())) {
throw new ClassCastException();
}
long mask = 1l << element.ordinal();
if ((bits & mask) == mask) {
return false;
}
bits |= mask;
size++;
return true;
|
public boolean | addAll(java.util.Collection collection)
if (0 == collection.size()) {
return false;
}
if (collection instanceof EnumSet) {
EnumSet<?> set = (EnumSet)collection;
if (!isValidType(set.elementClass)) {
throw new ClassCastException();
}
MiniEnumSet<?> miniSet = (MiniEnumSet<?>) set;
long oldBits = bits;
bits |= miniSet.bits;
size = Long.bitCount(bits);
return (oldBits != bits);
}
return super.addAll(collection);
|
public void | clear()
bits = 0;
size = 0;
|
void | complement()
if (0 != enums.length) {
bits = ~bits;
bits &= (-1l >>> (MAX_ELEMENTS - enums.length));
size = enums.length - size;
}
|
public boolean | contains(java.lang.Object object)
if (null == object) {
return false;
}
if (!isValidType(object.getClass())) {
return false;
}
Enum<?> element = (Enum<?>) object;
int ordinal = element.ordinal();
return (bits & (1l << ordinal)) != 0;
|
public boolean | containsAll(java.util.Collection collection)
if (collection.size() == 0) {
return true;
}
if (collection instanceof MiniEnumSet) {
MiniEnumSet<?> set = (MiniEnumSet<?>) collection;
return isValidType(set.elementClass ) && ((bits & set.bits) == set.bits);
}
return !(collection instanceof EnumSet) && super.containsAll(collection);
|
public boolean | equals(java.lang.Object object)
if (!(object instanceof EnumSet)) {
return super.equals(object);
}
EnumSet<?> set =(EnumSet<?>)object;
if( !isValidType(set.elementClass) ) {
return size == 0 && set.size() == 0;
}
return bits == ((MiniEnumSet<?>)set).bits;
|
public java.util.Iterator | iterator()
return new MiniEnumSetIterator();
|
public boolean | remove(java.lang.Object object)
if (!contains(object)) {
return false;
}
Enum<?> element = (Enum<?>) object;
int ordinal = element.ordinal();
bits -= (1l << ordinal);
size--;
return true;
|
public boolean | removeAll(java.util.Collection collection)
if (0 == collection.size()) {
return false;
}
if (collection instanceof EnumSet) {
EnumSet<E> set = (EnumSet<E>) collection;
boolean removeSuccessful = false;
if (isValidType(set.elementClass)) {
long mask = bits & ((MiniEnumSet<E>) set).bits;
if (mask != 0) {
bits -= mask;
size = Long.bitCount(bits);
removeSuccessful = true;
}
}
return removeSuccessful;
}
return super.removeAll(collection);
|
public boolean | retainAll(java.util.Collection collection)
if (collection instanceof EnumSet) {
EnumSet<E> set = (EnumSet<E>) collection;
if (!isValidType(set.elementClass)) {
clear();
return true;
}
boolean retainSuccessful = false;
long oldBits = bits;
bits &= ((MiniEnumSet<E>)set).bits;
if (oldBits != bits) {
size = Long.bitCount(bits);
retainSuccessful = true;
}
return retainSuccessful;
}
return super.retainAll(collection);
|
void | setRange(E start, E end)
int length = end.ordinal() - start.ordinal() + 1;
long range = (-1l >>> (MAX_ELEMENTS - length)) << start.ordinal();
bits |= range;
size = Long.bitCount(bits);
|
public int | size()
return size;
|