Package com.helger.commons.lang
Class EnumHelper
- java.lang.Object
-
- com.helger.commons.lang.EnumHelper
-
@Immutable public final class EnumHelper extends Object
Some enum utility methods.- Author:
- Philip Helger
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static EChangeclearCache()static <ENUMTYPE extends Enum<ENUMTYPE>>
ENUMTYPEfindFirst(Class<ENUMTYPE> aClass, Predicate<? super ENUMTYPE> aFilter)static <ENUMTYPE extends Enum<ENUMTYPE>>
ENUMTYPEfindFirst(Class<ENUMTYPE> aClass, Predicate<? super ENUMTYPE> aFilter, ENUMTYPE eDefault)static <ENUMTYPE extends Enum<ENUMTYPE>>
ICommonsList<ENUMTYPE>getAll(Class<ENUMTYPE> aClass, Predicate<? super ENUMTYPE> aFilter)static StringgetEnumID(Enum<?> aEnum)Get the unique name of the passed enum entry.static <ENUMTYPE extends Enum<ENUMTYPE> & IHasID<String>>
ENUMTYPEgetFromIDCaseInsensitiveOrDefault(Class<ENUMTYPE> aClass, String sID, ENUMTYPE eDefault)Get the enum value with the passed string ID case insensitivestatic <ENUMTYPE extends Enum<ENUMTYPE> & IHasID<String>>
ENUMTYPEgetFromIDCaseInsensitiveOrNull(Class<ENUMTYPE> aClass, String sID)Get the enum value with the passed string ID case insensitivestatic <ENUMTYPE extends Enum<ENUMTYPE> & IHasID<String>>
ENUMTYPEgetFromIDCaseInsensitiveOrThrow(Class<ENUMTYPE> aClass, String sID)Get the enum value with the passed string ID (case insensitive).static <ENUMTYPE extends Enum<ENUMTYPE> & IHasIntID>
ENUMTYPEgetFromIDOrDefault(Class<ENUMTYPE> aClass, int nID, ENUMTYPE eDefault)Get the enum value with the passed IDstatic <KEYTYPE,ENUMTYPE extends Enum<ENUMTYPE> & IHasID<KEYTYPE>>
ENUMTYPEgetFromIDOrDefault(Class<ENUMTYPE> aClass, KEYTYPE aID, ENUMTYPE eDefault)Get the enum value with the passed IDstatic <ENUMTYPE extends Enum<ENUMTYPE> & IHasIntID>
ENUMTYPEgetFromIDOrNull(Class<ENUMTYPE> aClass, int nID)Get the enum value with the passed IDstatic <KEYTYPE,ENUMTYPE extends Enum<ENUMTYPE> & IHasID<KEYTYPE>>
ENUMTYPEgetFromIDOrNull(Class<ENUMTYPE> aClass, KEYTYPE aID)Get the enum value with the passed IDstatic <ENUMTYPE extends Enum<ENUMTYPE> & IHasIntID>
ENUMTYPEgetFromIDOrThrow(Class<ENUMTYPE> aClass, int nID)Get the enum value with the passed ID.static <KEYTYPE,ENUMTYPE extends Enum<ENUMTYPE> & IHasID<KEYTYPE>>
ENUMTYPEgetFromIDOrThrow(Class<ENUMTYPE> aClass, KEYTYPE aID)Get the enum value with the passed ID.static <ENUMTYPE extends Enum<ENUMTYPE> & IHasName>
ENUMTYPEgetFromNameCaseInsensitiveOrDefault(Class<ENUMTYPE> aClass, String sName, ENUMTYPE eDefault)Get the enum value with the passed name case insensitivestatic <ENUMTYPE extends Enum<ENUMTYPE> & IHasName>
ENUMTYPEgetFromNameCaseInsensitiveOrNull(Class<ENUMTYPE> aClass, String sName)Get the enum value with the passed name case insensitivestatic <ENUMTYPE extends Enum<ENUMTYPE> & IHasName>
ENUMTYPEgetFromNameCaseInsensitiveOrThrow(Class<ENUMTYPE> aClass, String sName)Get the enum value with the passed name (case insensitive).static <ENUMTYPE extends Enum<ENUMTYPE> & IHasName>
ENUMTYPEgetFromNameOrDefault(Class<ENUMTYPE> aClass, String sName, ENUMTYPE eDefault)Get the enum value with the passed namestatic <ENUMTYPE extends Enum<ENUMTYPE> & IHasName>
ENUMTYPEgetFromNameOrNull(Class<ENUMTYPE> aClass, String sName)Get the enum value with the passed namestatic <ENUMTYPE extends Enum<ENUMTYPE> & IHasName>
ENUMTYPEgetFromNameOrThrow(Class<ENUMTYPE> aClass, String sName)Get the enum value with the passed name.
-
-
-
Method Detail
-
findFirst
@Nullable public static <ENUMTYPE extends Enum<ENUMTYPE>> ENUMTYPE findFirst(@Nonnull Class<ENUMTYPE> aClass, @Nullable Predicate<? super ENUMTYPE> aFilter)
-
findFirst
@Nullable public static <ENUMTYPE extends Enum<ENUMTYPE>> ENUMTYPE findFirst(@Nonnull Class<ENUMTYPE> aClass, @Nullable Predicate<? super ENUMTYPE> aFilter, @Nullable ENUMTYPE eDefault)
-
getAll
@Nonnull @ReturnsMutableCopy public static <ENUMTYPE extends Enum<ENUMTYPE>> ICommonsList<ENUMTYPE> getAll(@Nonnull Class<ENUMTYPE> aClass, @Nullable Predicate<? super ENUMTYPE> aFilter)
-
getFromIDOrNull
@Nullable public static <KEYTYPE,ENUMTYPE extends Enum<ENUMTYPE> & IHasID<KEYTYPE>> ENUMTYPE getFromIDOrNull(@Nonnull Class<ENUMTYPE> aClass, @Nullable KEYTYPE aID)
Get the enum value with the passed ID- Type Parameters:
KEYTYPE- The ID typeENUMTYPE- The enum type- Parameters:
aClass- The enum classaID- The ID to search- Returns:
nullif no enum item with the given ID is present.
-
getFromIDOrDefault
@Nullable public static <KEYTYPE,ENUMTYPE extends Enum<ENUMTYPE> & IHasID<KEYTYPE>> ENUMTYPE getFromIDOrDefault(@Nonnull Class<ENUMTYPE> aClass, @Nullable KEYTYPE aID, @Nullable ENUMTYPE eDefault)
Get the enum value with the passed ID- Type Parameters:
KEYTYPE- The ID typeENUMTYPE- The enum type- Parameters:
aClass- The enum classaID- The ID to searcheDefault- The default value to be returned, if the ID was not found.- Returns:
- The default parameter if no enum item with the given ID is present.
-
getFromIDOrThrow
@Nonnull public static <KEYTYPE,ENUMTYPE extends Enum<ENUMTYPE> & IHasID<KEYTYPE>> ENUMTYPE getFromIDOrThrow(@Nonnull Class<ENUMTYPE> aClass, @Nullable KEYTYPE aID)
Get the enum value with the passed ID. If no such ID is present, anIllegalArgumentExceptionis thrown.- Type Parameters:
KEYTYPE- The ID typeENUMTYPE- The enum type- Parameters:
aClass- The enum classaID- The ID to search- Returns:
- The enum item with the given ID. Never
null. - Throws:
IllegalArgumentException- if no enum item with the given ID is present
-
getFromIDCaseInsensitiveOrNull
@Nullable public static <ENUMTYPE extends Enum<ENUMTYPE> & IHasID<String>> ENUMTYPE getFromIDCaseInsensitiveOrNull(@Nonnull Class<ENUMTYPE> aClass, @Nullable String sID)
Get the enum value with the passed string ID case insensitive- Type Parameters:
ENUMTYPE- The enum type- Parameters:
aClass- The enum classsID- The ID to search- Returns:
nullif no enum item with the given ID is present.
-
getFromIDCaseInsensitiveOrDefault
@Nullable public static <ENUMTYPE extends Enum<ENUMTYPE> & IHasID<String>> ENUMTYPE getFromIDCaseInsensitiveOrDefault(@Nonnull Class<ENUMTYPE> aClass, @Nullable String sID, @Nullable ENUMTYPE eDefault)
Get the enum value with the passed string ID case insensitive- Type Parameters:
ENUMTYPE- The enum type- Parameters:
aClass- The enum classsID- The ID to searcheDefault- The default value to be returned, if the ID was not found.- Returns:
- The default parameter if no enum item with the given ID is present.
-
getFromIDCaseInsensitiveOrThrow
@Nonnull public static <ENUMTYPE extends Enum<ENUMTYPE> & IHasID<String>> ENUMTYPE getFromIDCaseInsensitiveOrThrow(@Nonnull Class<ENUMTYPE> aClass, @Nullable String sID)
Get the enum value with the passed string ID (case insensitive). If no such ID is present, anIllegalArgumentExceptionis thrown.- Type Parameters:
ENUMTYPE- The enum type- Parameters:
aClass- The enum classsID- The ID to search- Returns:
- The enum item with the given ID. Never
null. - Throws:
IllegalArgumentException- if no enum item with the given ID is present
-
getFromIDOrNull
@Nullable public static <ENUMTYPE extends Enum<ENUMTYPE> & IHasIntID> ENUMTYPE getFromIDOrNull(@Nonnull Class<ENUMTYPE> aClass, int nID)
Get the enum value with the passed ID- Type Parameters:
ENUMTYPE- The enum type- Parameters:
aClass- The enum classnID- The ID to search- Returns:
nullif no enum item with the given ID is present.
-
getFromIDOrDefault
@Nullable public static <ENUMTYPE extends Enum<ENUMTYPE> & IHasIntID> ENUMTYPE getFromIDOrDefault(@Nonnull Class<ENUMTYPE> aClass, int nID, @Nullable ENUMTYPE eDefault)
Get the enum value with the passed ID- Type Parameters:
ENUMTYPE- The enum type- Parameters:
aClass- The enum classnID- The ID to searcheDefault- The default value to be returned, if the ID was not found.- Returns:
- The default parameter if no enum item with the given ID is present.
-
getFromIDOrThrow
@Nonnull public static <ENUMTYPE extends Enum<ENUMTYPE> & IHasIntID> ENUMTYPE getFromIDOrThrow(@Nonnull Class<ENUMTYPE> aClass, int nID)
Get the enum value with the passed ID. If no such ID is present, anIllegalArgumentExceptionis thrown.- Type Parameters:
ENUMTYPE- The enum type- Parameters:
aClass- The enum classnID- The ID to search- Returns:
- The enum item with the given ID. Never
null. - Throws:
IllegalArgumentException- if no enum item with the given ID is present
-
getFromNameOrNull
@Nullable public static <ENUMTYPE extends Enum<ENUMTYPE> & IHasName> ENUMTYPE getFromNameOrNull(@Nonnull Class<ENUMTYPE> aClass, @Nullable String sName)
Get the enum value with the passed name- Type Parameters:
ENUMTYPE- The enum type- Parameters:
aClass- The enum classsName- The name to search- Returns:
nullif no enum item with the given name is present.
-
getFromNameOrDefault
@Nullable public static <ENUMTYPE extends Enum<ENUMTYPE> & IHasName> ENUMTYPE getFromNameOrDefault(@Nonnull Class<ENUMTYPE> aClass, @Nullable String sName, @Nullable ENUMTYPE eDefault)
Get the enum value with the passed name- Type Parameters:
ENUMTYPE- The enum type- Parameters:
aClass- The enum classsName- The name to searcheDefault- The default value to be returned, if the name was not found.- Returns:
- The default parameter if no enum item with the given name is present.
-
getFromNameOrThrow
@Nonnull public static <ENUMTYPE extends Enum<ENUMTYPE> & IHasName> ENUMTYPE getFromNameOrThrow(@Nonnull Class<ENUMTYPE> aClass, @Nullable String sName)
Get the enum value with the passed name. If no such name is present, anIllegalArgumentExceptionis thrown.- Type Parameters:
ENUMTYPE- The enum type- Parameters:
aClass- The enum classsName- The name to search- Returns:
- The enum item with the given name. Never
null. - Throws:
IllegalArgumentException- if no enum item with the given name is present
-
getFromNameCaseInsensitiveOrNull
@Nullable public static <ENUMTYPE extends Enum<ENUMTYPE> & IHasName> ENUMTYPE getFromNameCaseInsensitiveOrNull(@Nonnull Class<ENUMTYPE> aClass, @Nullable String sName)
Get the enum value with the passed name case insensitive- Type Parameters:
ENUMTYPE- The enum type- Parameters:
aClass- The enum classsName- The name to search- Returns:
nullif no enum item with the given ID is present.
-
getFromNameCaseInsensitiveOrDefault
@Nullable public static <ENUMTYPE extends Enum<ENUMTYPE> & IHasName> ENUMTYPE getFromNameCaseInsensitiveOrDefault(@Nonnull Class<ENUMTYPE> aClass, @Nullable String sName, @Nullable ENUMTYPE eDefault)
Get the enum value with the passed name case insensitive- Type Parameters:
ENUMTYPE- The enum type- Parameters:
aClass- The enum classsName- The name to searcheDefault- The default value to be returned, if the name was not found.- Returns:
- The default parameter if no enum item with the given name is present.
-
getFromNameCaseInsensitiveOrThrow
@Nonnull public static <ENUMTYPE extends Enum<ENUMTYPE> & IHasName> ENUMTYPE getFromNameCaseInsensitiveOrThrow(@Nonnull Class<ENUMTYPE> aClass, @Nullable String sName)
Get the enum value with the passed name (case insensitive). If no such name is present, anIllegalArgumentExceptionis thrown.- Type Parameters:
ENUMTYPE- The enum type- Parameters:
aClass- The enum classsName- The name to search- Returns:
- The enum item with the given name. Never
null. - Throws:
IllegalArgumentException- if no enum item with the given name is present
-
getEnumID
@Nonnull public static String getEnumID(@Nonnull Enum<?> aEnum)
Get the unique name of the passed enum entry.- Parameters:
aEnum- The enum to use. May not benull.- Returns:
- The unique ID as a combination of the class name and the enum entry
name. Never
null.
-
-