Class Strings

java.lang.Object
eu.bandm.tools.util.java.Strings

public class Strings extends Object
Utility class for string manipulation.
  • Field Details

    • linefeedPattern

      static final Pattern linefeedPattern
    • STANDARD_SUFFIX

      public static final String STANDARD_SUFFIX
      Will be appended to a truncated string.
      See Also:
  • Method Details

    • removeQuotes

      public static String removeQuotes(String in)
      Remove the first and the last character in a string. (Assuming that these are open and close quotations marks.)
    • normalizeLinefeed

      public static String normalizeLinefeed(String s)
      Replace linefeed according to different encodings, plus maximal preceding whitespace, by one standard Unix encoding. The replaced encodings are "\n", "\r", and \r\n. The replacement is "\n". The preceding whitespace is a maximal sequnce of blanks, tabs, and formfeeds. Java regular expressions.

      (Please note that there are other linefeed encodings, not covered by this method and seldomly used, like IBM mainframe 0x85.)

    • replaceLinefeedByBlank

      public static String replaceLinefeedByBlank(String s)
      Replace linefeed according to different encodings, plus maximal preceding whitespace, by one single space character. The replaced encodings are "\n", "\r", and \r\n. The replacement is "\n". The preceding whitespace is a maximal sequnce of blanks, tabs, and formfeeds. Java regular expressions.

      (Please note that there are other linefeed encodings, not covered by this method and seldomly used, like IBM mainframe 0x85.)

    • prefix

      public static String prefix(String s, int len, String suffix)
      Deliver the prefix of the given string of the given max length. Append the suffix if the input has been truncated.
    • prefix

      public static String prefix(String s, int len)
      Deliver the prefix of the given string of the given max length. Append the STANDARD_SUFFIX if the input has been truncated.
    • hash32

      public static String hash32(Object o)
      Delivers easily readable String representation.
    • compose

      public static String compose(String prefix, String suffix)
      Compose two Strings with "." as the standard separator.
      See Also:
      • compose(String,String,String)
    • uncapitalize

      public static String uncapitalize(String s)
      Turns the very first character to lower case.
    • capitalize

      public static String capitalize(String s)
      Turns the very first character to upper case.
    • splitByFirst

      public static String[] splitByFirst(String text)
      Takes the very first character as delimiter for splitting the rest of the string. The last character is ignored if it is the delimiter, so no empty sub-string is recognized at the end of the list. Is somehow equivalent to the xslt code splitbyfirst in doctypes/d2d_gp/libbasic.xslt.
    • iterableToString

      public static <T> String iterableToString(@Opt @Opt String openDelim, Iterable<T> elements, String separator, @Opt @Opt String closeDelim)
      Convert an Iterable into a string representation by applying Object.toString() to all elements and merging the results.
    • iterableToString

      public static <T> String iterableToString(@Opt @Opt String openDelim, Iterable<T> elements, Function<T,String> fun, String separator, @Opt @Opt String closeDelim)
      Convert an Iterable into a string representation by applying the given function to all elements and merging the results.
    • collectionToText

      public static <T> String collectionToText(Collection<T> elements, Function<T,String> fun, String separatorNotLast, String separatorLast, String separatorOnly)
      Convert a collection into a human-readable string representation by applying the given function to all elements and merging the results. Is required for printed English language, for results like »a, b, and c« and »a and b«.
      Parameters:
      elements - to display.
      fun - to apply.
      separatorNotLast - separator between multiple elements
      separatorLast - separator between the last two elements
      separatorOnly - separator between only two elements
    • editDistance

      public static int editDistance(String s1, String s2)
      Computes the Levenshtein distance of two strings.
      Parameters:
      s1 - one string
      s2 - another string
      Returns:
      the Levenshtein (edit) distance of the two strings
      See Also: