E - The type of Enum objects contained in this set.@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
@Immutable
public final class BitField<E extends java.lang.Enum<E>>
extends java.lang.Object
implements java.lang.Iterable<E>, java.io.Serializable
TODO: Add more modifying methods.
| Modifier and Type | Field and Description |
|---|---|
private java.util.EnumSet<E> |
bits |
private static long |
serialVersionUID |
| Modifier | Constructor and Description |
|---|---|
private |
BitField(java.lang.Class<E> elementType,
boolean allOf)
Constructs a new bit field which contains all or none of the enums
of the given element type.
|
private |
BitField(java.util.Collection<E> bits)
Constructs a new bit field by sharing the given set of enums.
|
private |
BitField(E bit)
Constructs a new bit field which contains the given bit.
|
private |
BitField(E bit,
E... bits)
Constructs a new bit field which contains the given bits.
|
| Modifier and Type | Method and Description |
|---|---|
static <E extends java.lang.Enum<E>> |
allOf(java.lang.Class<E> elementType)
Returns a bit field which contains all enums of the given element type.
|
BitField<E> |
and(BitField<E> that) |
int |
cardinality()
Returns the number of bits set in this field.
|
BitField<E> |
clear(E bit)
Clears the given bit.
|
static <E extends java.lang.Enum<E>> |
copyOf(java.util.Collection<E> bits)
Returns a bit field which contains the same bits as the given set of
enums.
|
boolean |
equals(java.lang.Object that)
Returns
true if and only if the given object is another
BitField and contains the same bits. |
boolean |
get(E bit)
Returns
true if and only if the given bit is set. |
int |
hashCode()
Returns a hash code which is consistent with
equals(java.lang.Object). |
boolean |
is(E bit)
Equivalent to
get(bit). |
boolean |
isEmpty()
Returns
true if and only if all bits are cleared in this bit
field. |
java.util.Iterator<E> |
iterator()
Returns a read-only iterator for the bits in this field.
|
static <E extends java.lang.Enum<E>> |
noneOf(java.lang.Class<E> elementType)
Returns a bit field which can contain the given element type and is
initially empty.
|
BitField<E> |
not() |
static <E extends java.lang.Enum<E>> |
of(java.lang.Class<E> elementType,
java.lang.String list) |
static <E extends java.lang.Enum<E>> |
of(E bit)
Returns a bit field which contains the given bit.
|
static <E extends java.lang.Enum<E>> |
of(E bit,
E... bits)
Returns a bit field which contains the given bits.
|
BitField<E> |
or(BitField<E> that) |
BitField<E> |
set(E bit)
Sets the given bit.
|
BitField<E> |
set(E bit,
boolean set)
Sets or clears the given bit.
|
java.util.EnumSet<E> |
toEnumSet()
Returns a new set of enums containing the same bits as this instance.
|
java.lang.String |
toString()
Returns a concatenation of the names of the bits in this field,
separated by
"|". |
private static final long serialVersionUID
private BitField(java.lang.Class<E> elementType, boolean allOf)
private BitField(E bit)
private BitField(E bit, E... bits)
private BitField(java.util.Collection<E> bits)
bits - the set of enums to share with this instance.public static <E extends java.lang.Enum<E>> BitField<E> noneOf(java.lang.Class<E> elementType)
This could be used like this:
BitField<Option> field = BitField.noneOf(Option.class);
where Option is an arbitrary enum type.public static <E extends java.lang.Enum<E>> BitField<E> allOf(java.lang.Class<E> elementType)
This could be used like this:
BitField<Option> field = BitField.allOf(Option.class);
where Option is an arbitrary enum type.public static <E extends java.lang.Enum<E>> BitField<E> of(E bit)
This could be used like this:
BitField<Option> field = BitField.of(Option.ONE);
where Option.ONE is an arbitrary enum.public static <E extends java.lang.Enum<E>> BitField<E> of(E bit, E... bits)
This could be used like this:
BitField<Option> field = BitField.of(Option.ONE, Option.TWO);
where Option.ONE and Option.TWO are arbitrary enums.public static <E extends java.lang.Enum<E>> BitField<E> copyOf(java.util.Collection<E> bits)
This could be used like this:
BitField<Option> field = BitField.of(bits);
where bits is an EnumSet<Option>.public static <E extends java.lang.Enum<E>> BitField<E> of(java.lang.Class<E> elementType, java.lang.String list)
public boolean isEmpty()
true if and only if all bits are cleared in this bit
field.public int cardinality()
public boolean get(E bit)
true if and only if the given bit is set.bit - The bit to test.public BitField<E> set(E bit, boolean set)
Subclasses could override this method in order to cache frequently used results, such as a null bit field, a single bit field etc.
bit - The bit to set or clear.set - Whether the bit shall get set or cleared.public java.util.Iterator<E> iterator()
public java.util.EnumSet<E> toEnumSet()
null bit field bits:
bits.equals(BitField.of(bits.toEnumSet())).public java.lang.String toString()
"|".toString in class java.lang.Objectpublic boolean equals(@CheckForNull
java.lang.Object that)
true if and only if the given object is another
BitField and contains the same bits.equals in class java.lang.Objectpublic int hashCode()
equals(java.lang.Object).hashCode in class java.lang.ObjectCopyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.