|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjmri.util.StringUtil
public class StringUtil
Common utility methods for working with Strings.
We needed a place to refactor common string-processing idioms in JMRI code, so this class was created. It's more of a library of procedures than a real class, as (so far) all of the operations have needed no state information.
In some cases, these routines use a Java 1.3 or later method, falling back to an explicit implementation when running on Java 1.1
| Constructor Summary | |
|---|---|
StringUtil()
|
|
| Method Summary | |
|---|---|
static String |
appendTwoHexFromInt(int val,
String inString)
Quickly append an int to a String as exactly two hexadecimal characters |
static byte[] |
bytesFromHexString(String s)
Create a byte[] from a String containing hexadecimal values. |
static String |
getNameFromState(int state,
int[] states,
String[] names)
Starting with two arrays, one of names and one of corresponding numeric state values, find the name string that matches a given state value. |
static String[] |
getNamesFromStateMasked(int state,
int[] states,
int[] masks,
String[] names)
Starting with three arrays, one of names, one of corresponding numeric state values, and one of masks for the state values, find the name string(s) that match a given state value |
static int |
getStateFromName(String name,
int[] states,
String[] names)
Starting with two arrays, one of names and one of corresponding numeric state values, find the state value that matches a given name string |
static String |
hexStringFromBytes(byte[] bytes)
Create a String containing hexadecimal values from a byte[]. |
static String |
join(Collection<String> s,
String delimiter)
Join a collection of strings, separated by a delimiter |
static String |
join(String[] s,
String delimiter)
Join an array of strings, separated by a delimiter |
static void |
numberSort(String[] values)
Sort String[] representing numbers, in ascending order. |
static String |
parenQuote(String in)
If there's an unmatched ), quote it with \, and quote \ with \ too. |
static void |
sort(Object[] values)
This is a lexagraphic sort; lower case goes to the end. |
static void |
sort(String[] values)
This is a lexagraphic sort; lower case goes to the end. |
static void |
sortUpperCase(Object[] values)
This is a case-independent lexagraphic sort. |
static String[] |
split(String input,
String divider)
Split a string into an array of Strings, at a particular divider. |
static List<String> |
splitParens(String in)
|
static String |
to8Bits(int val,
boolean msbLeft)
Convert a small number to eight 1/0 characters. |
static String |
twoHexFromInt(int val)
Convert an int to a exactly two hexadecimal characters |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public StringUtil()
| Method Detail |
|---|
public static int getStateFromName(String name,
int[] states,
String[] names)
public static String[] getNamesFromStateMasked(int state,
int[] states,
int[] masks,
String[] names)
public static String getNameFromState(int state,
int[] states,
String[] names)
public static String twoHexFromInt(int val)
val -
public static String appendTwoHexFromInt(int val,
String inString)
val - Value to append in hexinString - String to be extended
public static String to8Bits(int val,
boolean msbLeft)
msbLeft - the MSB is on the left of the displaypublic static String hexStringFromBytes(byte[] bytes)
bytes - byte array. Can be zero length,
but must not be null.
public static byte[] bytesFromHexString(String s)
s - String of hex values, ala "01 02 0A B1 21".
public static void sort(String[] values)
values - public static void sort(Object[] values)
values - public static void sortUpperCase(Object[] values)
values -
public static void numberSort(String[] values)
throws NumberFormatException
values -
NumberFormatException
public static String join(Collection<String> s,
String delimiter)
s - collection of stringsdelimiter -
public static String join(String[] s,
String delimiter)
s - collection of stringsdelimiter -
public static String[] split(String input,
String divider)
input - String to splitdivider - Where to divide the input; this does not appear in outputpublic static String parenQuote(String in)
public static List<String> splitParens(String in)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||