Package komposten.leapjna.leapc.enums
Class Enums
java.lang.Object
komposten.leapjna.leapc.enums.Enums
Utility functions for converting from primitives to enum constants and back.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
An interface for enums with byte values.static interface
An interface for enums with integer values.static interface
Enums.IntFlagEnum<T extends Enums.IntFlagEnum<?>>
An interface for enums with integer values that are meant to be used as flags/bitmasks. -
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends Enums.IntFlagEnum<E>>
intcreateMask
(E... flags) Converts a set of flag enum constants into a bitmask using bitwise or.static <E extends Enums.ByteEnum>
Eparse
(byte value, E defaultValue) Attempts to find an enum constant in the typeE
matching the provided byte value.static <E extends Enums.IntEnum>
Eparse
(int value, E defaultValue) Attempts to find an enum constant in the typeE
matching the provided integer value.static <E extends Enums.IntFlagEnum<E>>
E[]Parses the provided bitmask into an array of corresponding enum constants.
-
Method Details
-
parse
Attempts to find an enum constant in the typeE
matching the provided integer value.- Type Parameters:
E
- The enum type to convert the integer value to.- Parameters:
value
- The integer value of an enum constant.defaultValue
- The default return value if no enum constant in the specified type matches the provided integer value.- Returns:
- An enum constant of type
E
matchingvalue
, ordefaultValue
if no match is found.
-
parse
Attempts to find an enum constant in the typeE
matching the provided byte value.- Type Parameters:
E
- The enum type to convert the byte value to.- Parameters:
value
- The byte value of an enum constant.defaultValue
- The default return value if no enum constant in the specified type matches the provided byte value.- Returns:
- An enum constant of type
E
matchingvalue
, ordefaultValue
if no match is found.
-
parseMask
Parses the provided bitmask into an array of corresponding enum constants.- Type Parameters:
E
- The flag enum type whose constants to use.- Parameters:
mask
- A bitmask.enumClass
- The flag enum class whose constants to use.- Returns:
- An array of enum constants corresponding to the flags set in the
mask, or the enum class'
empty constant
if there are no matching enum constants or the mask is empty.
-
createMask
Converts a set of flag enum constants into a bitmask using bitwise or.- Type Parameters:
E
- The flag enum type the constants belong to.- Parameters:
flags
- The flag constants to merge into a bitmask.- Returns:
- A bitmask corresponding to the provided flags.
-