Top Description Inners Fields Constructors Methods
com.vladsch.flexmark.util.misc

public Class BitFieldSet<E extends Enum<E>>

extends AbstractSet<E extends Enum<E>>
implements Cloneable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Cloneable
Annotations
@SuppressWarnings:ManualArrayToCollectionCopy, UseBulkOperation
Imports
org.jetbrains.annotations.NotNull, java.io.Serializable, java.lang.reflect.Field, java.util.AbstractSet, .Collection, .Iterator, .NoSuchElementException, java.util.concurrent.ConcurrentHashMap

Re-Implementation of RegularEnumSet class for EnumSet, for "regular sized" enum types (i.e., those with 64 or fewer enum constants)

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.

Authors
Vladimir Schneider, Josh Bloch
Since
1.5

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class
private static class
BitFieldSet.SerializationProxy<E extends Enum<E>>

This class is used to serialize all EnumSet instances, regardless of implementation type.

pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv final long[]
bitMasks

All bit masks for each field since some can span more than one

pack-priv long
elements

Bit vector representation of this set.

pack-priv final Class<E>
elementType

The class of all the elements of this set.

private static final long
pack-priv final int
totalBits

total number of bits used by all fields

pack-priv final E[]
universe

All values comprising T

pack-priv static final Enum<?>[]

Constructor Summary

AccessConstructor and Description
pack-priv
BitFieldSet(Class<E> elementType, Enum<?>[] universe, long[] bitMasks)

Method Summary

Modifier and TypeMethod and Description
public boolean
add(E e1, E e2)

public boolean
add(E e1, E e2, E e3)

public boolean
add(E e1, E e2, E e3, E e4)

public boolean
add(E e1, E e2, E e3, E e4, E e5)

public final boolean
add(E...
element to be added to this set
rest
)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Adds the specified element to this set if it is not already present (optional operation).

public boolean

Returns:

true if the set changed as a result of the call
add
(E
element to be added to this set
e
)

Overrides java.util.AbstractCollection.add.

Implements java.util.Set.add, java.util.Collection.add.

Adds the specified element to this set if it is not already present.

pack-priv void
public boolean

Returns:

true if this set changed as a result of the call
addAll
(Collection<? extends E>
collection whose elements are to be added to this set
c
)

Overrides java.util.AbstractCollection.addAll.

Implements java.util.Set.addAll, java.util.Collection.addAll.

Adds all of the elements in the specified collection to this set.

pack-priv void
addRange(E from, E to)

public boolean
all(long mask)

public static boolean
all(long flags, long mask)

public boolean
all(E e1)

public boolean
all(E e1, E e2)

public boolean
all(E e1, E e2, E e3)

public boolean
all(E e1, E e2, E e3, E e4)

public boolean
all(E e1, E e2, E e3, E e4, E e5)

public final boolean
all(E... rest)

public long
public static <
The class of the elements in the set
E extends Enum<E>
>
BitFieldSet<E>

Returns:

An enum set containing all the elements in the specified type.
allOf
(Class<E>
the class object of the element type for this enum set
elementType
)

Creates an enum set containing all of the elements in the specified element type.

public boolean
andNotMask(long mask)

public static long
andNotMask(long flags, long mask)

public boolean
any(long mask)

public static boolean
any(long flags, long mask)

public boolean
any(E e1)

public boolean
any(E e1, E e2)

public boolean
any(E e1, E e2, E e3)

public boolean
any(E e1, E e2, E e3, E e4)

public boolean
any(E e1, E e2, E e3, E e4, E e5)

public final boolean
any(E... rest)

public void
clear()

Overrides java.util.AbstractCollection.clear.

Implements java.util.Set.clear, java.util.Collection.clear.

Removes all of the elements from this set.

public BitFieldSet<E>

Returns:

a copy of this set
clone
()

Overrides java.lang.Object.clone.

Returns a copy of this set.

public void
public static <
The class of the elements in the enum set
E extends Enum<E>
>
BitFieldSet<E>

Returns:

