Class StringUtilities


  • public class StringUtilities
    extends Object
    An utilities class for handling strings and similar.
    Since:
    0.7.0
    Author:
    Andrea Antonello (www.hydrologis.com)
    • Field Detail

      • REGEX_PATTER_DOT

        public static final Pattern REGEX_PATTER_DOT
    • Constructor Detail

      • StringUtilities

        public StringUtilities()
    • Method Detail

      • checkSameName

        public static String checkSameName​(List<String> strings,
                                           String string)
        Checks if the list of strings supplied contains the supplied string.

        If the string is contained it changes the name by adding a number.

        The spaces are trimmed away before performing name equality.

        Parameters:
        strings - the list of existing strings.
        string - the proposed new string, to be changed if colliding.
        Returns:
        the new non-colliding name for the string.
      • joinStrings

        public static String joinStrings​(String separator,
                                         String... strings)
        Join strings through StringBuilder.
        Parameters:
        separator - separator to use or null.
        strings - strings to join.
        Returns:
        the joined string.
      • splitString

        public static List<String> splitString​(String string,
                                               int limit)
        Splits a string by char limit, not breaking works.
        Parameters:
        string - the string to split.
        limit - the char limit.
        Returns:
        the list of split words.
      • trimToCount

        public static String trimToCount​(String string,
                                         int count)
      • trimOrPadToCount

        public static String trimOrPadToCount​(String string,
                                              int count)
      • streamToScanner

        public static Scanner streamToScanner​(InputStream stream,
                                              String delimiter)
        Get scanner from input stream. Note: the scanner needs to be closed after use.
        Parameters:
        stream - the stream to read.
        delimiter - the delimiter to use.
        Returns:
        the scanner.
      • streamToStringList

        public static List<String> streamToStringList​(InputStream stream,
                                                      String delimiter)
        Extract strings form a stream.
        Parameters:
        stream - the stream.
        delimiter - the delimiter used to split. If null, newline is used.
        Returns:
        the list of string pieces.
      • stringToDoubleArray

        public static double[] stringToDoubleArray​(String string,
                                                   String separator)
        Convert a string containing a list of numbers into its array.
        Parameters:
        string - the string containing numbers.
        separator - the number separator.
        Returns:
        the array of values.
      • parseCommand

        public static String[] parseCommand​(String command)