Top Description Fields Constructors Methods
org.wildfly.common.flags

public abstract Class Flags<E extends java.lang.Enum<E>, This extends org.wildfly.common.flags.Flags<E, This>>

extends AbstractSet<E extends Enum<E>>
implements SortedSet<E extends Enum<E>>
Class Inheritance
All Implemented Interfaces
java.util.SortedSet, java.util.SequencedSet, java.util.Set, java.util.Collection, java.lang.Iterable, java.util.SequencedCollection
Static Imports
java.lang.Integer.bitCount, .Integer.highestOneBit, .Integer.lowestOneBit, .Integer.numberOfTrailingZeros

A base class for implementing value-like flags and flag sets, where flags and flag sets may be used without allocation overhead.

Field Summary

Modifier and TypeField and Description
pack-priv final int

Constructor Summary

AccessConstructor and Description
protected
Flags(final int
the bits of this set
bits
)

Construct a new instance.

Method Summary

Modifier and TypeMethod and Description
private static int
bitOf(Enum<?> item)

protected abstract E

Returns:

the cast object, or null
castItemOrNull
(Object
the object to cast
obj
)

Get the item (cast to the correct enum type), or null if it is not of the correct type.

protected abstract This

Returns:

the cast object
castThis
(Object
the object to cast
obj
)

Cast the given object to this class, throwing an exception if the cast fails.

public final Comparator<? super E>

Returns:

null
comparator
()

Implements java.util.SortedSet.comparator.

Get the null comparator, indicating that this set is always sorted in natural order.
public final This

Returns:

the complement of this set
complement
()

Get the complement of this set.

public final boolean

Returns:

true if the flag is contained by this set
contains
(E
the flag
flag
)

Determine if this flag set contains the given flag.

public final boolean

Returns:

true if the object is contained by this set
contains
(final Object
the object
o
)

Overrides java.util.AbstractCollection.contains.

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

Determine if this flag set contains the given object.
public final boolean

Returns:

true if all of the collection's objects are contained by this set
containsAll
(final Collection<?>
the collection
c
)

Overrides java.util.AbstractCollection.containsAll.

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

Determine if this flag set contains all of the objects in the given collection.
public final boolean

Returns:

true if all of the given set's flags are contained by this set
containsAll
(This
the flag set
other
)

Determine if this flag set contains all of the flags in the given flag set.

public final boolean

Returns:

true if all of the given flags are contained by this set
containsAll
(E
the first flag
flag1
,
E
the second flag
flag2
)

Determine if this flag set contains all of the given flags.

public final boolean

Returns:

true if all of the given flags are contained by this set
containsAll
(E
the first flag
flag1
,
E
the second flag
flag2
,
E
the third flag
flag3
)

Determine if this flag set contains all of the given flags.

public final boolean

Returns:

true if all of the given set's flags are contained by this set
containsAny
(This
the flag set
other
)

Determine if this flag set contains any of the flags in the given flag set.

public final boolean

Returns:

true if any of the given flags are contained by this set
containsAny
(E
the first flag
flag1
,
E
the second flag
flag2
)

Determine if this flag set contains any of the given flags.

public final boolean

Returns:

true if any of the given flags are contained by this set
containsAny
(E
the first flag
flag1
,
E
the second flag
flag2
,
E
the third flag
flag3
)

Determine if this flag set contains any of the given flags.

public final Iterator<E>

Returns:

the iterator
descendingIterator
()

Iterate this set in order from last to first flag.

public final boolean

Returns:

true if the object is equal to this set, false otherwise
equals
(final Object
the other object
o
)

Overrides java.util.AbstractSet.equals.

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

Determine if this flag set is equal to the given object.
public final boolean

Returns:

true if the set is equal to this set, false otherwise
equals
(final Set<?>
the other set
o
)

Determine if this flag set is equal to the given set.

public final boolean

Returns:

true if the flag set is equal to this set, false otherwise
equals
(final This
the other flag set
o
)

Determine if this flag set is equal to the given flag set.

public final E

Returns:

the first flag
first
()

Implements java.util.SortedSet.first.

