public class BitFieldSet<E extends Enum<E>> extends AbstractSet<E> implements Cloneable, Serializable
Modification allows access and manipulation of the bit mask for the elements so this class can be easily converted between long/int and BitFieldSet to use as efficient option flags in implementation but convenient enum sets for manipulation.
If the Enum implements BitField then each field can have 1..N bits up to a maximum total of 64 bits per enum.
The class provides methods for setting and getting values from these fields as long, int, short or byte values, either signed or unsigned.
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E... rest) |
boolean |
add(E e)
Adds the specified element to this set if it is not already present.
|
boolean |
add(E e1,
E e2) |
boolean |
add(E e1,
E e2,
E e3) |
boolean |
add(E e1,
E e2,
E e3,
E e4) |
boolean |
add(E e1,
E e2,
E e3,
E e4,
E e5) |
boolean |
addAll(Collection<? extends E> c)
Adds all of the elements in the specified collection to this set.
|
boolean |
all(E... rest) |
boolean |
all(E e1) |
boolean |
all(E e1,
E e2) |
boolean |
all(E e1,
E e2,
E e3) |
boolean |
all(E e1,
E e2,
E e3,
E e4) |
boolean |
all(E e1,
E e2,
E e3,
E e4,
E e5) |
boolean |
all(long mask) |
static boolean |
all(long flags,
long mask) |
long |
allBitsMask() |
static <E extends Enum<E>> |
allOf(Class<E> elementType)
Creates an enum set containing all of the elements in the specified
element type.
|
boolean |
andNotMask(long mask) |
static long |
andNotMask(long flags,
long mask) |
boolean |
any(E... rest) |
boolean |
any(E e1) |
boolean |
any(E e1,
E e2) |
boolean |
any(E e1,
E e2,
E e3) |
boolean |
any(E e1,
E e2,
E e3,
E e4) |
boolean |
any(E e1,
E e2,
E e3,
E e4,
E e5) |
boolean |
any(long mask) |
static boolean |
any(long flags,
long mask) |
void |
clear()
Removes all of the elements from this set.
|
BitFieldSet<E> |
clone()
Returns a copy of this set.
|
void |
complement() |
static <E extends Enum<E>> |
complementOf(BitFieldSet<E> s)
Creates an enum set with the same element type as the specified enum
set, initially containing all the elements of this type that are
not contained in the specified set.
|
boolean |
contains(Object e)
Returns true if this set contains the specified element.
|
boolean |
containsAll(Collection<?> c)
Returns true if this set contains all of the elements
in the specified collection.
|
static <E extends Enum<E>> |
copyOf(BitFieldSet<E> s)
Creates an enum set with the same element type as the specified enum
set, initially containing the same elements (if any).
|
static <E extends Enum<E>> |
copyOf(Collection<E> c)
Creates an enum set initialized from the specified collection.
|
boolean |
equals(Object o)
Compares the specified object with this set for equality.
|
long |
get(E e1)
Returns unsigned value for the field, except if the field is 64 bits
|
static <E extends Enum<E>> |
getBitField(byte elements,
E e1) |
static <E extends Enum<E>> |
getBitField(int elements,
E e1) |
static <E extends Enum<E>> |
getBitField(long elements,
E e1)
Returns signed value for the field, except if the field is 64 bits
|
static <E extends Enum<E>> |
getBitField(short elements,
E e1) |
static <E extends Enum<E>> |
getBitMasks(Class<E> elementType)
Returns all of the values comprising E.
|
byte |
getByte(E e1) |
int |
getInt(E e1) |
long |
getLong(E e1)
Returns signed value for the field, except if the field is 64 bits
|
short |
getShort(E e1) |
long |
getSigned(E e1,
int maxBits,
String typeName) |
static int |
getTotalBits(long[] bitMasks) |
byte |
getUByte(E e1) |
int |
getUInt(E e1) |
static <E extends Enum<E>> |
getUniverse(Class<E> elementType)
Returns all of the values comprising E.
|
long |
getUnsigned(E e1,
int maxBits,
String typeName) |
static <E extends Enum<E>> |
getUnsignedBitField(long elements,
E e1,
int maxBits,
String typeName)
Returns unsigned value for the field, except if the field is 64 bits
|
short |
getUShort(E e1) |
static <E extends Enum<E>> |
intMask(E e1) |
boolean |
isEmpty()
Returns true if this set contains no elements.
|
@NotNull Iterator<E> |
iterator()
Returns an iterator over the elements contained in this set.
|
static <E extends Enum<E>> |
longMask(E e1) |
long |
mask(E... rest) |
long |
mask(E e1) |
long |
mask(E e1,
E e2) |
long |
mask(E e1,
E e2,
E e3) |
long |
mask(E e1,
E e2,
E e3,
E e4) |
long |
mask(E e1,
E e2,
E e3,
E e4,
E e5) |
static long |
nextBitMask(int nextAvailableBit,
int bits) |
boolean |
none(E... rest) |
boolean |
none(E e1) |
boolean |
none(E e1,
E e2) |
boolean |
none(E e1,
E e2,
E e3) |
boolean |
none(E e1,
E e2,
E e3,
E e4) |
boolean |
none(E e1,
E e2,
E e3,
E e4,
E e5) |
boolean |
none(long mask) |
static boolean |
none(long flags,
long mask) |
static <E extends Enum<E>> |
noneOf(Class<E> elementType)
Creates an empty enum set with the specified element type.
|
static <E extends Enum<E>> |
of(@NotNull Class<E> declaringClass,
E[] rest)
Creates an enum set initially containing the specified elements.
|
static <T extends Enum<T>> |
of(@NotNull Class<T> enumClass,
long mask)
Create a bit enum set from a bit mask
|
static <E extends Enum<E>> |
of(E e)
Creates an enum set initially containing the specified element.
|
static <E extends Enum<E>> |
of(E first,
E... rest)
Creates an enum set initially containing the specified elements.
|
static <E extends Enum<E>> |
of(E e1,
E e2)
Creates an enum set initially containing the specified elements.
|
static <E extends Enum<E>> |
of(E e1,
E e2,
E e3)
Creates an enum set initially containing the specified elements.
|
static <E extends Enum<E>> |
of(E e1,
E e2,
E e3,
E e4)
Creates an enum set initially containing the specified elements.
|
static <E extends Enum<E>> |
of(E e1,
E e2,
E e3,
E e4,
E e5)
Creates an enum set initially containing the specified elements.
|
boolean |
orMask(long mask) |
static long |
orMask(long flags,
long mask) |
static <E extends Enum<E>> |
range(E from,
E to)
Creates an enum set initially containing all of the elements in the
range defined by the two specified endpoints.
|
boolean |
remove(E... rest) |
boolean |
remove(E e1,
E e2) |
boolean |
remove(E e1,
E e2,
E e3) |
boolean |
remove(E e1,
E e2,
E e3,
E e4) |
boolean |
remove(E e1,
E e2,
E e3,
E e4,
E e5) |
boolean |
remove(Object e)
Removes the specified element from this set if it is present.
|
boolean |
removeAll(Collection<?> c)
Removes from this set all of its elements that are contained in
the specified collection.
|
boolean |
replaceAll(long mask)
Deprecated.
use
setAll(long) |
boolean |
retainAll(Collection<?> c)
Retains only the elements in this set that are contained in the
specified collection.
|
boolean |
setAll(long mask) |
static <E extends Enum<E>> |
setBitField(byte elements,
E e1,
byte value) |
void |
setBitField(E e1,
byte value) |
void |
setBitField(E e1,
int value) |
void |
setBitField(E e1,
long value) |
void |
setBitField(E e1,
short value) |
static <E extends Enum<E>> |
setBitField(int elements,
E e1,
int value) |
static <E extends Enum<E>> |
setBitField(long elements,
E e1,
int value) |
static <E extends Enum<E>> |
setBitField(short elements,
E e1,
short value) |
boolean |
setSigned(E e1,
long value)
Set a signed value for the field
|
boolean |
setUnsigned(E e1,
long value)
Set a signed value for the field
|
void |
setUnsignedField(E e1,
byte value) |
void |
setUnsignedField(E e1,
int value) |
void |
setUnsignedField(E e1,
long value) |
void |
setUnsignedField(E e1,
short value) |
int |
size()
Returns the number of elements in this set.
|
byte |
toByte() |
int |
toInt() |
long |
toLong() |
short |
toShort() |
String |
toString() |
hashCodetoArray, toArrayfinalize, getClass, notify, notifyAll, wait, wait, waitspliterator, toArray, toArrayparallelStream, removeIf, streampublic static long nextBitMask(int nextAvailableBit,
int bits)
public static <E extends Enum<E>> E[] getUniverse(Class<E> elementType)
E - type of enumelementType - class of enumpublic static <E extends Enum<E>> long[] getBitMasks(Class<E> elementType)
E - type of enumelementType - class of enumpublic static int getTotalBits(long[] bitMasks)
public void complement()
public long toLong()
public int toInt()
public short toShort()
public byte toByte()
public long allBitsMask()
public boolean orMask(long mask)
@Deprecated public boolean replaceAll(long mask)
setAll(long)mask - bit fields valuespublic boolean setAll(long mask)
public String toString()
toString in class AbstractCollection<E extends Enum<E>>public boolean andNotMask(long mask)
public boolean any(long mask)
public boolean none(long mask)
public boolean all(long mask)
public static <E extends Enum<E>> long longMask(E e1)
public static <E extends Enum<E>> int intMask(E e1)
public long get(E e1)
e1 - field to getpublic boolean setUnsigned(E e1, long value)
e1 - fieldvalue - value to setpublic boolean setSigned(E e1, long value)
e1 - fieldvalue - value to setpublic void setBitField(E e1, long value)
public void setBitField(E e1, int value)
public void setBitField(E e1, short value)
public void setBitField(E e1, byte value)
public void setUnsignedField(E e1, long value)
public void setUnsignedField(E e1, int value)
public void setUnsignedField(E e1, short value)
public void setUnsignedField(E e1, byte value)
public long getLong(E e1)
e1 - field to getpublic int getInt(E e1)
public short getShort(E e1)
public byte getByte(E e1)
public int getUInt(E e1)
public short getUShort(E e1)
public byte getUByte(E e1)
public static long orMask(long flags,
long mask)
public static long andNotMask(long flags,
long mask)
public static boolean any(long flags,
long mask)
public static boolean all(long flags,
long mask)
public static boolean none(long flags,
long mask)
public long mask(E e1)
@SafeVarargs public final long mask(E... rest)
@SafeVarargs public final boolean add(E... rest)
@SafeVarargs public final boolean remove(E... rest)
public boolean any(E e1)
@SafeVarargs public final boolean any(E... rest)
public boolean all(E e1)
@SafeVarargs public final boolean all(E... rest)
public boolean none(E e1)
@SafeVarargs public final boolean none(E... rest)
@NotNull public @NotNull Iterator<E> iterator()
ConcurrentModificationException; the elements are traversed as they
existed when this call was invoked.
NOTE: bit field iteration requires skipping fields whose bits are all 0 so constant time is violated
iterator in interface Iterable<E extends Enum<E>>iterator in interface Collection<E extends Enum<E>>iterator in interface Set<E extends Enum<E>>iterator in class AbstractCollection<E extends Enum<E>>public int size()
public boolean isEmpty()
public boolean contains(Object e)
contains in interface Collection<E extends Enum<E>>contains in interface Set<E extends Enum<E>>contains in class AbstractCollection<E extends Enum<E>>e - element to be checked for containment in this collectionpublic boolean add(E e)
add in interface Collection<E extends Enum<E>>add in interface Set<E extends Enum<E>>add in class AbstractCollection<E extends Enum<E>>e - element to be added to this setNullPointerException - if e is nullpublic boolean remove(Object e)
remove in interface Collection<E extends Enum<E>>remove in interface Set<E extends Enum<E>>remove in class AbstractCollection<E extends Enum<E>>e - element to be removed from this set, if presentpublic boolean containsAll(Collection<?> c)
containsAll in interface Collection<E extends Enum<E>>containsAll in interface Set<E extends Enum<E>>containsAll in class AbstractCollection<E extends Enum<E>>c - collection to be checked for containment in this setNullPointerException - if the specified collection is nullpublic boolean addAll(Collection<? extends E> c)
addAll in interface Collection<E extends Enum<E>>addAll in interface Set<E extends Enum<E>>addAll in class AbstractCollection<E extends Enum<E>>c - collection whose elements are to be added to this setNullPointerException - if the specified collection or any
of its elements are nullpublic boolean removeAll(Collection<?> c)
removeAll in interface Collection<E extends Enum<E>>removeAll in interface Set<E extends Enum<E>>removeAll in class AbstractSet<E extends Enum<E>>c - elements to be removed from this setNullPointerException - if the specified collection is nullpublic boolean retainAll(Collection<?> c)
retainAll in interface Collection<E extends Enum<E>>retainAll in interface Set<E extends Enum<E>>retainAll in class AbstractCollection<E extends Enum<E>>c - elements to be retained in this setNullPointerException - if the specified collection is nullpublic void clear()
public static <T extends Enum<T>> BitFieldSet<T> of(@NotNull @NotNull Class<T> enumClass, long mask)
T - enum typeenumClass - class of the enummask - bit mask for itemspublic BitFieldSet<E> clone()
public boolean equals(Object o)
equals in interface Collection<E extends Enum<E>>equals in interface Set<E extends Enum<E>>equals in class AbstractSet<E extends Enum<E>>o - object to be compared for equality with this setpublic static <E extends Enum<E>> BitFieldSet<E> noneOf(Class<E> elementType)
E - The class of the elements in the setelementType - the class object of the element type for this enum
setNullPointerException - if elementType is nullpublic static <E extends Enum<E>> long setBitField(long elements, E e1, int value)
public static <E extends Enum<E>> int setBitField(int elements, E e1, int value)
public static <E extends Enum<E>> short setBitField(short elements, E e1, short value)
public static <E extends Enum<E>> byte setBitField(byte elements, E e1, byte value)
public static <E extends Enum<E>> long getUnsignedBitField(long elements, E e1, int maxBits, String typeName)
E - type of enumelements - bit mask for elementse1 - field to getmaxBits - maximum bits for typetypeName - name of typepublic static <E extends Enum<E>> long getBitField(long elements, E e1)
E - type of enumelements - bit mask for elementse1 - field to getpublic static <E extends Enum<E>> int getBitField(int elements, E e1)
public static <E extends Enum<E>> short getBitField(short elements, E e1)
public static <E extends Enum<E>> byte getBitField(byte elements, E e1)
public static <E extends Enum<E>> BitFieldSet<E> allOf(Class<E> elementType)
E - The class of the elements in the setelementType - the class object of the element type for this enum
setNullPointerException - if elementType is nullpublic static <E extends Enum<E>> BitFieldSet<E> copyOf(BitFieldSet<E> s)
E - The class of the elements in the sets - the enum set from which to initialize this enum setNullPointerException - if s is nullpublic static <E extends Enum<E>> BitFieldSet<E> copyOf(Collection<E> c)
copyOf(BitFieldSet).
Otherwise, the specified collection must contain at least one element
(in order to determine the new enum set's element type).E - The class of the elements in the collectionc - the collection from which to initialize this enum setIllegalArgumentException - if c is not an
BitFieldSet instance and contains no elementsNullPointerException - if c is nullpublic static <E extends Enum<E>> BitFieldSet<E> complementOf(BitFieldSet<E> s)
E - The class of the elements in the enum sets - the enum set from whose complement to initialize this enum setNullPointerException - if s is nullpublic static <E extends Enum<E>> BitFieldSet<E> of(E e)
Overloads of this method exist to initialize an enum set with one through five elements. A sixth overloading is provided that uses the varargs feature. This overloading may be used to create an enum set initially containing an arbitrary number of elements, but is likely to run slower than the overloads that do not use varargs.
E - The class of the specified element and of the sete - the element that this set is to contain initiallyNullPointerException - if e is nullpublic static <E extends Enum<E>> BitFieldSet<E> of(E e1, E e2)
Overloads of this method exist to initialize an enum set with one through five elements. A sixth overloading is provided that uses the varargs feature. This overloading may be used to create an enum set initially containing an arbitrary number of elements, but is likely to run slower than the overloads that do not use varargs.
E - The class of the parameter elements and of the sete1 - an element that this set is to contain initiallye2 - another element that this set is to contain initiallyNullPointerException - if any parameters are nullpublic static <E extends Enum<E>> BitFieldSet<E> of(E e1, E e2, E e3)
Overloads of this method exist to initialize an enum set with one through five elements. A sixth overloading is provided that uses the varargs feature. This overloading may be used to create an enum set initially containing an arbitrary number of elements, but is likely to run slower than the overloads that do not use varargs.
E - The class of the parameter elements and of the sete1 - an element that this set is to contain initiallye2 - another element that this set is to contain initiallye3 - another element that this set is to contain initiallyNullPointerException - if any parameters are nullpublic static <E extends Enum<E>> BitFieldSet<E> of(E e1, E e2, E e3, E e4)
Overloads of this method exist to initialize an enum set with one through five elements. A sixth overloading is provided that uses the varargs feature. This overloading may be used to create an enum set initially containing an arbitrary number of elements, but is likely to run slower than the overloads that do not use varargs.
E - The class of the parameter elements and of the sete1 - an element that this set is to contain initiallye2 - another element that this set is to contain initiallye3 - another element that this set is to contain initiallye4 - another element that this set is to contain initiallyNullPointerException - if any parameters are nullpublic static <E extends Enum<E>> BitFieldSet<E> of(E e1, E e2, E e3, E e4, E e5)
Overloads of this method exist to initialize an enum set with one through five elements. A sixth overloading is provided that uses the varargs feature. This overloading may be used to create an enum set initially containing an arbitrary number of elements, but is likely to run slower than the overloads that do not use varargs.
E - The class of the parameter elements and of the sete1 - an element that this set is to contain initiallye2 - another element that this set is to contain initiallye3 - another element that this set is to contain initiallye4 - another element that this set is to contain initiallye5 - another element that this set is to contain initiallyNullPointerException - if any parameters are null@SafeVarargs public static <E extends Enum<E>> BitFieldSet<E> of(E first, E... rest)
E - The class of the parameter elements and of the setfirst - an element that the set is to contain initiallyrest - the remaining elements the set is to contain initiallyNullPointerException - if any of the specified elements are null,
or if rest is nullpublic static <E extends Enum<E>> BitFieldSet<E> of(@NotNull @NotNull Class<E> declaringClass, E[] rest)
E - The class of the parameter elements and of the setdeclaringClass - declaring class of enumrest - the remaining elements the set is to contain initiallyNullPointerException - if any of the specified elements are null,
or if rest is nullpublic static <E extends Enum<E>> BitFieldSet<E> range(E from, E to)
E - The class of the parameter elements and of the setfrom - the first element in the rangeto - the last element in the rangeNullPointerException - if from or to are nullIllegalArgumentException - if from.compareTo(to) > 0Copyright © 2020. All rights reserved.