Package no.digipost
Class DiggEnums
- java.lang.Object
-
- no.digipost.DiggEnums
-
public final class DiggEnums extends Object
Utilities for working with Javaenums.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E extends Enum<E>>
Stream<E>fromCommaSeparated(String enumsString, Function<String,String> toEnumName, Class<E> enumType)Resolveenumconstants from a string of comma separated identifiers.static <E extends Enum<E>>
Stream<E>fromCommaSeparatedNames(String enumNames, Class<E> enumType)Resolveenumconstants from a string of comma separated names.static <E extends Enum<E>>
Stream<E>fromEnumsString(String enumsString, String delimRegex, Function<String,E> convertToEnum)Resolveenumconstants from a string containing identifiers separated by a delimiter.static <E extends Enum<E>>
Stream<E>fromEnumsString(String enumsString, String delimRegex, Predicate<String> included, Function<String,E> convertToEnum)Resolveenumconstants from a string containing identifiers separated by a delimiter.static <E extends Enum<E>>
StringtoCommaSeparatedNames(E... enums)Join severalenumconstants to a comma separated string of theirnames.static <E extends Enum<E>>
StringtoCommaSeparatedNames(Collection<E> enums)Join severalenumconstants to a comma separated string of theirnames.static <E extends Enum<E>>
StringtoNames(String delim, E... enums)static <E extends Enum<E>>
StringtoNames(String delim, Collection<E> enums)static <E extends Enum<E>>
StringtoStringOf(Function<? super E,String> enumAsString, String delim, E... enums)Join severalenumconstants to a string where each constant is converted to a string, and separated by the givendelimiter.static <E extends Enum<E>>
StringtoStringOf(Function<? super E,String> enumAsString, String delim, Collection<E> enums)Join severalenumconstants to a string where each constant is converted to a string, and separated by the givendelimiter.static <E extends Enum<E>>
StringtoStringOf(Function<? super E,String> enumAsString, Collector<? super String,?,String> joiner, E... enums)Join severalenumconstants to a string where each constant is converted to a string, and joined to one string using a givenCollector.static <E extends Enum<E>>
StringtoStringOf(Function<? super E,String> enumAsString, Collector<? super String,?,String> joiner, Collection<E> enums)Join severalenumconstants to a string where each constant is converted to a string, and joined to one string using a givenCollector.
-
-
-
Method Detail
-
fromCommaSeparatedNames
public static <E extends Enum<E>> Stream<E> fromCommaSeparatedNames(String enumNames, Class<E> enumType)
Resolveenumconstants from a string of comma separated names. The names must be exactly equal to the constant names of the givenenumtype, but may include any whitespace before and/or after each comma.- Parameters:
enumNames- the string containing the comma separatedenumnames.enumType- the type of theenum.- Returns:
- a stream of the resolved
enumconstants.
-
fromCommaSeparated
public static <E extends Enum<E>> Stream<E> fromCommaSeparated(String enumsString, Function<String,String> toEnumName, Class<E> enumType)
Resolveenumconstants from a string of comma separated identifiers. The string may include any whitespace before and/or after each comma. The identifiers must be converted toenumnames using a givenFunction.- Parameters:
enumsString- the string containing the comma separatedenumidentifiers.toEnumName- the function to convert from the identifiers toenumnames.enumType- the type of theenum.- Returns:
- a stream of the resolved
enumconstants.
-
fromEnumsString
public static <E extends Enum<E>> Stream<E> fromEnumsString(String enumsString, String delimRegex, Function<String,E> convertToEnum)
Resolveenumconstants from a string containing identifiers separated by a delimiter. The identifiers must be converted toenumconstants using a givenFunction.- Parameters:
enumsString- the string containing theenumidentifiers.delimRegex- the regular expression which is applied to the {code enumString} to split it into separate identifiers.convertToEnum- the function to convert from the identifiers toenumconstants from the identifiers.- Returns:
- a stream of the resolved
enumconstants.
-
fromEnumsString
public static <E extends Enum<E>> Stream<E> fromEnumsString(String enumsString, String delimRegex, Predicate<String> included, Function<String,E> convertToEnum)
Resolveenumconstants from a string containing identifiers separated by a delimiter. The identifiers must be converted toenumconstants using a givenFunction. In addition, this method offers a filtering mechanism to only include identifiers which satisfy aPredicate.- Parameters:
enumsString- the string containing theenumidentifiers.delimRegex- the regular expression which is applied to the {code enumString} to split it into separate identifiers.included- predicate which is used as a filter on each identifier. Identifiers not satisfying this predicate will not be attempted to resolve as anenumconstant.convertToEnum- the function to convert from the identifiers toenumconstants from the identifiers.- Returns:
- a stream of the resolved
enumconstants.
-
toCommaSeparatedNames
@SafeVarargs public static <E extends Enum<E>> String toCommaSeparatedNames(E... enums)
Join severalenumconstants to a comma separated string of theirnames.- Parameters:
enums- theenums- Returns:
- the comma separated
enumnames.
-
toCommaSeparatedNames
public static <E extends Enum<E>> String toCommaSeparatedNames(Collection<E> enums)
Join severalenumconstants to a comma separated string of theirnames.- Parameters:
enums- theenums- Returns:
- the comma separated
enumnames.
-
toNames
@SafeVarargs public static <E extends Enum<E>> String toNames(String delim, E... enums)
- Parameters:
delim- thedelimiter.enums- theenums.- Returns:
- the
enumnames, separated by thedelimiter.
-
toNames
public static <E extends Enum<E>> String toNames(String delim, Collection<E> enums)
- Parameters:
delim- thedelimiter.enums- theenums.- Returns:
- the
enumnames, separated by thedelimiter.
-
toStringOf
@SafeVarargs public static <E extends Enum<E>> String toStringOf(Function<? super E,String> enumAsString, String delim, E... enums)
Join severalenumconstants to a string where each constant is converted to a string, and separated by the givendelimiter.- Parameters:
enumAsString- the function which converts eachenumconstant to a string.delim- thedelimiter.enums- theenums.- Returns:
- the joined string
-
toStringOf
public static <E extends Enum<E>> String toStringOf(Function<? super E,String> enumAsString, String delim, Collection<E> enums)
Join severalenumconstants to a string where each constant is converted to a string, and separated by the givendelimiter.- Parameters:
enumAsString- the function which converts eachenumconstant to a string.delim- thedelimiter.enums- theenums.- Returns:
- the joined string.
-
toStringOf
@SafeVarargs public static <E extends Enum<E>> String toStringOf(Function<? super E,String> enumAsString, Collector<? super String,?,String> joiner, E... enums)
Join severalenumconstants to a string where each constant is converted to a string, and joined to one string using a givenCollector.- Parameters:
enumAsString- the function which converts eachenumconstant to a string.joiner- theCollectorto join the strings.enums- theenums.- Returns:
- the joined string.
-
toStringOf
public static <E extends Enum<E>> String toStringOf(Function<? super E,String> enumAsString, Collector<? super String,?,String> joiner, Collection<E> enums)
Join severalenumconstants to a string where each constant is converted to a string, and joined to one string using a givenCollector.- Parameters:
enumAsString- the function which converts eachenumconstant to a string.joiner- theCollectorto join the strings.enums- theenums.- Returns:
- the joined string.
-
-