Get the first flag in the set.
public void
forEach(final Consumer<? super E>
the action to apply
action
)

Overrides default java.lang.Iterable.forEach.

Apply the given action for every flag in this set.
public final int

Returns:

the flag set hash code
hashCode
()

Overrides java.util.AbstractSet.hashCode.

Implements java.util.Set.hashCode, java.util.Collection.hashCode.

Get the hash code of this flag set.
public final This

Returns:

the subset
headSet
(final E
the "to" element (must not be null)
toElement
)

Implements java.util.SortedSet.headSet.

Get the subset of flags from this set, up to (but not including) the given element.
public boolean

Returns:

true if the flag set is empty, false otherwise
isEmpty
()

Overrides java.util.AbstractCollection.isEmpty.

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

Determine if this flag set is empty.
protected abstract E

Returns:

the flag
itemOf
(int
the index
index
)

Get the flag item with the given index.

public final Iterator<E>

Returns:

the iterator
iterator
()

Implements abstract java.util.AbstractCollection.iterator.

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

Iterate this set in order from first to last flag.
public final E

Returns:

the last flag
last
()

Implements java.util.SortedSet.last.

Get the last flag in the set.
public final int

Returns:

the flag set size
size
()

Implements abstract java.util.AbstractCollection.size.

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

Get the size of the flag set.
public final This

Returns:

the subset
subSet
(final E
the "from" element (must not be null)
fromElement
,
final E
the "to" element (must not be null)
toElement
)

Implements java.util.SortedSet.subSet.

Get the subset of flags, starting from fromElement up to (but not including) toElement.
public final This

Returns:

the subset
tailSet
(final E
the "from" element (must not be null)
fromElement
)

Implements java.util.SortedSet.tailSet.

Get the subset of flags from this set, starting from the given element.
protected abstract This

Returns:

this
this_
()

Return this.

public final Object[]

Returns:

the Object array
toArray
()

Overrides java.util.AbstractCollection.toArray.

Implements java.util.Set.toArray, java.util.Collection.toArray.

Get an Object array containing all the flag values of this set.
public final <
the element type
T
>
T[]

Returns:

the populated array
toArray
(T[]
the array to populate or clone
array
)

Overrides java.util.AbstractCollection.toArray.

Implements java.util.Set.toArray, java.util.Collection.toArray.

Get a typed array containing all the flag values of this set.
public final String

Returns:

the string representation
toString
()

Overrides java.util.AbstractCollection.toString.

Get a string representation of this flag set.
protected abstract This

Returns:

the set instance
value
(int
the bit combination (possibly with extra bits)
bits
)

Get the set value of the given bit combination.

public final This

Returns:

the combined set
with
(E
the additional flag
flag
)

Return a set which includes all of the flags in this set and the given additional flag.

public final This

Returns:

the combined set
with
(E
the first flag
flag1
,
E
the second flag
flag2
)

Return a set which includes all of the flags in this set and the given additional flags.

public final This

Returns:

the combined set
with
(E
the first flag
flag1
,
E
the second flag
flag2
,
E
the third flag
flag3
)

Return a set which includes all of the flags in this set and the given additional flags.

public final This

Returns:

the combined set
with
(E...
the additional flags
flags
)

Return a set which includes all of the flags in this set and the given additional flags.

public final This

Returns:

the combined set
with
(This
the additional flags
other
)

Return a set which includes all of the flags in this set and the given additional flags.

public final This

Returns:

the reduced set
without
(E
the flag
flag
)

Return a set which includes all of the flags except for the given flag.

public final This

Returns:

the reduced set
without
(This
the flags
other
)

Return a set which includes all of the flags except for the given flags.

Inherited from java.util.AbstractSet:
removeAll

Field Detail

bitsback to summary
pack-priv final int bits

Constructor Detail

Flagsback to summary
protected Flags(final int bits)

Construct a new instance. This constructor should only be called during initial array construction.

Parameters
bits:int

the bits of this set

Method Detail

bitOfback to summary
private static int bitOf(Enum<?> item)
castItemOrNullback to summary
protected abstract E castItemOrNull(Object obj)

Get the item (cast to the correct enum type), or null if it is not of the correct type.

