Modifier and Type | Field and Description |
---|---|
static EnumBitMask<?> |
NONE16
16 bit mask with no flag set.
|
static EnumBitMask<?> |
NONE32
32 bit mask with no flag set.
|
static EnumBitMask<?> |
NONE64
64 bit mask with no flag set.
|
Constructor and Description |
---|
EnumBitMask(BitMask bitMask)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
EnumBitMask<E> |
and(EnumBitMask<E> other)
Get a bit mask where all flags are set which are set in this and in another one.
|
<F extends java.lang.Enum<F> & BitFlag> |
cast(java.lang.Class<F> enumClass)
Cast this enum bit mask to one using a different kind of bit flags.
|
EnumBitMask<E> |
clear(E flag)
Clear the given flag.
|
EnumBitMask<E> |
clear(EnumBitMask<E> other)
Get a bit mask where all flags are cleared which are set in another one.
|
EnumBitMask<E> |
clearAll(E... flags)
Clear all given flags.
|
EnumBitMask<E> |
cleared()
Get a version of this enum bit mask where all flags are cleared.
|
static <F extends java.lang.Enum<F> & BitFlag> |
combine(F... bitFlags)
Combine bit flags using an arbitrary number of bits into a bit mask.
|
static <F extends java.lang.Enum<F> & BitFlag> |
combine(java.lang.Iterable<F> bitFlags)
Combine bit flags using an arbitrary number of bits into a bit mask.
|
static <F extends java.lang.Enum<F> & BitFlag> |
combine16(java.util.Collection<F> bitFlags)
Combine bit flags using at maximum 16 bits into a bit mask.
|
static <F extends java.lang.Enum<F> & BitFlag> |
combine16(F... bitFlags)
Combine bit flags using at maximum 16 bits into a bit mask.
|
static <F extends java.lang.Enum<F> & BitFlag> |
combine32(java.util.Collection<F> bitFlags)
Combine bit flags using at maximum 32 bits into a bit mask.
|
static <F extends java.lang.Enum<F> & BitFlag> |
combine32(F... bitFlags)
Combine bit flags using at maximum 32 bits into a bit mask.
|
static <F extends java.lang.Enum<F> & BitFlag> |
combine64(java.util.Collection<F> bitFlags)
Combine bit flags using at maximum 64 bits into a bit mask.
|
static <F extends java.lang.Enum<F> & BitFlag> |
combine64(F... bitFlags)
Combine bit flags using at maximum 64 bits into a bit mask.
|
boolean |
equals(java.lang.Object o) |
java.util.List<E> |
flags(java.lang.Class<E> flagType)
Get a list of all flags which are set in this mask.
|
EnumBitMask<E> |
flip(E flag)
Flip the given flag.
|
EnumBitMask<E> |
flipAll(E... flags)
Flip all given flags.
|
void |
forEachSet(java.lang.Iterable<E> flags,
java.util.function.Consumer<? super E> handler)
Call a handler for each of the given flags which is set in this bit mask.
|
void |
forEachUnset(java.lang.Iterable<E> flags,
java.util.function.Consumer<? super E> handler)
Call a handler for each of the given flags which is unset in this bit mask.
|
static <T extends java.lang.Enum<T> & BitFlag> |
get16(EnumBitMask<T> mask,
T... flags)
Get a cached 16bit mask for a combination of flags.
|
static <T extends java.lang.Enum<T> & BitFlag> |
get16(int value,
java.lang.Class<T> type)
Get a cached 16bit mask for the given value.
|
static <T extends java.lang.Enum<T> & BitFlag> |
get16(T... flags)
Get a cached 16bit mask for a combination of flags.
|
static <T extends java.lang.Enum<T> & BitFlag> |
get32(EnumBitMask<T> mask,
T... flags)
Get a cached 32bit mask for a combination of flags.
|
static <T extends java.lang.Enum<T> & BitFlag> |
get32(java.lang.Integer value,
java.lang.Class<T> type)
Get a cached 32bit mask for the given value.
|
static <T extends java.lang.Enum<T> & BitFlag> |
get32(T... flags)
Get a cached 32bit mask for a combination of flags.
|
java.util.List<E> |
getAllCleared(E... flags)
Get a list of all flags which are not set in this mask.
|
java.util.List<E> |
getAllCleared(java.lang.Iterable<E> flags)
Get a list of all flags which are not set in this mask.
|
java.util.List<E> |
getAllSet(E... flags)
Get a list of all flags out of a given set which are set in this mask.
|
java.util.List<E> |
getAllSet(java.lang.Iterable<E> flags)
Get a list of all flags which are set in this mask.
|
BitMask |
getBitMask()
Get the underlying bit mask,
|
int |
getCardinality()
Get the cardinality of this enum bit mask.
|
int |
getHighestFlagSet()
Get the highest flag set.
|
int |
getLowestFlagSet()
Get the lowest flag set.
|
int |
hashCode() |
boolean |
isEmpty()
Is no flag set?
|
boolean |
isSet(E flag)
Is the given flag set?
|
boolean |
isSetAll(java.util.Collection<E> flags)
Are all flags from the given collection set?
|
boolean |
isSetAll(E... flags)
Are all flags from the given sequence set?
|
boolean |
isSetAll(EnumBitMask<E> other)
Are all flags set in the other bitmask set in this bitmask, too?
|
boolean |
isSetAny(java.util.Collection<E> flags)
Is any flag from the given collection set?
|
boolean |
isSetAny(E... flags)
Is any flag from the given sequence set?
|
boolean |
isSetAny(EnumBitMask<E> other)
Is any flag in both this and the other bit mask set?
|
EnumBitMask<E> |
map(java.lang.Iterable<E> flagsToCheck,
java.util.function.BiPredicate<? super E,java.lang.Boolean> mapping)
Map the chosen flags from this mask to another flag
|
EnumBitMask<E> |
mapFromSet(java.lang.Iterable<E> flagsToCheck,
java.util.function.Predicate<? super E> mapping)
Map the chosen set flags from this mask to another mask.
|
EnumBitMask<E> |
mapFromUnset(java.lang.Iterable<E> flagsToCheck,
java.util.function.Predicate<? super E> mapping)
Map the chosen unset flags from this mask to another mask.
|
EnumBitMask<E> |
or(EnumBitMask<E> other)
Get a bit mask where all flags are set which are set in this or in another one.
|
EnumBitMask<E> |
set(E flag)
Set the given flag.
|
EnumBitMask<E> |
setAll(E... flags)
Set all given flags.
|
EnumBitMask<E> |
setTo(E flag,
boolean onOff)
Set or clear the given flag.
|
static <F extends java.lang.Enum<F> & BitFlag> |
toFlags(EnumBitMask<F> mask,
java.lang.Class<F> enumClass)
Divide a bit mask into a set of flags.
|
static <F extends java.lang.Enum<F> & BitFlag> |
toMask(F flag)
Convert a flag to a generic bit mask.
|
static <F extends java.lang.Enum<F> & BitFlag> |
toMask16(F flag)
Convert a flag to a 16 bit bit mask.
|
static <F extends java.lang.Enum<F> & BitFlag> |
toMask32(F flag)
Convert a flag to a 32 bit bit mask.
|
static <F extends java.lang.Enum<F> & BitFlag> |
toMask64(F flag)
Convert a flag to a 64 bit bit mask.
|
java.lang.String |
toString()
Get a string representation.
|
EnumBitMask<E> |
unique16()
Get the unique object representing the given 16bit flags.
|
EnumBitMask<E> |
unique32()
Get the unique object representing the given 32bit flags.
|
public static final EnumBitMask<?> NONE16
public static final EnumBitMask<?> NONE32
public static final EnumBitMask<?> NONE64
public boolean isSet(@NotNull E flag)
flag
- flag to checktrue
: the flag is setfalse
: the flag is not setpublic boolean isSetAny(@NotNull EnumBitMask<E> other)
other
- other bit masktrue
: if any bit is set in both masksfalse
: if no bit is set in both maskspublic boolean isSetAll(@NotNull EnumBitMask<E> other)
other
- other bit masktrue
: if all set flags of the other mask are set in this maskfalse
: if any flag set in the other mask is not set in this mask@SafeVarargs public final boolean isSetAny(@NotNull E... flags)
flags
- flags to checktrue
: if any bit flag is set in this masksfalse
: if no bit flag is set in this maskspublic boolean isSetAny(@NotNull java.util.Collection<E> flags)
flags
- flags to checktrue
: if any bit flag is set in this masksfalse
: if no bit flag is set in this masks@SafeVarargs public final boolean isSetAll(@NotNull E... flags)
flags
- flags to checktrue
: if every bit flag is set in this masksfalse
: if any bit flag is not set in this maskspublic boolean isSetAll(@NotNull java.util.Collection<E> flags)
flags
- flags to checktrue
: if every bit flag is set in this masksfalse
: if any bit flag is not set in this maskspublic EnumBitMask<E> or(@NotNull EnumBitMask<E> other)
other
- other bit mask defining the flags which are setand(EnumBitMask)
,
clear(EnumBitMask)
public EnumBitMask<E> and(@NotNull EnumBitMask<E> other)
other
- other bit mask defining the flags which are setor(EnumBitMask)
,
clear(EnumBitMask)
@NotNull public EnumBitMask<E> set(@NotNull E flag)
flag
- flag to setpublic EnumBitMask<E> setTo(@NotNull E flag, boolean onOff)
flag
- flag to changeonOff
- true
: set the flagfalse
: clear the flag@SafeVarargs @NotNull public final EnumBitMask<E> setAll(@NotNull E... flags)
flags
- flags to set@NotNull public EnumBitMask<E> clear(@NotNull E flag)
flag
- flag to clearpublic EnumBitMask<E> clear(@NotNull EnumBitMask<E> other)
other
- other bit mask defining the flags which are clearedand(EnumBitMask)
,
or(EnumBitMask)
@SafeVarargs @NotNull public final EnumBitMask<E> clearAll(@NotNull E... flags)
flags
- flags to clear@NotNull public EnumBitMask<E> flip(@NotNull E flag)
flag
- flag to flip@SafeVarargs @NotNull public final EnumBitMask<E> flipAll(@NotNull E... flags)
flags
- flags to flippublic int getCardinality()
BitMask.getCardinality()
@NotNull @SafeVarargs public final java.util.List<E> getAllSet(@NotNull E... flags)
flags
- flags to checkflags(Class)
,
getAllSet(Iterable)
public void forEachSet(@NotNull java.lang.Iterable<E> flags, @NotNull java.util.function.Consumer<? super E> handler)
flags
- flags to checkhandler
- handler called with all flags from flags
that are setpublic void forEachUnset(@NotNull java.lang.Iterable<E> flags, @NotNull java.util.function.Consumer<? super E> handler)
flags
- flags to checkhandler
- handler called with all flags from flags
that are unset@NotNull public java.util.List<E> flags(@NotNull java.lang.Class<E> flagType)
flagType
- type of flags in this mask, must match the type of flags used in this mask.
Necessary due to the quirks of the Java type system.getAllSet(Enum[])
,
getAllSet(Iterable)
@NotNull public java.util.List<E> getAllSet(@NotNull java.lang.Iterable<E> flags)
flags
- flags to checkflags(Class)
,
getAllSet(Enum[])
@NotNull @SafeVarargs public final java.util.List<E> getAllCleared(@NotNull E... flags)
flags
- flags to check@NotNull public java.util.List<E> getAllCleared(@NotNull java.lang.Iterable<E> flags)
flags
- flags to checkpublic int getHighestFlagSet()
BitMask.getHighestBitSet()
)
and not in enum order.-1
if no flag is setpublic int getLowestFlagSet()
BitMask.getLowestBitSet()
)
and not in enum order.-1
if no flag is setpublic boolean isEmpty()
true
: if no flag in this bit mask is setfalse
: if any flag in this bit mask is set@NotNull public EnumBitMask<E> cleared()
@NotNull public <F extends java.lang.Enum<F> & BitFlag> EnumBitMask<F> cast(@NotNull java.lang.Class<F> enumClass)
F
- type of enum bit flag classenumClass
- new enum bit flag class@NotNull public EnumBitMask<E> unique16()
@NotNull public EnumBitMask<E> unique32()
@NotNull public EnumBitMask<E> mapFromSet(@NotNull java.lang.Iterable<E> flagsToCheck, @NotNull java.util.function.Predicate<? super E> mapping)
flagsToCheck
- set of flags to check from this maskmapping
- predicate called for each checked flag which is set
deciding which flags are set in the result@NotNull public EnumBitMask<E> mapFromUnset(@NotNull java.lang.Iterable<E> flagsToCheck, @NotNull java.util.function.Predicate<? super E> mapping)
flagsToCheck
- set of flags to check from this maskmapping
- predicate called for each checked flag which is unset
deciding which flags are set in the result@NotNull public EnumBitMask<E> map(@NotNull java.lang.Iterable<E> flagsToCheck, @NotNull java.util.function.BiPredicate<? super E,java.lang.Boolean> mapping)
flagsToCheck
- set of flags to check from this maskmapping
- predicate called for each flag from the set,
second parameter is true
if the flag is set
and false
if it is unset@NotNull public static <F extends java.lang.Enum<F> & BitFlag> EnumBitMask<F> toMask(@NotNull F flag)
This internally uses a bit set bit mask, which allows for all possible flags.
F
- type of bit flagflag
- flag to convert@NotNull public static <F extends java.lang.Enum<F> & BitFlag> EnumBitMask<F> toMask16(@NotNull F flag)
F
- type of bit flagflag
- flag to convert@NotNull public static <F extends java.lang.Enum<F> & BitFlag> EnumBitMask<F> toMask32(@NotNull F flag)
F
- type of bit flagflag
- flag to convert@NotNull public static <F extends java.lang.Enum<F> & BitFlag> EnumBitMask<F> toMask64(@NotNull F flag)
F
- type of bit flagflag
- flag to convert@NotNull public static <F extends java.lang.Enum<F> & BitFlag> java.util.Set<F> toFlags(@NotNull EnumBitMask<F> mask, @NotNull java.lang.Class<F> enumClass)
F
- type of bit flagmask
- bit maskenumClass
- class of the enum flags in this mask, necessary to overcome
the shortcomings of Java genericscombine(Enum[])
,
combine(BitMask, Enum[])
,
combine16(Collection)
,
combine32(Collection)
,
combine64(Collection)
@SafeVarargs @NotNull public static <F extends java.lang.Enum<F> & BitFlag> EnumBitMask<F> combine16(F... bitFlags)
F
- bit flag typebitFlags
- bit flagsget16(Enum[])
@NotNull public static <F extends java.lang.Enum<F> & BitFlag> EnumBitMask<F> combine16(@NotNull java.util.Collection<F> bitFlags)
F
- bit flag typebitFlags
- bit flags to combine@SafeVarargs @NotNull public static <F extends java.lang.Enum<F> & BitFlag> EnumBitMask<F> combine32(F... bitFlags)
F
- bit flag typebitFlags
- bit flagsget32(Enum[])
@NotNull public static <F extends java.lang.Enum<F> & BitFlag> EnumBitMask<F> combine32(@NotNull java.util.Collection<F> bitFlags)
F
- bit flag typebitFlags
- bit flags to combine@SafeVarargs @NotNull public static <F extends java.lang.Enum<F> & BitFlag> EnumBitMask<F> combine64(F... bitFlags)
F
- bit flag typebitFlags
- bit flags@NotNull public static <F extends java.lang.Enum<F> & BitFlag> EnumBitMask<F> combine64(@NotNull java.util.Collection<F> bitFlags)
F
- bit flag typebitFlags
- bit flags@SafeVarargs @NotNull public static <F extends java.lang.Enum<F> & BitFlag> EnumBitMask<F> combine(F... bitFlags)
F
- bit flag typebitFlags
- bit flags@NotNull public static <F extends java.lang.Enum<F> & BitFlag> EnumBitMask<F> combine(@NotNull java.lang.Iterable<F> bitFlags)
F
- bit flag typebitFlags
- bit flags to combinepublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
@NotNull public static <T extends java.lang.Enum<T> & BitFlag> EnumBitMask<T> get16(int value, @NotNull java.lang.Class<T> type)
This is an optimization reducing created bit masks.
T
- enum typevalue
- value (an int only for convenience, only the low 16bits are used)type
- enum type of returned@SafeVarargs @NotNull public static <T extends java.lang.Enum<T> & BitFlag> EnumBitMask<T> get16(T... flags)
This is an optimization reducing created bit masks.
T
- enum typeflags
- flags to combine@SafeVarargs @NotNull public static <T extends java.lang.Enum<T> & BitFlag> EnumBitMask<T> get16(@NotNull EnumBitMask<T> mask, @NotNull T... flags)
This is an optimization reducing created bit masks.
T
- enum typemask
- basic maskflags
- flags to combine with mask@NotNull public static <T extends java.lang.Enum<T> & BitFlag> EnumBitMask<T> get32(@NotNull java.lang.Integer value, @NotNull java.lang.Class<T> type)
This is an optimization reducing the number of created bit masks.
T
- enum typevalue
- valuetype
- enum type of returned@SafeVarargs @NotNull public static <T extends java.lang.Enum<T> & BitFlag> EnumBitMask<T> get32(T... flags)
This is an optimization reducing created bit masks.
T
- enum typeflags
- flags to combine@SafeVarargs @NotNull public static <T extends java.lang.Enum<T> & BitFlag> EnumBitMask<T> get32(@NotNull EnumBitMask<T> mask, @NotNull T... flags)
This is an optimization reducing created bit masks.
T
- enum typemask
- basic maskflags
- flags to combine with mask