Class CasedString.StringCase

java.lang.Object
io.aiven.commons.util.strings.CasedString.StringCase
Enclosing class:
CasedString

public static class CasedString.StringCase extends Object
An enumeration of supported string cases. These cases tag strings as having a specific format.
  • Field Details

    • CAMEL

      public static final CasedString.StringCase CAMEL
      Camel case tags strings like 'CamelCase' or 'camelCase'. This conversion forces the first character to lower case. If the first character is desired to be upper case use PASCAL case instead.
    • PASCAL

      public static final CasedString.StringCase PASCAL
      Camel case tags strings like 'PascalCase' or 'pascalCase'. This conversion forces the first character to upper case. If the first character is desired to be lower case use CAMEL case instead.
    • SNAKE

      public static final CasedString.StringCase SNAKE
      Snake case tags strings like 'Snake_Case'. This conversion does not change the capitalization of any characters in the string. If specific capitalization is required use String.toUpperCase(), String.toLowerCase(), or the commons-text methods WordUtils.capitalize(String), or WordUtils.uncapitalize(String) as required.
    • KEBAB

      public static final CasedString.StringCase KEBAB
      Kebab case tags strings like 'kebab-case'. This conversion does not change the capitalization of any characters in the string. If specific capitalization is required use String.toUpperCase(), String.toLowerCase(), * or the commons-text methods WordUtils.capitalize(String), or WordUtils.uncapitalize(String) as required.
    • PHRASE

      public static final CasedString.StringCase PHRASE
      Phrase case tags phrases of words like 'phrase case'. This conversion does not change the capitalization of any characters in the string. If specific capitalization is required use String.toUpperCase(), String.toLowerCase(), * or the commons-text methods WordUtils.capitalize(String), or WordUtils.uncapitalize(String) as required.
    • DOT

      public static final CasedString.StringCase DOT
      Dot case tags phrases of words like 'phrase.case'. This conversion does not change the capitalization of any characters in the string. If specific capitalization is required use String.toUpperCase(), String.toLowerCase(), * or the commons-text methods WordUtils.capitalize(String), or WordUtils.uncapitalize(String) as required.
    • SLASH

      public static final CasedString.StringCase SLASH
      Slash case tags phrases of words like 'phrase.case'. This conversion does not change the capitalization of any characters in the string. If specific capitalization is required use String.toUpperCase(), String.toLowerCase(), * or the commons-text methods WordUtils.capitalize(String), or WordUtils.uncapitalize(String) as required.
  • Constructor Details

    • StringCase

      public StringCase(String name, Predicate<Character> splitter, boolean preserveSplit, Function<String[],String> joiner)
      Defines a String Case.
      Parameters:
      name - The name of the string case
      splitter - The predicate that determines when a new word in the cased string begins.
      preserveSplit - if true the character that the splitter detected is preserved as the first character of the new word.
      joiner - The function to merge a list of strings into the cased String.
    • StringCase

      public StringCase(String name, char delimiter)
      Create a simple string case for the delimiter. Items will be split on the delimiter. Arrays of strings will be joined by the delimiter, null strings will be discarded.
      Parameters:
      name - the name of the case.
      delimiter - the delimiter
    • StringCase

      public StringCase(String name, Predicate<Character> splitter, boolean preserveSplit, Function<String[],String> joiner, Function<String,String> postProcess)
      Defines a String Case.
      Parameters:
      name - The name of the string case
      splitter - The predicate that determines when a new word in the cased string begins.
      preserveSplit - if true the character that the splitter detected is preserved as the first character of the new word.
      joiner - The function to merge a list of strings into the cased String.
      postProcess - A function to perform post split processing on the generated String array.
  • Method Details

    • simpleJoiner

      public static Function<String[],String> simpleJoiner(char delimiter)
      Creates a function to join a String array with a character delimiter. Null strings are discarded. Empty strings will be processed and result in leading or trailing delimiters (if at the start or end of the array) or extra delimiters in other positions.
      Parameters:
      delimiter - the character to join the string array with.
      Returns:
      the function to perform the array join.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • assemble

      public String assemble(String[] segments)
      Creates a cased string from a collection of segments.
      Parameters:
      segments - the segments to create the CasedString from.
      Returns:
      a CasedString
    • getSegments

      public String[] getSegments(String string)
      Returns an array of each of the segments in this CasedString. Segments are defined as the strings between the separators in the CasedString. For the CAMEL case the segments are determined by the presence of a capital letter.
      Parameters:
      string - The string to parse into segments.
      Returns:
      the array of Strings that are segments of the cased string.