Package com.jalios.util
Class EnumUtils
- java.lang.Object
-
- com.jalios.util.EnumUtils
-
public final class EnumUtils extends java.lang.ObjectUtils Class to handle enumeration values to int-based "bit flags".- Author:
- Nicolas Dos Santos
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisFlagSet(int value, java.lang.Enum<?> e)Checks whether the int-based "bit flags" representation of the given enumeration value is present in the given value.static inttoAllFlagValue(java.lang.Class<? extends java.lang.Enum<?>> enumClass)Returns int-based "bit flags" representing the values of the given Enum class.
If the given Enum class isnull, return 0.static <E extends java.lang.Enum<E>>
EtoEnum(java.lang.Class<E> enumClass, java.lang.String enumName)Gets the enum for the class, returningnullif not found.static inttoFlagValue(java.lang.Enum<?> e)Returns int-based "bit flags" representing the value of the given enumeration.
If the given enumeration isnull, return 0.static inttoFlagValue(java.lang.Enum<?>... enumArray)Returns int-based "bit flags" representing the values of the given enumerations.
If the given enumerations isnull, return 0.static inttoFlagValue(java.util.Collection<? extends java.lang.Enum<?>> enumList)Returns int-based "bit flags" representing the values of the given list of enumerations.
If the given list of enumerations isnull, return 0.static <T extends java.lang.Enum<T>>
java.lang.String[]toStringArray(java.lang.Class<T> enumClass)Converts an Enum to a String array.
-
-
-
Method Detail
-
toFlagValue
public static int toFlagValue(java.lang.Enum<?> e)
Returns int-based "bit flags" representing the value of the given enumeration.
If the given enumeration isnull, return 0.- Parameters:
e- Enumeration value to handle- Returns:
- int-based "bit flags", or
0ifeisnull
-
toFlagValue
public static int toFlagValue(java.lang.Enum<?>... enumArray)
Returns int-based "bit flags" representing the values of the given enumerations.
If the given enumerations isnull, return 0.- Parameters:
enumArray- Enumeration values to handle- Returns:
- int-based "bit flags", or
0ifenumArrayisnull
-
toFlagValue
public static int toFlagValue(java.util.Collection<? extends java.lang.Enum<?>> enumList)
Returns int-based "bit flags" representing the values of the given list of enumerations.
If the given list of enumerations isnull, return 0.- Parameters:
enumList- Enumeration values to handle- Returns:
- int-based "bit flags", or
0ifenumListisnull
-
toAllFlagValue
public static int toAllFlagValue(java.lang.Class<? extends java.lang.Enum<?>> enumClass)
Returns int-based "bit flags" representing the values of the given Enum class.
If the given Enum class isnull, return 0.- Parameters:
enumClass- Enum class to handle- Returns:
- int-based "bit flags", or
0ifenumClassisnull
-
isFlagSet
public static boolean isFlagSet(int value, java.lang.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 checke- Enumeration value- Returns:
truethe Enumeration value is flagged
-
toStringArray
public static <T extends java.lang.Enum<T>> java.lang.String[] toStringArray(java.lang.Class<T> enumClass)
Converts an Enum to a String array.- Parameters:
enumClass-Classrepresenting the Enum- Returns:
String[]
-
toEnum
public static <E extends java.lang.Enum<E>> E toEnum(java.lang.Class<E> enumClass, java.lang.String enumName)Gets the enum for the class, returning
nullif 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 nullenumName- the enum name, null returns null- Returns:
- the enum, null if not found
-
-