Package no.digipost
Class DiggEnums
java.lang.Object
no.digipost.DiggEnums
Utilities for working with Java
enums.-
Method Summary
Modifier and TypeMethodDescriptionResolveenumconstants from a string of comma separated identifiers.fromCommaSeparatedNames(String enumNames, Class<E> enumType) Resolveenumconstants from a string of comma separated names.fromEnumsString(String enumsString, String delimRegex, Function<String, E> convertToEnum) Resolveenumconstants from a string containing identifiers separated by a delimiter.fromEnumsString(String enumsString, String delimRegex, Predicate<String> included, Function<String, E> convertToEnum) Resolveenumconstants from a string containing identifiers separated by a delimiter.toCommaSeparatedNames(E... enums) Join severalenumconstants to a comma separated string of theirnames.toCommaSeparatedNames(Collection<E> enums) Join severalenumconstants to a comma separated string of theirnames.toNames(String delim, Collection<E> enums) 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.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.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.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.
-
Method Details
-
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
Join severalenumconstants to a comma separated string of theirnames.- Parameters:
enums- theenums- Returns:
- the comma separated
enumnames.
-
toCommaSeparatedNames
Join severalenumconstants to a comma separated string of theirnames.- Parameters:
enums- theenums- Returns:
- the comma separated
enumnames.
-
toNames
- Parameters:
delim- thedelimiter.enums- theenums.- Returns:
- the
enumnames, separated by thedelimiter.
-
toNames
- 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.
-