Methods Summary |
---|
public boolean | add(E e)Adds the specified element to this set if it is not already present.
typeCheck(e);
int eOrdinal = e.ordinal();
int eWordNum = eOrdinal >>> 6;
long oldElements = elements[eWordNum];
elements[eWordNum] |= (1L << eOrdinal);
boolean result = (elements[eWordNum] != oldElements);
if (result)
size++;
return result;
|
public boolean | addAll(java.util.Collection c)Adds all of the elements in the specified collection to this set.
if (!(c instanceof JumboEnumSet))
return super.addAll(c);
JumboEnumSet es = (JumboEnumSet)c;
if (es.elementType != elementType) {
if (es.isEmpty())
return false;
else
throw new ClassCastException(
es.elementType + " != " + elementType);
}
for (int i = 0; i < elements.length; i++)
elements[i] |= es.elements[i];
return recalculateSize();
|
void | addAll()
for (int i = 0; i < elements.length; i++)
elements[i] = -1;
elements[elements.length - 1] >>>= -universe.length;
size = universe.length;
|
void | addRange(E from, E to)
int fromIndex = from.ordinal() >>> 6;
int toIndex = to.ordinal() >>> 6;
if (fromIndex == toIndex) {
elements[fromIndex] = (-1L >>> (from.ordinal() - to.ordinal() - 1))
<< from.ordinal();
} else {
elements[fromIndex] = (-1L << from.ordinal());
for (int i = fromIndex + 1; i < toIndex; i++)
elements[i] = -1;
elements[toIndex] = -1L >>> (63 - to.ordinal());
}
size = to.ordinal() - from.ordinal() + 1;
|
public void | clear()Removes all of the elements from this set.
Arrays.fill(elements, 0);
size = 0;
|
public java.util.EnumSet | clone()
JumboEnumSet<E> result = (JumboEnumSet<E>) super.clone();
result.elements = (long[]) result.elements.clone();
return result;
|
void | complement()
for (int i = 0; i < elements.length; i++)
elements[i] = ~elements[i];
elements[elements.length - 1] &= (-1L >>> -universe.length);
size = universe.length - size;
|
public boolean | contains(java.lang.Object e)Returns true if this set contains the specified element.
if (e == null)
return false;
Class eClass = e.getClass();
if (eClass != elementType && eClass.getSuperclass() != elementType)
return false;
int eOrdinal = ((Enum)e).ordinal();
return (elements[eOrdinal >>> 6] & (1L << eOrdinal)) != 0;
|
public boolean | containsAll(java.util.Collection c)Returns true if this set contains all of the elements
in the specified collection.
if (!(c instanceof JumboEnumSet))
return super.containsAll(c);
JumboEnumSet es = (JumboEnumSet)c;
if (es.elementType != elementType)
return es.isEmpty();
for (int i = 0; i < elements.length; i++)
if ((es.elements[i] & ~elements[i]) != 0)
return false;
return true;
|
public boolean | equals(java.lang.Object o)Compares the specified object with this set for equality. Returns
true if the given object is also a set, the two sets have
the same size, and every member of the given set is contained in
this set.
if (!(o instanceof JumboEnumSet))
return super.equals(o);
JumboEnumSet es = (JumboEnumSet)o;
if (es.elementType != elementType)
return size == 0 && es.size == 0;
return Arrays.equals(es.elements, elements);
|
public boolean | isEmpty()Returns true if this set contains no elements.
return size == 0;
|
public java.util.Iterator | iterator()Returns an iterator over the elements contained in this set. The
iterator traverses the elements in their natural order (which is
the order in which the enum constants are declared). The returned
Iterator is a "weakly consistent" iterator that will never throw {@link
ConcurrentModificationException}.
return new EnumSetIterator<E>();
|
private boolean | recalculateSize()Recalculates the size of the set. Returns true if it's changed.
int oldSize = size;
size = 0;
for (long elt : elements)
size += Long.bitCount(elt);
return size != oldSize;
|
public boolean | remove(java.lang.Object e)Removes the specified element from this set if it is present.
if (e == null)
return false;
Class eClass = e.getClass();
if (eClass != elementType && eClass.getSuperclass() != elementType)
return false;
int eOrdinal = ((Enum)e).ordinal();
int eWordNum = eOrdinal >>> 6;
long oldElements = elements[eWordNum];
elements[eWordNum] &= ~(1L << eOrdinal);
boolean result = (elements[eWordNum] != oldElements);
if (result)
size--;
return result;
|
public boolean | removeAll(java.util.Collection c)Removes from this set all of its elements that are contained in
the specified collection.
if (!(c instanceof JumboEnumSet))
return super.removeAll(c);
JumboEnumSet es = (JumboEnumSet)c;
if (es.elementType != elementType)
return false;
for (int i = 0; i < elements.length; i++)
elements[i] &= ~es.elements[i];
return recalculateSize();
|
public boolean | retainAll(java.util.Collection c)Retains only the elements in this set that are contained in the
specified collection.
if (!(c instanceof JumboEnumSet))
return super.retainAll(c);
JumboEnumSet<?> es = (JumboEnumSet<?>)c;
if (es.elementType != elementType) {
boolean changed = (size != 0);
clear();
return changed;
}
for (int i = 0; i < elements.length; i++)
elements[i] &= es.elements[i];
return recalculateSize();
|
public int | size()Returns the number of elements in this set.
return size;
|