net.sf.jomic.tools
Class StringTools

java.lang.Object
  extended by net.sf.jomic.tools.StringTools

public final class StringTools
extends java.lang.Object

Utility class to simplify dealing with Strings.

Author:
Thomas Aglassinger

Method Summary
 java.lang.String arrayToString(double[] data)
           
 java.lang.String arrayToString(java.io.File[] data)
           
 java.lang.String arrayToString(float[] data)
           
 java.lang.String arrayToString(int[] data)
           
 java.lang.String arrayToString(java.lang.String[] data)
           
 java.lang.String asHtmlEscaped(java.lang.String some)
          Escaped as HTML attribute value.
 java.lang.String camelized(java.lang.String some)
          Return some converted to "camel case" using "-" or "_" as word seperators.
 java.lang.String colorString(java.awt.Color color)
          Hex-color representation of color.
 java.lang.String colorString(long rgba)
          Hex-color representation of RGB color value.
 boolean equalsAnyOf(java.lang.String[] haystack, java.lang.String needle)
           
 boolean equalsAnyOf(java.lang.String[] haystack, java.lang.String needle, boolean sort)
           
 java.lang.String extractNumberBackwards(java.lang.String possiblyPagedName, int endIndex)
          Extract number by moving backwards starting at endIndex.
 int getDigitCount(int value)
          Get number of digits required to represent value (including a possible '-' for negative numbers).
 java.text.DecimalFormat getLeadingZeroFormat(int maxValue)
          Get DecimalFormat with leading zeroes that can handle up to maxValue.
 char[] getMnemonics(java.lang.String[] labels, char[] suggestions)
          Get unique mnemonics for all labels.
 java.lang.String getPercentText(double value)
          Get value formatted as percent.
 java.lang.String hexString(long value, int digits)
          Hex representation of value, prefixed with "0x".
 java.lang.String hexString(long value, int digits, java.lang.String prefix)
          Hex representation of value.
static StringTools instance()
          Get accessor to unique instance.
 boolean isNullOrEmpty(java.lang.String some)
          Is some null or only consisting of white space?
 boolean isSorted(java.lang.String[] some)
          Return true if some is sorted.
 boolean isWhiteSpace(java.lang.String some)
          Are all characters in some white space? If some is empty, return false.
 double log10(double some)
          Get 10-log.
 java.lang.String sourced(char some)
          Source code version of character some that can be pasted into a Java source.
 java.lang.String sourced(java.io.File some)
          Same as sourced(String), but uses absolute file path.
 java.lang.String sourced(java.lang.String some)
          Source code version of some that can be pasted into a Java source.
 int[] stringToIntArray(java.lang.String data)
           
 java.lang.String titled(java.lang.String some)
          Some as some, but with the first character converted to title case.
 java.lang.String trimPrefix(java.lang.String text, java.lang.String prefix)
          If text starts with prefix, trim it from the left, otherwise just return text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDigitCount

public int getDigitCount(int value)
Get number of digits required to represent value (including a possible '-' for negative numbers).


getLeadingZeroFormat

public java.text.DecimalFormat getLeadingZeroFormat(int maxValue)
Get DecimalFormat with leading zeroes that can handle up to maxValue.


getMnemonics

public char[] getMnemonics(java.lang.String[] labels,
                           char[] suggestions)
Get unique mnemonics for all labels.

Parameters:
labels - the long texts that need mnemonics
suggestions - an array with the same length as labels that can already contain mnemonics for certain labels. For the rest, use '\0' as suggestion so the will be computed automatically. A suggestion of null means that all mnemonics should be computed.

getPercentText

public java.lang.String getPercentText(double value)
Get value formatted as percent.


isNullOrEmpty

public boolean isNullOrEmpty(java.lang.String some)
Is some null or only consisting of white space?


isSorted

public boolean isSorted(java.lang.String[] some)
Return true if some is sorted.

See Also:
String.compareTo(java.lang.String)

isWhiteSpace

public boolean isWhiteSpace(java.lang.String some)
Are all characters in some white space? If some is empty, return false.


instance

public static StringTools instance()
Get accessor to unique instance.


arrayToString

public java.lang.String arrayToString(double[] data)

arrayToString

public java.lang.String arrayToString(java.io.File[] data)

arrayToString

public java.lang.String arrayToString(float[] data)

arrayToString

public java.lang.String arrayToString(int[] data)

arrayToString

public java.lang.String arrayToString(java.lang.String[] data)

asHtmlEscaped

public java.lang.String asHtmlEscaped(java.lang.String some)
Escaped as HTML attribute value. For example, "&" becomes "&".


camelized

public java.lang.String camelized(java.lang.String some)
Return some converted to "camel case" using "-" or "_" as word seperators. For example, "some-stuff-to-do" yields "someStuffToDo".


colorString

public java.lang.String colorString(long rgba)
Hex-color representation of RGB color value. For example, and RGB tupple of red=0x12, green=0x34, blue=0x56 would be encoded into an int of 0x123456, and yield "#123456". (This is the same principle used to represent colors in HTML.)

See Also:
Color.getRGB()

colorString

public java.lang.String colorString(java.awt.Color color)
Hex-color representation of color.

See Also:
Color.getRGB()

equalsAnyOf

public boolean equalsAnyOf(java.lang.String[] haystack,
                           java.lang.String needle)

equalsAnyOf

public boolean equalsAnyOf(java.lang.String[] haystack,
                           java.lang.String needle,
                           boolean sort)

extractNumberBackwards

public java.lang.String extractNumberBackwards(java.lang.String possiblyPagedName,
                                               int endIndex)
Extract number by moving backwards starting at endIndex. If the character at endIndex is no digit, return an empty string ("").


hexString

public java.lang.String hexString(long value,
                                  int digits,
                                  java.lang.String prefix)
Hex representation of value.

Parameters:
digits - the number of digits the result should have at least; if necessary, leading "0"s are prepended
prefix - the text to be used as the fist few characters of the result; "0x" if null.

hexString

public java.lang.String hexString(long value,
                                  int digits)
Hex representation of value, prefixed with "0x".

Parameters:
digits - the number of digits the result should have at least; if necessary, leading "0"s are prepended

log10

public double log10(double some)
Get 10-log.


sourced

public java.lang.String sourced(java.lang.String some)
Source code version of some that can be pasted into a Java source. The result is embedded in two quotes, escape characters are rendered where possible. Invisible characters are rendered as unicode escape. The value null results in the the text "null" (without quotes).


sourced

public java.lang.String sourced(char some)
Source code version of character some that can be pasted into a Java source. The result is embedded in two quotes, escape characters are rendered where possible. Invisible characters are rendered as unicode escape.


sourced

public java.lang.String sourced(java.io.File some)
Same as sourced(String), but uses absolute file path.

See Also:
sourced(String)

stringToIntArray

public int[] stringToIntArray(java.lang.String data)
                       throws java.io.IOException,
                              java.text.ParseException
Throws:
java.io.IOException
java.text.ParseException

titled

public java.lang.String titled(java.lang.String some)
Some as some, but with the first character converted to title case.

See Also:
Character.toTitleCase(char)

trimPrefix

public java.lang.String trimPrefix(java.lang.String text,
                                   java.lang.String prefix)
If text starts with prefix, trim it from the left, otherwise just return text.