public final class Enums extends Object
| Modifier and Type | Class and Description | 
|---|---|
| static interface  | Enums.EnumParser<E extends Enum>Single abstract method interface for parsing enum
 constant values from strings. | 
| static interface  | Enums.StringProducer<E extends Enum>Single abstract method interface for converting Enum
 constant values to strings. | 
| Constructor and Description | 
|---|
| Enums() | 
| Modifier and Type | Method and Description | 
|---|---|
| static <E extends Enum>  | createDisplayNameMap(Class<E> enumClass)Convenience method for creating String -> enum map where the String keys
 are produced by calling the displayName() method on each enum constant. | 
| static <E extends Enum>  | createStringKeyMap(Class<E> enumClass,
                  Enums.StringProducer<E> keyProducer)Returns a map of String -> enum constant for all constants
 in the provided enum class. | 
| static <E extends Enum>  | displayNameEnumParser(Class<E> enumClass)Returns an EnumParser that converts String values to enum constants by
 calling valueOfDisplayName() on the enum class. | 
| static <E extends Enum>  | displayNameStringProducer(Class<E> enumClass)Returns a StringProducer that converts enum constants to String values by
 calling displayName() on each enum constant. | 
| static <E extends Enum>  | methodNameEnumParser(Class<E> enumClass,
                    String methodName)Returns an EnumParser that uses reflection to invoke a method
 on an enum class to translate String values to enum constants. | 
| static <E extends Enum>  | methodNameStringProducer(Class<E> enumClass,
                        String methodName)Returns a StringProducer uses reflection to produce Strings from
 enum constant values. | 
| static <E extends Enum>  | parseDisplayNameEnumRequestParameter(javax.faces.context.ExternalContext external,
                                    String paramName,
                                    Class<E> enumClass,
                                    E defaultValue)Convenience for Enums.parseEnumRequestParameter() that uses a display name-based
 EnumParser to parse values. | 
| static <E extends Enum>  | parseEnumRequestParameter(javax.faces.context.ExternalContext external,
                         String paramName,
                         Class<E> enumClass,
                         Enums.EnumParser<E> enumParser,
                         E defaultValue)Parses a request parameter into a collection of enum constant values. | 
| static <E extends Enum>  | parseEnumValues(Collection<String> valuesToParse,
               Class<E> enumClass,
               Enums.EnumParser<E> enumParser,
               E defaultValue)Parses a collection of strings into a corresponding collection
 of enum constant values. | 
| static <E extends Enum>  | patternOf(Class<E> enumClass,
         Enums.StringProducer<E> patternProducer)Returns a string suitable for use in a regular expression
 pattern that matches all values of the specified enum. | 
| static <T extends Enum>  | stringToEnum(Map<String,T> stringToEnumMap,
            String key,
            Class<T> enumClass)Looks up an Enum value in a String -> Enum map and
 throws an IllegalArgumentException if a value
 is not found. | 
public static <E extends Enum> Map<String,E> createStringKeyMap(Class<E> enumClass, Enums.StringProducer<E> keyProducer)
enumClass - the enum class from which the map will be createdkeyProducer - called for each enum constant to produce the string
   key for the map.public static <T extends Enum> T stringToEnum(Map<String,T> stringToEnumMap, String key, Class<T> enumClass)
stringToEnumMap - the map containing String -> enum mappingskey - the string value to look up in the mapenumClass - the target enum classIllegalArgumentException - if no value is found.public static <E extends Enum> String patternOf(Class<E> enumClass, Enums.StringProducer<E> patternProducer)
enumClass - the enum class from which the pattern
   will be derived.patternProducer - called for each enum constant value
   to produce the string representation to use in the pattern.public static <E extends Enum> Collection<E> parseEnumValues(Collection<String> valuesToParse, Class<E> enumClass, Enums.EnumParser<E> enumParser, E defaultValue) throws EnumParseException
valuesToParse - string values to parseenumClass - target enum classdefaultValue - an enum value to include in the parsed collection if
   valueToParse is empty.enumParser - called for each string value to convert to an enum constant.EnumParseException - if the EnumParser fails to parse one of the values.public static <E extends Enum> Collection<E> parseEnumRequestParameter(javax.faces.context.ExternalContext external, String paramName, Class<E> enumClass, Enums.EnumParser<E> enumParser, E defaultValue) throws EnumParseException
external - the ExternalContext that defines the request parameter valuesparamName - the name of the request parameter to parseenumClass - target enum classdefaultValue - an enum value to include in the parsed collection if
   valuesToParse is empty.enumParser - called for each string value to convert to an enum constant.EnumParseException - if the EnumParser fails to parse one of the values.public static <E extends Enum> Map<String,E> createDisplayNameMap(Class<E> enumClass)
public static <E extends Enum> Enums.StringProducer<E> displayNameStringProducer(Class<E> enumClass) throws IllegalArgumentException
enumClass - the class of the enum for which we want to produce strings.  This
   class must provide a public displayName() method.IllegalArgumentException - if the enum class does not provide a publicly
   accessible displayName() method.public static <E extends Enum> Enums.EnumParser<E> displayNameEnumParser(Class<E> enumClass)
enumClass - the target class to which String values are parsed.  This
   class must provide a public static valueOfDisplayName(String) method.IllegalArgumentException - if the enum class does not provide a publicly
   accessible valueOfDisplayName(String) method.public static <E extends Enum> Enums.StringProducer<E> methodNameStringProducer(Class<E> enumClass, String methodName) throws IllegalArgumentException
enumClass - the enum class on which the StringProducer operatesmethodName - the name of the method which the StringProducer invokesIllegalArgumentException - if the method specified by the 
   methodName argument does not exist.public static <E extends Enum> Enums.EnumParser<E> methodNameEnumParser(Class<E> enumClass, String methodName) throws IllegalArgumentException
enumClass - the target enum classmethodName - the name of the method to invokeIllegalArgumentException - if the method specified by the 
   methodName argument does not exist.public static <E extends Enum> Collection<E> parseDisplayNameEnumRequestParameter(javax.faces.context.ExternalContext external, String paramName, Class<E> enumClass, E defaultValue) throws EnumParseException
Copyright © 2001-2017 The Apache Software Foundation. All Rights Reserved.