Package org.wildfly.common.flags
Class Flags<E extends Enum<E>,This extends Flags<E,This>>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
org.wildfly.common.flags.Flags<E,This>
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Set<E>,SortedSet<E>
public abstract class Flags<E extends Enum<E>,This extends Flags<E,This>>
extends AbstractSet<E>
implements SortedSet<E>
A base class for implementing value-like flags and flag sets, where flags and flag sets may be used without allocation
overhead.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract EcastItemOrNull(Object obj) Get the item (cast to the correctenumtype), ornullif it is not of the correct type.protected abstract ThisCast the given object to this class, throwing an exception if the cast fails.final Comparator<? super E>Get thenullcomparator, indicating that this set is always sorted in natural order.final ThisGet the complement of this set.final booleanDetermine if this flag set contains the given flag.final booleanDetermine if this flag set contains the given object.final booleancontainsAll(E flag1, E flag2) Determine if this flag set contains all of the given flags.final booleancontainsAll(E flag1, E flag2, E flag3) Determine if this flag set contains all of the given flags.final booleancontainsAll(Collection<?> c) Determine if this flag set contains all of the objects in the given collection.final booleancontainsAll(This other) Determine if this flag set contains all of the flags in the given flag set.final booleancontainsAny(E flag1, E flag2) Determine if this flag set contains any of the given flags.final booleancontainsAny(E flag1, E flag2, E flag3) Determine if this flag set contains any of the given flags.final booleancontainsAny(This other) Determine if this flag set contains any of the flags in the given flag set.Iterate this set in order from last to first flag.final booleanDetermine if this flag set is equal to the given object.final booleanDetermine if this flag set is equal to the given set.final booleanDetermine if this flag set is equal to the given flag set.final Efirst()Get the first flag in the set.voidApply the given action for every flag in this set.final inthashCode()Get the hash code of this flag set.final ThisGet the subset of flags from this set, up to (but not including) the given element.booleanisEmpty()Determine if this flag set is empty.protected abstract EitemOf(int index) Get the flag item with the given index.iterator()Iterate this set in order from first to last flag.final Elast()Get the last flag in the set.final intsize()Get the size of the flag set.final ThisGet the subset of flags, starting fromfromElementup to (but not including)toElement.final ThisGet the subset of flags from this set, starting from the given element.protected abstract Thisthis_()Returnthis.final Object[]toArray()Get anObjectarray containing all the flag values of this set.final <T> T[]toArray(T[] array) Get a typed array containing all the flag values of this set.final StringtoString()Get a string representation of this flag set.protected abstract Thisvalue(int bits) Get the set value of the given bit combination.final ThisReturn a set which includes all of the flags in this set and the given additional flag.final ThisReturn a set which includes all of the flags in this set and the given additional flags.final ThisReturn a set which includes all of the flags in this set and the given additional flags.final ThisReturn a set which includes all of the flags in this set and the given additional flags.final ThisReturn a set which includes all of the flags in this set and the given additional flags.final ThisReturn a set which includes all of the flags except for the given flag.final ThisReturn a set which includes all of the flags except for the given flags.Methods inherited from class java.util.AbstractSet
removeAllMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.SortedSet
spliterator
-
Constructor Details
-
Flags
protected Flags(int bits) Construct a new instance. This constructor should only be called during initial array construction.- Parameters:
bits- the bits of this set
-
-
Method Details
-
value
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- the bit combination (possibly with extra bits)- Returns:
- the set instance
-
this_
Returnthis.- Returns:
this
-
itemOf
Get the flag item with the given index.- Parameters:
index- the index- Returns:
- the flag
-
castItemOrNull
Get the item (cast to the correctenumtype), ornullif it is not of the correct type.- Parameters:
obj- the object to cast- Returns:
- the cast object, or
null
-
castThis
Cast the given object to this class, throwing an exception if the cast fails.- Parameters:
obj- the object to cast- Returns:
- the cast object
-
size
public final int size()Get the size of the flag set. -
first
Get the first flag in the set. -
last
Get the last flag in the set. -
comparator
Get thenullcomparator, indicating that this set is always sorted in natural order.- Specified by:
comparatorin interfaceSortedSet<E extends Enum<E>>- Returns:
null
-
isEmpty
public boolean isEmpty()Determine if this flag set is empty. -
headSet
Get the subset of flags from this set, up to (but not including) the given element. -
tailSet
Get the subset of flags from this set, starting from the given element. -
subSet
Get the subset of flags, starting fromfromElementup to (but not including)toElement. -
toArray
Get anObjectarray containing all the flag values of this set. -
toArray
public final <T> T[] toArray(T[] array) Get a typed array containing all the flag values of this set.- Specified by:
toArrayin interfaceCollection<E extends Enum<E>>- Specified by:
toArrayin interfaceSet<E extends Enum<E>>- Overrides:
toArrayin classAbstractCollection<E extends Enum<E>>- Type Parameters:
T- the element type- Parameters:
array- the array to populate or clone- Returns:
- the populated array
-
contains
Determine if this flag set contains the given flag.- Parameters:
flag- the flag- Returns:
trueif the flag is contained by this set
-
contains
Determine if this flag set contains the given object. -
containsAll
Determine if this flag set contains all of the objects in the given collection.- Specified by:
containsAllin interfaceCollection<E extends Enum<E>>- Specified by:
containsAllin interfaceSet<E extends Enum<E>>- Overrides:
containsAllin classAbstractCollection<E extends Enum<E>>- Parameters:
c- the collection- Returns:
trueif all of the collection's objects are contained by this set
-
containsAll
Determine if this flag set contains all of the flags in the given flag set.- Parameters:
other- the flag set- Returns:
trueif all of the given set's flags are contained by this set
-
containsAll
Determine if this flag set contains all of the given flags.- Parameters:
flag1- the first flagflag2- the second flag- Returns:
trueif all of the given flags are contained by this set
-
containsAll
Determine if this flag set contains all of the given flags.- Parameters:
flag1- the first flagflag2- the second flagflag3- the third flag- Returns:
trueif all of the given flags are contained by this set
-
containsAny
Determine if this flag set contains any of the flags in the given flag set.- Parameters:
other- the flag set- Returns:
trueif all of the given set's flags are contained by this set
-
containsAny
Determine if this flag set contains any of the given flags.- Parameters:
flag1- the first flagflag2- the second flag- Returns:
trueif any of the given flags are contained by this set
-
containsAny
Determine if this flag set contains any of the given flags.- Parameters:
flag1- the first flagflag2- the second flagflag3- the third flag- Returns:
trueif any of the given flags are contained by this set
-
complement
Get the complement of this set.- Returns:
- the complement of this set
-
with
Return a set which includes all of the flags in this set and the given additional flag.- Parameters:
flag- the additional flag- Returns:
- the combined set
-
with
Return a set which includes all of the flags in this set and the given additional flags.- Parameters:
flag1- the first flagflag2- the second flag- Returns:
- the combined set
-
with
Return a set which includes all of the flags in this set and the given additional flags.- Parameters:
flag1- the first flagflag2- the second flagflag3- the third flag- Returns:
- the combined set
-
with
Return a set which includes all of the flags in this set and the given additional flags.- Parameters:
flags- the additional flags- Returns:
- the combined set
-
with
Return a set which includes all of the flags in this set and the given additional flags.- Parameters:
other- the additional flags- Returns:
- the combined set
-
without
Return a set which includes all of the flags except for the given flag.- Parameters:
flag- the flag- Returns:
- the reduced set
-
without
Return a set which includes all of the flags except for the given flags.- Parameters:
other- the flags- Returns:
- the reduced set
-
equals
Determine if this flag set is equal to the given object. -
equals
Determine if this flag set is equal to the given set.- Parameters:
o- the other set- Returns:
trueif the set is equal to this set,falseotherwise
-
equals
Determine if this flag set is equal to the given flag set.- Parameters:
o- the other flag set- Returns:
trueif the flag set is equal to this set,falseotherwise
-
hashCode
public final int hashCode()Get the hash code of this flag set. -
iterator
Iterate this set in order from first to last flag. -
descendingIterator
Iterate this set in order from last to first flag.- Returns:
- the iterator
-
forEach
Apply the given action for every flag in this set. -
toString
Get a string representation of this flag set.- Overrides:
toStringin classAbstractCollection<E extends Enum<E>>- Returns:
- the string representation
-