Package org.hortonmachine.gears.utils
Class StringUtilities
- java.lang.Object
-
- org.hortonmachine.gears.utils.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 Summary
Fields Modifier and Type Field Description static PatternREGEX_PATTER_DOT
-
Constructor Summary
Constructors Constructor Description StringUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringcheckSameName(List<String> strings, String string)Checks if the list of strings supplied contains the supplied string.static StringjoinStrings(String separator, String... strings)Join strings throughStringBuilder.static String[]parseCommand(String command)static List<String>splitString(String string, int limit)Splits a string by char limit, not breaking works.static ScannerstreamToScanner(InputStream stream, String delimiter)Get scanner from input stream.static List<String>streamToStringList(InputStream stream, String delimiter)Extract strings form a stream.static double[]stringToDoubleArray(String string, String separator)Convert a string containing a list of numbers into its array.static StringtrimOrPadToCount(String string, int count)static StringtrimToCount(String string, int count)
-
-
-
Field Detail
-
REGEX_PATTER_DOT
public static final Pattern REGEX_PATTER_DOT
-
-
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 throughStringBuilder.- Parameters:
separator- separator to use ornull.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.
-
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. Ifnull, 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.
-
-