Package com.helger.commons.lang
Class EnumHelper
java.lang.Object
com.helger.commons.lang.EnumHelper
Some enum utility methods.
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic EChangestatic <ENUMTYPE extends Enum<ENUMTYPE>>
ENUMTYPEstatic <ENUMTYPE extends Enum<ENUMTYPE>>
ENUMTYPEstatic <ENUMTYPE extends Enum<ENUMTYPE>>
ICommonsList<ENUMTYPE> static StringGet the unique name of the passed enum entry.getFromIDCaseInsensitiveOrDefault(Class<ENUMTYPE> aClass, String sID, ENUMTYPE eDefault) Get the enum value with the passed string ID case insensitivegetFromIDCaseInsensitiveOrNull(Class<ENUMTYPE> aClass, String sID) Get the enum value with the passed string ID case insensitivegetFromIDCaseInsensitiveOrThrow(Class<ENUMTYPE> aClass, String sID) Get the enum value with the passed string ID (case insensitive).getFromIDOrDefault(Class<ENUMTYPE> aClass, int nID, ENUMTYPE eDefault) Get the enum value with the passed IDgetFromIDOrDefault(Class<ENUMTYPE> aClass, KEYTYPE aID, ENUMTYPE eDefault) Get the enum value with the passed IDgetFromIDOrNull(Class<ENUMTYPE> aClass, int nID) Get the enum value with the passed IDgetFromIDOrNull(Class<ENUMTYPE> aClass, KEYTYPE aID) Get the enum value with the passed IDgetFromIDOrThrow(Class<ENUMTYPE> aClass, int nID) Get the enum value with the passed ID.getFromIDOrThrow(Class<ENUMTYPE> aClass, KEYTYPE aID) Get the enum value with the passed ID.getFromNameCaseInsensitiveOrDefault(Class<ENUMTYPE> aClass, String sName, ENUMTYPE eDefault) Get the enum value with the passed name case insensitivegetFromNameCaseInsensitiveOrNull(Class<ENUMTYPE> aClass, String sName) Get the enum value with the passed name case insensitivegetFromNameCaseInsensitiveOrThrow(Class<ENUMTYPE> aClass, String sName) Get the enum value with the passed name (case insensitive).getFromNameOrDefault(Class<ENUMTYPE> aClass, String sName, ENUMTYPE eDefault) Get the enum value with the passed namegetFromNameOrNull(Class<ENUMTYPE> aClass, String sName) Get the enum value with the passed namegetFromNameOrThrow(Class<ENUMTYPE> aClass, String sName) Get the enum value with the passed name.
-
Method Details
-
findFirst
-
findFirst
-
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
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.
-
clearCache
-