Class EnumUtils

java.lang.Object
com.jalios.util.EnumUtils

public final class EnumUtils extends Object
Utils Class to handle enumeration values ​​to int-based "bit flags".
Author:
Nicolas Dos Santos
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isFlagSet(int value, Enum<?> e)
    Checks whether the int-based "bit flags" representation of the given enumeration value is present in the given value.
    static int
    toAllFlagValue(Class<? extends Enum<?>> enumClass)
    Returns int-based "bit flags" representing the values of the given Enum class.
    If the given Enum class is null, return 0.
    static <E extends Enum<E>>
    E
    toEnum(Class<E> enumClass, String enumName)
    Gets the enum for the class, returning null if not found.
    static int
    Returns int-based "bit flags" representing the value of the given enumeration.
    If the given enumeration is null, return 0.
    static int
    toFlagValue(Enum<?>... enumArray)
    Returns int-based "bit flags" representing the values of the given enumerations.
    If the given enumerations is null, return 0.
    static int
    toFlagValue(Collection<? extends Enum<?>> enumList)
    Returns int-based "bit flags" representing the values of the given list of enumerations.
    If the given list of enumerations is null, return 0.
    static <T extends Enum<T>>
    String[]
    toStringArray(Class<T> enumClass)
    Converts an Enum to a String array.

    Methods inherited from class java.lang.Object

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

    • toFlagValue

      public static int toFlagValue(Enum<?> e)
      Returns int-based "bit flags" representing the value of the given enumeration.
      If the given enumeration is null, return 0.
      Parameters:
      e - Enumeration value to handle
      Returns:
      int-based "bit flags", or 0 if e is null
    • toFlagValue

      public static int toFlagValue(Enum<?>... enumArray)
      Returns int-based "bit flags" representing the values of the given enumerations.
      If the given enumerations is null, return 0.
      Parameters:
      enumArray - Enumeration values to handle
      Returns:
      int-based "bit flags", or 0 if enumArray is null
    • toFlagValue

      public static int toFlagValue(Collection<? extends Enum<?>> enumList)
      Returns int-based "bit flags" representing the values of the given list of enumerations.
      If the given list of enumerations is null, return 0.
      Parameters:
      enumList - Enumeration values to handle
      Returns:
      int-based "bit flags", or 0 if enumList is null
    • toAllFlagValue

      public static int toAllFlagValue(Class<? extends Enum<?>> enumClass)
      Returns int-based "bit flags" representing the values of the given Enum class.
      If the given Enum class is null, return 0.
      Parameters:
      enumClass - Enum class to handle
      Returns:
      int-based "bit flags", or 0 if enumClass is null
    • isFlagSet

      public static boolean isFlagSet(int value, Enum<?> e)
      Checks whether the int-based "bit flags" representation of the given enumeration value is present in the given value.
      Parameters:
      value - value to check
      e - Enumeration value
      Returns:
      true the Enumeration value is flagged
    • toStringArray

      public static <T extends Enum<T>> String[] toStringArray(Class<T> enumClass)
      Converts an Enum to a String array.
      Parameters:
      enumClass - Class representing the Enum
      Returns:
      String[]
    • toEnum

      public static <E extends Enum<E>> E toEnum(Class<E> enumClass, String enumName)

      Gets the enum for the class, returning null if not found.

      This method differs from Enum.valueOf(java.lang.Class<T>, java.lang.String) in that it does not throw an exception for an invalid enum name.

      Type Parameters:
      E - the type of the enumeration
      Parameters:
      enumClass - the class of the enum to query, not null
      enumName - the enum name, null returns null
      Returns:
      the enum, null if not found