Class Enums

java.lang.Object
komposten.leapjna.leapc.enums.Enums

public class Enums extends Object
Utility functions for converting from primitives to enum constants and back.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    An interface for enums with byte values.
    static interface 
    An interface for enums with integer values.
    static interface 
    An interface for enums with integer values that are meant to be used as flags/bitmasks.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <E extends Enums.IntFlagEnum<E>>
    int
    createMask(E... flags)
    Converts a set of flag enum constants into a bitmask using bitwise or.
    static <E extends Enums.ByteEnum>
    E
    parse(byte value, E defaultValue)
    Attempts to find an enum constant in the type E matching the provided byte value.
    static <E extends Enums.IntEnum>
    E
    parse(int value, E defaultValue)
    Attempts to find an enum constant in the type E matching the provided integer value.
    static <E extends Enums.IntFlagEnum<E>>
    E[]
    parseMask(int mask, Class<E> enumClass)
    Parses the provided bitmask into an array of corresponding enum constants.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • parse

      public static <E extends Enums.IntEnum> E parse(int value, E defaultValue)
      Attempts to find an enum constant in the type E 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 matching value, or defaultValue if no match is found.
    • parse

      public static <E extends Enums.ByteEnum> E parse(byte value, E defaultValue)
      Attempts to find an enum constant in the type E 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 matching value, or defaultValue if no match is found.
    • parseMask

      public static <E extends Enums.IntFlagEnum<E>> E[] parseMask(int mask, Class<E> enumClass)
      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

      public static <E extends Enums.IntFlagEnum<E>> int createMask(E... flags)
      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.