Parameters
obj:Object

the object to cast

Returns:E

the cast object, or null

castThisback to summary
protected abstract This castThis(Object obj)

Cast the given object to this class, throwing an exception if the cast fails.

Parameters
obj:Object

the object to cast

Returns:This

the cast object

comparatorback to summary
public final Comparator<? super E> comparator()

Implements java.util.SortedSet.comparator.

Get the null comparator, indicating that this set is always sorted in natural order.

Returns:Comparator<? super E>

null

complementback to summary
public final This complement()

Get the complement of this set.

Returns:This

the complement of this set

containsback to summary
public final boolean contains(E flag)

Determine if this flag set contains the given flag.

Parameters
flag:E

the flag

Returns:boolean

true if the flag is contained by this set

containsback to summary
public final boolean contains(final Object o)

Overrides java.util.AbstractCollection.contains.

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

Determine if this flag set contains the given object.

Parameters
o:Object

the object

Returns:boolean

true if the object is contained by this set

containsAllback to summary
public final boolean containsAll(final Collection<?> c)

Overrides java.util.AbstractCollection.containsAll.

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

Determine if this flag set contains all of the objects in the given collection.

Parameters
c:Collection<?>

the collection

Returns:boolean

true if all of the collection's objects are contained by this set

containsAllback to summary
public final boolean containsAll(This other)

Determine if this flag set contains all of the flags in the given flag set.

Parameters
other:This

the flag set

Returns:boolean

true if all of the given set's flags are contained by this set

containsAllback to summary
public final boolean containsAll(E flag1, E flag2)

Determine if this flag set contains all of the given flags.

Parameters
flag1:E

the first flag

flag2:E

the second flag

Returns:boolean

true if all of the given flags are contained by this set

containsAllback to summary
public final boolean containsAll(E flag1, E flag2, E flag3)

Determine if this flag set contains all of the given flags.

Parameters
flag1:E

the first flag

flag2:E

the second flag

flag3:E

the third flag

Returns:boolean

true if all of the given flags are contained by this set

containsAnyback to summary
public final boolean containsAny(This other)

Determine if this flag set contains any of the flags in the given flag set.

Parameters
other:This

the flag set

Returns:boolean

true if all of the given set's flags are contained by this set

containsAnyback to summary
public final boolean containsAny(E flag1, E flag2)

Determine if this flag set contains any of the given flags.

Parameters
flag1:E

the first flag

flag2:E

the second flag

Returns:boolean

true if any of the given flags are contained by this set

containsAnyback to summary
public final boolean containsAny(E flag1, E flag2, E flag3)

Determine if this flag set contains any of the given flags.

Parameters
flag1:E

the first flag

flag2:E

the second flag

flag3:E

the third flag

Returns:boolean

true if any of the given flags are contained by this set

descendingIteratorback to summary
public final Iterator<E> descendingIterator()

Iterate this set in order from last to first flag.

Returns:Iterator<E>

the iterator

equalsback to summary
public final boolean equals(final Object o)

Overrides java.util.AbstractSet.equals.

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

Determine if this flag set is equal to the given object.

Parameters
o:Object

the other object

Returns:boolean

true if the object is equal to this set, false otherwise

equalsback to summary
public final boolean equals(final Set<?> o)

Determine if this flag set is equal to the given set.

Parameters
o:Set<?>

the other set

Returns:boolean

true if the set is equal to this set, false otherwise

equalsback to summary
public final boolean equals(final This o)

Determine if this flag set is equal to the given flag set.

Parameters
o:This

the other flag set

Returns:boolean

true if the flag set is equal to this set, false otherwise

firstback to summary
public final E first()

Implements java.util.SortedSet.first.

Get the first flag in the set.

Returns:E

the first flag

forEachback to summary
public void forEach(final Consumer<? super E> action)

Overrides default java.lang.Iterable.forEach.

Apply the given action for every flag in this set.

Parameters
action:Consumer<? super E>

the action to apply

hashCodeback to summary
public final int hashCode()

Overrides java.util.AbstractSet.hashCode.

Implements java.util.Set.hashCode, java.util.Collection.hashCode.

