Package no.digipost

Class DiggEnums

java.lang.Object
no.digipost.DiggEnums

public final class DiggEnums extends Object
Utilities for working with Java enums.
  • Method Details

    • fromCommaSeparatedNames

      public static <E extends Enum<E>> Stream<E> fromCommaSeparatedNames(String enumNames, Class<E> enumType)
      Resolve enum constants from a string of comma separated names. The names must be exactly equal to the constant names of the given enum type, but may include any whitespace before and/or after each comma.
      Parameters:
      enumNames - the string containing the comma separated enum names.
      enumType - the type of the enum.
      Returns:
      a stream of the resolved enum constants.
    • fromCommaSeparated

      public static <E extends Enum<E>> Stream<E> fromCommaSeparated(String enumsString, Function<String,String> toEnumName, Class<E> enumType)
      Resolve enum constants from a string of comma separated identifiers. The string may include any whitespace before and/or after each comma. The identifiers must be converted to enum names using a given Function.
      Parameters:
      enumsString - the string containing the comma separated enum identifiers.
      toEnumName - the function to convert from the identifiers to enum names.
      enumType - the type of the enum.
      Returns:
      a stream of the resolved enum constants.
    • fromEnumsString

      public static <E extends Enum<E>> Stream<E> fromEnumsString(String enumsString, String delimRegex, Function<String,E> convertToEnum)
      Resolve enum constants from a string containing identifiers separated by a delimiter. The identifiers must be converted to enum constants using a given Function.
      Parameters:
      enumsString - the string containing the enum identifiers.
      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 to enum constants from the identifiers.
      Returns:
      a stream of the resolved enum constants.
    • fromEnumsString

      public static <E extends Enum<E>> Stream<E> fromEnumsString(String enumsString, String delimRegex, Predicate<String> included, Function<String,E> convertToEnum)
      Resolve enum constants from a string containing identifiers separated by a delimiter. The identifiers must be converted to enum constants using a given Function. In addition, this method offers a filtering mechanism to only include identifiers which satisfy a Predicate.
      Parameters:
      enumsString - the string containing the enum identifiers.
      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 an enum constant.
      convertToEnum - the function to convert from the identifiers to enum constants from the identifiers.
      Returns:
      a stream of the resolved enum constants.
    • toCommaSeparatedNames

      @SafeVarargs public static <E extends Enum<E>> String toCommaSeparatedNames(E... enums)
      Join several enum constants to a comma separated string of their names.
      Parameters:
      enums - the enums
      Returns:
      the comma separated enum names.
    • toCommaSeparatedNames

      public static <E extends Enum<E>> String toCommaSeparatedNames(Collection<E> enums)
      Join several enum constants to a comma separated string of their names.
      Parameters:
      enums - the enums
      Returns:
      the comma separated enum names.
    • toNames

      @SafeVarargs public static <E extends Enum<E>> String toNames(String delim, E... enums)
      Join several enum constants to a string of their names, separated by the given delimiter.
      Parameters:
      delim - the delimiter.
      enums - the enums.
      Returns:
      the enum names, separated by the delimiter.
    • toNames

      public static <E extends Enum<E>> String toNames(String delim, Collection<E> enums)
      Join several enum constants to a string of their names, separated by the given delimiter.
      Parameters:
      delim - the delimiter.
      enums - the enums.
      Returns:
      the enum names, separated by the delimiter.
    • toStringOf

      @SafeVarargs public static <E extends Enum<E>> String toStringOf(Function<? super E,String> enumAsString, String delim, E... enums)
      Join several enum constants to a string where each constant is converted to a string, and separated by the given delimiter.
      Parameters:
      enumAsString - the function which converts each enum constant to a string.
      delim - the delimiter.
      enums - the enums.
      Returns:
      the joined string
    • toStringOf

      public static <E extends Enum<E>> String toStringOf(Function<? super E,String> enumAsString, String delim, Collection<E> enums)
      Join several enum constants to a string where each constant is converted to a string, and separated by the given delimiter.
      Parameters:
      enumAsString - the function which converts each enum constant to a string.
      delim - the delimiter.
      enums - the enums.
      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 several enum constants to a string where each constant is converted to a string, and joined to one string using a given Collector.
      Parameters:
      enumAsString - the function which converts each enum constant to a string.
      joiner - the Collector to join the strings.
      enums - the enums.
      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 several enum constants to a string where each constant is converted to a string, and joined to one string using a given Collector.
      Parameters:
      enumAsString - the function which converts each enum constant to a string.
      joiner - the Collector to join the strings.
      enums - the enums.
      Returns:
      the joined string.