The complement of the specified set in this set
complementOf
(BitFieldSet<E>
the enum set from whose complement to initialize this enum set
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.

public boolean

Returns:

true if this set contains the specified element
contains
(Object
element to be checked for containment in this collection
e
)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Set.contains, java.util.Collection.contains.

Returns true if this set contains the specified element.

public boolean

Returns:

true if this set contains all of the elements in the specified collection
containsAll
(Collection<?>
collection to be checked for containment in this set
c
)

Overrides java.util.AbstractCollection.containsAll.

Implements java.util.Set.containsAll, java.util.Collection.containsAll.

Returns true if this set contains all of the elements in the specified collection.

public static <
The class of the elements in the set
E extends Enum<E>
>
BitFieldSet<E>

Returns:

A copy of the specified enum set.
copyOf
(BitFieldSet<E>
the enum set from which to initialize this enum set
s
)

Creates an enum set with the same element type as the specified enum set, initially containing the same elements (if any).

public static <
The class of the elements in the collection
E extends Enum<E>
>
BitFieldSet<E>

Returns:

An enum set initialized from the given collection.
copyOf
(Collection<E>
the collection from which to initialize this enum set
c
)

Hides java.util.Set.copyOf.

Creates an enum set initialized from the specified collection.

public boolean

Returns:

true if the specified object is equal to this set
equals
(Object
object to be compared for equality with this set
o
)

Overrides java.util.AbstractSet.equals.

Implements java.util.Set.equals, java.util.Collection.equals.

Compares the specified object with this set for equality.

public long

Returns:

unsigned value
get
(E
field to get
e1
)

Returns unsigned value for the field, except if the field is 64 bits

public static <
type of enum
E extends Enum<E>
>
long

Returns:

unsigned value
getBitField
(long
bit mask for elements
elements
,
E
field to get
e1
)

Returns signed value for the field, except if the field is 64 bits

public 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 <
type of enum
E extends Enum<E>
>
long[]

Returns:

array of bit masks for enum values
getBitMasks
(Class<E>
class of enum
elementType
)

Returns all of the values comprising E.

public byte
getByte(E e1)

public int
getInt(E e1)

public long

Returns:

unsigned value
getLong
(E
field to get
e1
)

Returns signed value for the field, except if the field is 64 bits

public short
getShort(E e1)

public long
getSigned(E e1, int maxBits, String typeName)

pack-priv static <E extends Enum<E>> long
getSignedBitField(long elements, E e1, int maxBits, String typeName)

public static int
getTotalBits(long[] bitMasks)

public byte
getUByte(E e1)

public int
getUInt(E e1)

public static <
type of enum
E extends Enum<E>
>
E[]

Returns:

array of enum values
getUniverse
(Class<E>
class of enum
elementType
)

Returns all of the values comprising E.

public long
getUnsigned(E e1, int maxBits, String typeName)

public static <
type of enum
E extends Enum<E>
>
long

Returns:

unsigned value
getUnsignedBitField
(long
bit mask for elements
elements
,
E
field to get
e1
,
int
maximum bits for type
maxBits
,
String
name of type
typeName
)

Returns unsigned value for the field, except if the field is 64 bits

public short
getUShort(E e1)

public static <E extends Enum<E>> int
intMask(E e1)

public boolean

Returns:

true if this set contains no elements
isEmpty
()

Overrides java.util.AbstractCollection.isEmpty.

Implements java.util.Set.isEmpty, java.util.Collection.isEmpty.

Returns true if this set contains no elements.

public @NotNull Iterator<E>

Returns:

an iterator over the elements contained in this set
iterator
()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Returns an iterator over the elements contained in this set.

public static <E extends Enum<E>> long
longMask(E e1)

public long
mask(E e1)

public long
mask(E e1, E e2)

public long
mask(E e1, E e2, E e3)

public long
mask(E e1, E e2, E e3, E e4)

public long
mask(E e1, E e2, E e3, E e4, E e5)

public final long
mask(E... rest)

public static long
nextBitMask(int nextAvailableBit, int bits)

public boolean
none(long mask)

public static boolean
none(long flags, long mask)

public boolean
none(E e1)

public boolean
none(E e1, E e2)

public boolean
none(E e1, E e2, E e3)

public boolean
none(E e1, E e2, E e3, E e4)

public boolean
none(E e1, E e2, E e3, E e4, E e5)

public final boolean
none(E... rest)

public static <
The class of the elements in the set
E extends Enum<E>
>
BitFieldSet<E>

Returns:

An empty enum set of the specified type.
noneOf
(Class<E>
the class object of the element type for this enum set
elementType
)

Creates an empty enum set with the specified element type.

public static <
enum type
T extends Enum<T>
>
BitFieldSet<T>

Returns:

bit enum set
of
(@NotNull Class<T>
class of the enum
enumClass
,
long
bit mask for items
mask
)

Hides java.util.Set.of.

Create a bit enum set from a bit mask

public static <
The class of the specified element and of the set
E extends Enum<E>
>
BitFieldSet<E>

Returns:

an enum set initially containing the specified element
of
(E
the element that this set is to contain initially
e
)

Hides java.util.Set.of.

Creates an enum set initially containing the specified element.

public static <
The class of the parameter elements and of the set
E extends Enum<E>
>
BitFieldSet<E>

Returns:

an enum set initially containing the specified elements
of
(E
an element that this set is to contain initially
e1
,
E
another element that this set is to contain initially
e2
)

Hides java.util.Set.of.

Creates an enum set initially containing the specified elements.

public static <
The class of the parameter elements and of the set
E extends Enum<E>
>
BitFieldSet<E>

Returns:

an enum set initially containing the specified elements
of
(E
an element that this set is to contain initially
e1
,
E
another element that this set is to contain initially
e2
,
E
another element that this set is to contain initially
e3
)

Hides java.util.Set.of.

Creates an enum set initially containing the specified elements.

public static <
The class of the parameter elements and of the set
E extends Enum<E>
>
BitFieldSet<E>

Returns:

an enum set initially containing the specified elements
of
(E
an element that this set is to contain initially
e1
,
E
another element that this set is to contain initially
e2
,
E
another element that this set is to contain initially
e3
,
E
another element that this set is to contain initially
e4
)

Hides java.util.Set.of.

Creates an enum set initially containing the specified elements.

public static <
The class of the parameter elements and of the set
E extends Enum<E>
>
BitFieldSet<E>

Returns:

an enum set initially containing the specified elements
of
(E
an element that this set is to contain initially
e1
,
E
another element that this set is to contain initially
e2
,
E
another element that this set is to contain initially
e3
,
E
another element that this set is to contain initially
e4
,
E
another element that this set is to contain initially
e5
)

Hides java.util.Set.of.

Creates an enum set initially containing the specified elements.

public static <
The class of the parameter elements and of the set
E extends Enum<E>
>
BitFieldSet<E>

Returns:

an enum set initially containing the specified elements
of
(E
an element that the set is to contain initially
first
,
E...
the remaining elements the set is to contain initially
rest
)

Hides java.util.Set.of.

Creates an enum set initially containing the specified elements.

public static <
The class of the parameter elements and of the set
E extends Enum<E>
>
BitFieldSet<E>

Returns:

an enum set initially containing the specified elements
of
(@NotNull Class<E>
declaring class of enum
declaringClass
,
E[]
the remaining elements the set is to contain initially
rest
)

Hides java.util.Set.of.

Creates an enum set initially containing the specified elements.

public boolean
orMask(long mask)

public static long
orMask(long flags, long mask)

public static <
The class of the parameter elements and of the set
E extends Enum<E>
>
BitFieldSet<E>

Returns:

an enum set initially containing all of the elements in the range defined by the two specified endpoints
range
(E
the first element in the range
from
,
E
the last element in the range
to
)

Creates an enum set initially containing all of the elements in the range defined by the two specified endpoints.

private void
public boolean
remove(E e1, E e2)

public boolean
remove(E e1, E e2, E e3)

public boolean
remove(E e1, E e2, E e3, E e4)

public boolean
remove(E e1, E e2, E e3, E e4, E e5)

public final boolean
remove(E... rest)

public boolean

Returns:

true if the set contained the specified element
remove
(Object
element to be removed from this set, if present
e
)

Overrides java.util.AbstractCollection.remove.

Implements java.util.Set.remove, java.util.Collection.remove.

Removes the specified element from this set if it is present.

public boolean

Returns:

true if this set changed as a result of the call
removeAll
(Collection<?>
elements to be removed from this set
c
)

Overrides java.util.AbstractSet.removeAll.

Implements java.util.Set.removeAll, java.util.Collection.removeAll.

Removes from this set all of its elements that are contained in the specified collection.

public boolean

Returns:

true if any field values were modified
replaceAll
(long
bit fields values
mask
)
Deprecated use setAll(long)

Set all bit fields to values in mask

public boolean

Returns:

true if this set changed as a result of the call
retainAll
(Collection<?>
elements to be retained in this set
c
)

Overrides java.util.AbstractCollection.retainAll.

Implements java.util.Set.retainAll, java.util.Collection.retainAll.

Retains only the elements in this set that are contained in the specified collection.

public boolean
setAll(long mask)

public 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 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 boolean

Returns:

true if elements changed by operation
setSigned
(E
field
e1
,
long
value to set
value
)

Set a signed value for the field

pack-priv static <E extends Enum<E>> long
setSigned(long elements, E
field
e1
,
long
value to set
value
)

Set a signed value for the field

pack-priv static <E extends Enum<E>> long
setSigned(Class<E> elementType, long[] bitMasks, long elements, E
field
e1
,
long
value to set
value
)

Set a signed value for the field

public boolean

Returns:

true if elements changed by operation
setUnsigned
(E
field
e1
,
long
value to set
value
)

Set a signed value for the field

pack-priv static <E extends Enum<E>> long
setUnsigned(long elements, E
field
e1
,
long
value to set
value
)

Set an unsigned value for the field

pack-priv static <E extends Enum<E>> long
setUnsigned(Class<E> elementType, long[] bitMasks, long elements, E
field
e1
,
long
value to set
value
)

Set an unsigned value for the field

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 int

Returns:

the number of elements in this set
size
()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Set.size, java.util.Collection.size.

Returns the number of elements in this set.

public byte
public int
public long
public short
public String
toString()

Overrides java.util.AbstractCollection.toString.

Returns a string representation of this collection.

pack-priv final void
typeCheck(E e)

Throws an exception if e is not of the correct type for this enum set.

pack-priv Object
Inherited from java.util.AbstractSet:
hashCode