Class StringUtilities


  • public class StringUtilities
    extends java.lang.Object
    Escapes strings into and out of a format where they only contain printable characters. Need to duplicate escape / unescape of strings as we have in C++ for java version of system states.
    Author:
    Haakon Humberset
    • Constructor Summary

      Constructors 
      Constructor Description
      StringUtilities()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String escape​(java.lang.String source)  
      static java.lang.String escape​(java.lang.String source, char delimiter)
      Escapes strings into a format with only printable ASCII characters.
      static java.lang.String implode​(java.lang.String[] array, java.lang.String sepString)
      Returns the given array flattened to string, with the given separator string
      static java.lang.String implodeMultiline​(java.util.List<java.lang.String> lines)
      Returns the given list flattened to one with newline between
      static java.lang.String quote​(java.lang.Object object)
      Adds single quotes around object.toString Example: '12'
      static java.util.Set<java.lang.String> split​(java.lang.String s)
      Splits a string on both space and comma
      static java.lang.String stripSuffix​(java.lang.String string, java.lang.String suffix)  
      static java.lang.String truncateSequencesIfNecessary​(java.lang.String text, int maxConsecutiveLength)
      This will truncate sequences in a string of the same character that exceed the maximum allowed length.
      static java.lang.String unescape​(java.lang.String source)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StringUtilities

        public StringUtilities()
    • Method Detail

      • escape

        public static java.lang.String escape​(java.lang.String source)
      • escape

        public static java.lang.String escape​(java.lang.String source,
                                              char delimiter)
        Escapes strings into a format with only printable ASCII characters.
        Parameters:
        source - The string to escape
        delimiter - Escape this character too, even if it is printable.
        Returns:
        The escaped string
      • unescape

        public static java.lang.String unescape​(java.lang.String source)
      • implode

        public static java.lang.String implode​(java.lang.String[] array,
                                               java.lang.String sepString)
        Returns the given array flattened to string, with the given separator string
        Parameters:
        array - the array
        sepString - or null
        Returns:
        imploded array
      • implodeMultiline

        public static java.lang.String implodeMultiline​(java.util.List<java.lang.String> lines)
        Returns the given list flattened to one with newline between
        Returns:
        flattened string
      • truncateSequencesIfNecessary

        public static java.lang.String truncateSequencesIfNecessary​(java.lang.String text,
                                                                    int maxConsecutiveLength)
        This will truncate sequences in a string of the same character that exceed the maximum allowed length.
        Returns:
        The same string or a new one if truncation is done.
      • stripSuffix

        public static java.lang.String stripSuffix​(java.lang.String string,
                                                   java.lang.String suffix)
      • quote

        public static java.lang.String quote​(java.lang.Object object)
        Adds single quotes around object.toString Example: '12'
      • split

        public static java.util.Set<java.lang.String> split​(java.lang.String s)
        Splits a string on both space and comma