public class FlagsEnum extends LegacyEnum
Modifier and Type | Class and Description |
---|---|
private static interface |
FlagsEnum.BitwiseOperation
Process two long values using some kind of bitwise operation and return the calculated value.
|
LegacyEnum.EnumControlRecord<E extends LegacyEnum>, LegacyEnum.EnumInitializer<E extends LegacyEnum>, LegacyEnum.NameLookupHelper<E extends LegacyEnum>
Modifier and Type | Field and Description |
---|---|
private boolean |
aliased
Identifies an enum which is an alias for one or more other flag enum values.
|
private static int |
HIGH_NEGATIVE_BOUNDARY
Negative values greater than or equal to this will trigger the maximal bitfield matching quirk.
|
private static java.lang.String |
ISSET_UNKNOWN
Error message for unknown value input in IsFlagSet.
|
private static java.lang.String |
ISSET_ZERO
Error message for zero value input in IsFlagSet.
|
private static java.lang.String |
MISMATCHED_INPUT
Error message for mismatched enum class as a parameter.
|
private boolean |
multibit
Identifies dynamically created multibit flags enums.
|
private boolean |
predefined
Identifies an enum which was predefined.
|
name, value
Modifier | Constructor and Description |
---|---|
protected |
FlagsEnum(java.lang.String name,
long value)
Construct an immutable enum instance with the given state.
|
Modifier and Type | Method and Description |
---|---|
static object<? extends FlagsEnum> |
and(object<? extends FlagsEnum> op1,
object<? extends FlagsEnum> op2)
Create a new enum instance that has all bits turned ON which are ON in both operands and return the
resulting enum.
|
private <T extends FlagsEnum> |
bitwiseWorker(object<T> op2,
FlagsEnum.BitwiseOperation bits,
java.lang.String meth)
Process the given binary bitwise operation with the current instance (
this ) as the first
operand and the op2 as the second operand. |
private static int |
compareValues(LegacyEnum e1,
LegacyEnum e2)
Flags enum comparator.
|
private java.lang.String |
dump()
Render the instance as text.
|
private static FlagsEnum |
getExistingOrCreate(java.lang.Class<FlagsEnum> cls,
long value)
For the given enum class and value, return any predefined instance which is an exact match or if no
match exists then create a new multibit instance for the given value (with no name).
|
private static void |
incompatibleDataTypes()
Generate an error 223 (normally a compile error) when the operator inputs are the wrong type
(different enum classes when they must be the same exact enum type).
|
private static <E extends LegacyEnum> |
initialize(LegacyEnum.EnumControlRecord<E> ecr,
E created,
E pattern)
Post-process a new enum to set state.
|
logical |
isFlagSet(object<? extends FlagsEnum> that)
Report if all bits which are set in the input enum are also set in this current enum
instance.
|
private static boolean |
isMultibit(long value)
Detect if more than one bit is set in the given value.
|
private static <E extends LegacyEnum> |
lookupNameSafeAdapter(LegacyEnum.EnumControlRecord<E> ecr,
java.lang.String name)
Return the enum instance of the given type which is associated with the provided name.
|
protected static <E extends LegacyEnum> |
lookupNameWorker(LegacyEnum.EnumControlRecord<E> ecr,
java.lang.String name)
Return the enum instance of the given type which is associated with the provided name.
|
protected static <E extends LegacyEnum> |
lookupNameWorkerSafe(LegacyEnum.EnumControlRecord<E> ecr,
java.lang.String name,
boolean trim)
Return the enum instance of the given type which is associated with the provided name.
|
protected static <E extends LegacyEnum> |
lookupValueWorker(LegacyEnum.EnumControlRecord<E> ecr,
long value)
Return the enum instance of the given type which is associated with the provided value.
|
protected static <E extends LegacyEnum> |
lookupValueWorkerSafe(LegacyEnum.EnumControlRecord<E> ecr,
long value)
Return the enum instance of the given type which is associated with the provided value.
|
private static void |
mismatchedInput(java.lang.String meth)
Generate an error 12905 (normally a compile error) to indicate that the method inputs were invalid.
|
protected static <E extends LegacyEnum> |
nameHelper(LegacyEnum.EnumControlRecord<E> ecr,
java.util.function.BiFunction<LegacyEnum.EnumControlRecord<E>,java.lang.String,E> hlp,
java.lang.String name)
Return the enum instance of the given type which is associated with the provided name.
|
static object<? extends FlagsEnum> |
not(object<? extends FlagsEnum> flag)
Invert the bits of this enum and return the result as a new enum instance.
|
private static <T extends FlagsEnum> |
operator(object<T> op1,
object<T> op2,
FlagsEnum.BitwiseOperation bits)
Process the given binary bitwise operation with the given operands.
|
static object<? extends FlagsEnum> |
or(object<? extends FlagsEnum> op1,
object<? extends FlagsEnum> op2)
Create a new enum instance that has all bits turned ON which are ON in both operands and return the
resulting enum.
|
protected static <T extends LegacyEnum> |
registerEnum(java.lang.Class<T> cls,
java.util.function.BiFunction<java.lang.String,java.lang.Long,T> create,
java.lang.String legacyName)
Register this enum.
|
<T extends FlagsEnum> |
setFlag(object<T> flag)
Create a new enum instance that has all bits turned ON which are ON in both
this and
flag and return the resulting enum. |
<T extends FlagsEnum> |
toggleFlag(object<T> flag)
Create a new enum instance that has all bits turned ON which are DIFFERENT states in both
this
and flag and return the resulting enum. |
character |
toLegacyString()
Get the string representation for this instance.
|
private static void |
unknownBitwiseOperation()
Generate an error 18210 (normally a compile error) to indicate that the operator inputs were invalid.
|
<T extends FlagsEnum> |
unsetFlag(object<T> flag)
Create a new enum instance which is a copy of the
this but where all bits are turned OFF which
are ON in flag and return the resulting enum. |
static object<? extends FlagsEnum> |
xor(object<? extends FlagsEnum> op1,
object<? extends FlagsEnum> op2)
Create a new enum instance that has all bits turned ON which are DIFFERENT states in both operands
return the resulting enum.
|
_getValue, compareTo, compareTo, compareWorker, createEnum, createEnum, createEnum, createWorker, dumpEnum, dumpEnums, equals, failEnumInstantiation, findClass, findClass, generateFailedToFindEnumType, generateInvalidValue, generateInvalidValue, generateNotFoundValue, getEnum, getEnum, getEnumName, getEnumNames, getEnumsDefineOrder, getEnumsDefineOrder, getEnumsValueSort, getEnumValue, getEnumValues, getExisting, getNextSibling, getPrevSibling, getValue, hashCode, isTracked, legacyEquals, lookupWorker, lookupWorker, maximalBitfield, registerEnum, toObject, toObject
__lang_BaseObject_constructor__, __lang_BaseObject_execute__, assertNotNull, assertNotNull, clone, getLegacyClass
private static final java.lang.String ISSET_UNKNOWN
private static final java.lang.String ISSET_ZERO
private static final java.lang.String MISMATCHED_INPUT
private static final int HIGH_NEGATIVE_BOUNDARY
private boolean multibit
private boolean aliased
private boolean predefined
protected FlagsEnum(java.lang.String name, long value)
name
- The case-preserved legacy name for the enum.value
- The 64-bit enum value.public static object<? extends FlagsEnum> or(object<? extends FlagsEnum> op1, object<? extends FlagsEnum> op2)
SetFlag
method with only a minor difference in the unknown value handling.op1
- The input enum as the left operand.op2
- The input enum as the right operand.ErrorConditionException
- If an operand is unknown value or the operand classes don't match.public static object<? extends FlagsEnum> xor(object<? extends FlagsEnum> op1, object<? extends FlagsEnum> op2)
ToggleFlag
method with only a minor difference in the unknown value handling.op1
- The input enum as the left operand.op2
- The input enum as the right operand.ErrorConditionException
- If an operand is unknown value or the operand classes don't match.public static object<? extends FlagsEnum> and(object<? extends FlagsEnum> op1, object<? extends FlagsEnum> op2)
op1
- The input enum as the left operand.op2
- The input enum as the right operand.ErrorConditionException
- If an operand is unknown value or the operand classes don't match.public static object<? extends FlagsEnum> not(object<? extends FlagsEnum> flag)
((INVERT enum_member) AND maximal_bitfield)
where INVERT is traditional
bitwise NOT (full inversion of bit state or one's complement), AND is traditional "bitwise AND" and
maximal_bitfield is the value created by bitwise OR'ing all pre-defined enums of this type. This
means that any bits which are not set in one of the predefined enums will not be set in the result.flag
- The input enum.ErrorConditionException
- If an operand is unknown value.public character toLegacyString()
Although the original method name is toString()
, this version returns a
character
type which would conflict with the java.lang.Object.toString()
version. For this reason, the name is mapped differently during conversion.
toLegacyString
in interface _BaseObject_
toLegacyString
in class LegacyEnum
public logical isFlagSet(object<? extends FlagsEnum> that)
true
.that
- The input enum with the bits to check for.true
if ALL bits which are ON in that
are also ON in the
current enum.ErrorConditionException
- If that
is unknown value or has a value of zero.public <T extends FlagsEnum> object<T> setFlag(object<T> flag)
this
and
flag
and return the resulting enum. This is the equivalent of the bitwise OR operator with
only a minor difference in the unknown value handling.T
- The enum type.flag
- The input enum.ErrorConditionException
- If an operand is unknown value or the operand classes don't match.public <T extends FlagsEnum> object<T> toggleFlag(object<T> flag)
this
and flag
and return the resulting enum. This is the equivalent of the bitwise XOR operator
with only a minor difference in the unknown value handling.T
- The enum type.flag
- The input enum.ErrorConditionException
- If an operand is unknown value or the operand classes don't match.public <T extends FlagsEnum> object<T> unsetFlag(object<T> flag)
this
but where all bits are turned OFF which
are ON in flag
and return the resulting enum. This is the equivalent of the operation
op1 AND (NOT op2)
.T
- The enum type.flag
- The input enum.ErrorConditionException
- If an operand is unknown value or the operand classes don't match.protected static <T extends LegacyEnum> void registerEnum(java.lang.Class<T> cls, java.util.function.BiFunction<java.lang.String,java.lang.Long,T> create, java.lang.String legacyName)
T
- The enum type.cls
- The enum class.create
- Lambda for creation of new instances.legacyName
- The legacy, fully qualified, name.protected static <E extends LegacyEnum> E lookupNameWorker(LegacyEnum.EnumControlRecord<E> ecr, java.lang.String name)
E
- The enum type.ecr
- The enum control record for the enum to be processed. Must not be null
.name
- The name of a single enum OR a comma-separated list of enums to return. If there
is just one name then this will process an exact match only. For a comma-separated
list of enum names, all results will be bitwise OR'd together. Must not be
null
.protected static <E extends LegacyEnum> E lookupNameWorkerSafe(LegacyEnum.EnumControlRecord<E> ecr, java.lang.String name, boolean trim)
E
- The enum type.ecr
- The enum control record for the enum to be processed. Must not be null
.name
- The name of a single enum OR a comma-separated list of enums to return. If there
is just one name then this will process an exact match only. For a comma-separated
list of enum names, all results will be bitwise OR'd together. Must not be
null
.trim
- Ignored because for flags enums trimming always occurs.protected static <E extends LegacyEnum> E lookupValueWorker(LegacyEnum.EnumControlRecord<E> ecr, long value)
This method also implements a 4GL quirk which excludes some negative values from being matched in bitset mode.
E
- The enum type.ecr
- The enum control record for the enum to process. Must not be null
.value
- The value of the enum to return.protected static <E extends LegacyEnum> E lookupValueWorkerSafe(LegacyEnum.EnumControlRecord<E> ecr, long value)
This is a very different algorithm from lookupValueWorker
which can generate an enum that
has bits which don't match any existing enum (thus yielding a empty string for the name).
E
- The enum type.ecr
- The enum control record for the enum to process. Must not be null
.value
- The value of the enum to return.null
if there is no match.protected static <E extends LegacyEnum> E nameHelper(LegacyEnum.EnumControlRecord<E> ecr, java.util.function.BiFunction<LegacyEnum.EnumControlRecord<E>,java.lang.String,E> hlp, java.lang.String name)
E
- The enum type.ecr
- The enum control record for the enum to be processed. Must not be null
.hlp
- The routine for per-name lookups.name
- The name of a single enum OR a comma-separated list of enums to return. If there
is just one name then this will process an exact match only. For a comma-separated
list of enum names, all results will be bitwise OR'd together. Must not be
null
.private java.lang.String dump()
private static <E extends LegacyEnum> E lookupNameSafeAdapter(LegacyEnum.EnumControlRecord<E> ecr, java.lang.String name)
E
- The enum type.ecr
- The enum control record for the enum to be processed. Must not be null
.name
- The name of a single enum OR a comma-separated list of enums to return. If there
is just one name then this will process an exact match only. For a comma-separated
list of enum names, all results will be bitwise OR'd together. Must not be
null
.private static <E extends LegacyEnum> void initialize(LegacyEnum.EnumControlRecord<E> ecr, E created, E pattern)
ecr
- The control record.created
- Newly created enum needing initialization.pattern
- Enum from which some state must be patterned. This only occurs when creating from an alias.private static boolean isMultibit(long value)
value
- The bitfield to process.true
if more than one bit is set.private static int compareValues(LegacyEnum e1, LegacyEnum e2)
e1
- First enum.e2
- Second enum.private static <T extends FlagsEnum> object<T> operator(object<T> op1, object<T> op2, FlagsEnum.BitwiseOperation bits)
T
- The enum type.op1
- The first operand. It MUST be the same exact enum class as the current instance.op2
- The second operand. It MUST be the same exact enum class as the current instance.bits
- The bitwise operation to perform.ErrorConditionException
- If an operand is unknown value or the operand classes don't match.private <T extends FlagsEnum> object<T> bitwiseWorker(object<T> op2, FlagsEnum.BitwiseOperation bits, java.lang.String meth)
this
) as the first
operand and the op2
as the second operand. The resulting value will be returned as an
enum instance. If the resulting value is an exact match to one of the operands or to one of the
predefined enums, that enum will be returned. Otherwise the result will be dynamically created
as a new multibit enum.T
- The enum type.op2
- The second operand. It MUST be the same exact enum class as the current instance.bits
- The bitwise operation to perform.meth
- Method name for error messages or null
if this call is for a bitwise operator.ErrorConditionException
- If op2
is unknown value.private static FlagsEnum getExistingOrCreate(java.lang.Class<FlagsEnum> cls, long value)
cls
- The enum class to process.value
- The value to lookup and/or use in any create.private static void mismatchedInput(java.lang.String meth)
meth
- The method name being processed.ErrorConditionException
- Always throws this.private static void unknownBitwiseOperation()
ErrorConditionException
- Always throws this.private static void incompatibleDataTypes()
ErrorConditionException
- Always throws this.