public class StringTools
extends Object
Modifier and Type | Field and Description |
---|---|
static int |
COLUMN_SPACING
Number of spaces between column prints in
StringTools.printListInColumns(List, PrintStream) |
Constructor and Description |
---|
StringTools() |
Modifier and Type | Method and Description |
---|---|
static String |
addIndexingAngleBrackets(String s)
Will insert angle brackets around indexing value
at the end of a String.
|
static int |
countOccurrences(String str,
char c)
Counts occurrences of a character in a string.
|
static boolean |
isInteger(String s) |
static String |
longestCommonPrefix(String s0,
String s1)
Get the longest common prefix between two strings starting at the beginning.
|
static String |
lowerCaseFirstLetter(String name) |
static void |
main(String[] args) |
static String |
makeCamelCase(String name) |
static String |
makeUpperCamelCase(String name) |
static String |
makeWhiteSpace(int length)
Creates a String of spaces of the specified length
|
static List<String> |
naturalSort(List<String> strings)
Sorts strings using the 'natural' sort approach where numbers are sorted by
their magnitudes, i.e.
|
static String[] |
naturalSort(String[] strings)
Sorts strings using the 'natural' sort approach where numbers are sorted by
their magnitudes, i.e.
|
static void |
printListInColumns(List<String> items,
PrintStream ps)
Prints a list of Strings in columns, based upon the terminal width.
|
static void |
printListInColumns(List<String> items,
PrintStream ps,
int maxColumns)
Prints a list of Strings in columns, based upon the terminal width.
|
static String |
removeLastSeparator(String s)
Removes any trailing '/' (File.separator) characters from file paths.
|
static String |
removeOuterQuotes(String s)
Removes any double quote characters from the ends of the string.
|
static String |
startsWithAny(String str,
Collection<String> prefixes)
Checks if given string starts with any of the provided prefix strings
|
public static final int COLUMN_SPACING
StringTools.printListInColumns(List, PrintStream)
public static String makeCamelCase(String name)
public static String lowerCaseFirstLetter(String name)
public static String makeUpperCamelCase(String name)
public static String removeOuterQuotes(String s)
s
- public static List<String> naturalSort(List<String> strings)
strings
- The list of strings to sortpublic static String removeLastSeparator(String s)
s
- File pathpublic static String[] naturalSort(String[] strings)
strings
- The array of strings to sortpublic static boolean isInteger(String s)
public static String addIndexingAngleBrackets(String s)
input0 --> input<0>
input10 --> input<10>
clk --> clk
s
- The string to which potentially angle brackets will be addedpublic static int countOccurrences(String str, char c)
str
- String to checkc
- Character of interestpublic static String longestCommonPrefix(String s0, String s1)
s0
- First string to checks1
- Second string to checkpublic static String startsWithAny(String str, Collection<String> prefixes)
str
- The string to checkprefixes
- The set of possible prefixes to match against strpublic static String makeWhiteSpace(int length)
length
- The number of spaces in the desired Stringpublic static void printListInColumns(List<String> items, PrintStream ps)
items
- The list of Strings to printps
- The stream to send the printed Strings to.public static void printListInColumns(List<String> items, PrintStream ps, int maxColumns)
items
- The list of Strings to printps
- The stream to send the printed Strings to.maxColumns
- A maximum limit to the number columns to printpublic static void main(String[] args)