Get the hash code of this flag set.

Returns:int

the flag set hash code

headSetback to summary
public final This headSet(final E toElement)

Implements java.util.SortedSet.headSet.

Get the subset of flags from this set, up to (but not including) the given element.

Parameters
toElement:E

the "to" element (must not be null)

Returns:This

the subset

isEmptyback to summary
public boolean isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

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

Determine if this flag set is empty.

Returns:boolean

true if the flag set is empty, false otherwise

itemOfback to summary
protected abstract E itemOf(int index)

Get the flag item with the given index.

Parameters
index:int

the index

Returns:E

the flag

iteratorback to summary
public final Iterator<E> iterator()

Implements abstract java.util.AbstractCollection.iterator.

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

Iterate this set in order from first to last flag.

Returns:Iterator<E>

the iterator

lastback to summary
public final E last()

Implements java.util.SortedSet.last.

Get the last flag in the set.

Returns:E

the last flag

sizeback to summary
public final int size()

Implements abstract java.util.AbstractCollection.size.

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

Get the size of the flag set.

Returns:int

the flag set size

subSetback to summary
public final This subSet(final E fromElement, final E toElement)

Implements java.util.SortedSet.subSet.

Get the subset of flags, starting from fromElement up to (but not including) toElement.

Parameters
fromElement:E

the "from" element (must not be null)

toElement:E

the "to" element (must not be null)

Returns:This

the subset

tailSetback to summary
public final This tailSet(final E fromElement)

Implements java.util.SortedSet.tailSet.

Get the subset of flags from this set, starting from the given element.

Parameters
fromElement:E

the "from" element (must not be null)

Returns:This

the subset

this_back to summary
protected abstract This this_()

Return this.

Returns:This

this

toArrayback to summary
public final Object[] toArray()

Overrides java.util.AbstractCollection.toArray.

Implements java.util.Set.toArray, java.util.Collection.toArray.

Get an Object array containing all the flag values of this set.

Returns:Object[]

the Object array

toArrayback to summary
public final <T> T[] toArray(T[] array)

Overrides java.util.AbstractCollection.toArray.

Implements java.util.Set.toArray, java.util.Collection.toArray.

Get a typed array containing all the flag values of this set.

Parameters
<T>
the element type
array:T[]

the array to populate or clone

Returns:T[]

the populated array

Annotations
@SuppressWarnings:unchecked
toStringback to summary
public final String toString()

Overrides java.util.AbstractCollection.toString.

Get a string representation of this flag set.

Returns:String

the string representation

valueback to summary
protected abstract This value(int bits)

Get the set value of the given bit combination. The bit combination may contain extraneous one-bits so any bits beyond the bit of the last flag should be masked off if an array is used for lookup.

Parameters
bits:int

the bit combination (possibly with extra bits)

Returns:This

the set instance

withback to summary
public final This with(E flag)

Return a set which includes all of the flags in this set and the given additional flag.

Parameters
flag:E

the additional flag

Returns:This

the combined set

withback to summary
public final This with(E flag1, E flag2)

Return a set which includes all of the flags in this set and the given additional flags.

Parameters
flag1:E

the first flag

flag2:E

the second flag

Returns:This

the combined set

withback to summary
public final This with(E flag1, E flag2, E flag3)

Return a set which includes all of the flags in this set and the given additional flags.

Parameters
flag1:E

the first flag

flag2:E

the second flag

flag3:E

the third flag

Returns:This

the combined set

withback to summary
public final This with(E... flags)

Return a set which includes all of the flags in this set and the given additional flags.

Parameters
flags:E[]

the additional flags

Returns:This

the combined set

Annotations
@SafeVarargs
withback to summary
public final This with(This other)

Return a set which includes all of the flags in this set and the given additional flags.

Parameters
other:This

the additional flags

Returns:This

the combined set

withoutback to summary
public final This without(E flag)

Return a set which includes all of the flags except for the given flag.

Parameters
flag:E

the flag

Returns:This

the reduced set

withoutback to summary
public final This without(This other)

Return a set which includes all of the flags except for the given flags.

Parameters
other:This

the flags

Returns:This

the reduced set