com.partnersoft.data
Class StringLib

java.lang.Object
  extended by com.partnersoft.data.StringLib
All Implemented Interfaces:
Lib

public class StringLib
extends java.lang.Object
implements Lib

General-purpose string functions.

Copyright 2003-2007 Partner Software, Inc.

Version:
$Id: StringLib.java 1790 2009-02-19 02:06:29Z paul $
Author:
Paul Reavis

Method Summary
static java.lang.String doubleToString(double victim)
          Converts a double to a string, with no stinking scientific notation.
static java.lang.String fill(int desiredLength, java.lang.String filler)
          Returns a String constructed by repeating the filler pattern until the result is the desired length.
static int findLineIndex(java.lang.String str, int lineToFind)
           
static int findLineIndex(java.lang.String str, int startFrom, int startFromLine, int lineToFind)
          Continues a search from a known starting point and line number.
static java.lang.String format(java.lang.String format, java.lang.Object... values)
          A smarter version of String.format() that snoops the format string and does appropriate data conversions.
static boolean hasIntegerPrefix(java.lang.String string)
          Returns true if the given string has an integer prefix.
static boolean hasIntegerSuffix(java.lang.String string)
          Checks for an integer suffix.
static int integerPrefixOf(java.lang.String string)
          Attempts to parse a integer prefix for the given string and return it as an integer.
static int integerSuffixOf(java.lang.String string)
          Returns the integer value of the suffix of the string.
static java.lang.String intToBinary(int aint)
           
static java.lang.String intToHex(int aint)
           
static java.lang.String join(java.lang.String delimiter, java.lang.Iterable<?> list)
           
static java.lang.String join(java.lang.String delimiter, java.lang.Object... list)
           
static java.lang.String leftPad(java.lang.String original, int desiredLength, java.lang.String filler)
          Returns a String of the desired length, padded with filler at the beginning and with the original String at the end.
static java.lang.String longToBinary(long along)
           
static java.lang.String longToHex(long along)
           
static java.lang.String longToString(long victim)
          Converts a long to a string, with no stinking scientific notation.
static java.lang.String removeIntegerPrefix(java.lang.String string)
          Removes any integer prefix and returns the remainder of the String.
static java.lang.String removeIntegerSuffix(java.lang.String string)
          Removes integer suffix and returns the remainder.
static java.lang.String replace(java.lang.String string, java.lang.String oldStr, java.lang.String newStr)
           
static java.lang.String rightPad(java.lang.String original, int desiredLength, java.lang.String filler)
          Returns a String of the desired length, with the original String at the beginning and padded with filler at the end.
static java.lang.String shortToBinary(short aint)
           
static java.lang.String shortToHex(short aint)
           
static java.lang.String[] split(java.lang.String original, char delimiter)
          Very boneheaded split.
static java.lang.String toString(double value)
           
static java.lang.String toString(int value)
           
static java.lang.String toString(java.lang.Object value)
          Converts things to strings a bit more smartly, mainly primitives and primitive arrays.
static java.lang.String trimAndNullIfBlank(java.lang.String input)
          Removes any whitespace from the beginning and end of the given string, returning the result or null if the result is empty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

doubleToString

public static java.lang.String doubleToString(double victim)
Converts a double to a string, with no stinking scientific notation.


longToString

public static java.lang.String longToString(long victim)
Converts a long to a string, with no stinking scientific notation.


toString

public static java.lang.String toString(java.lang.Object value)
Converts things to strings a bit more smartly, mainly primitives and primitive arrays.


toString

public static java.lang.String toString(double value)

toString

public static java.lang.String toString(int value)

hasIntegerSuffix

public static boolean hasIntegerSuffix(java.lang.String string)
Checks for an integer suffix.

Parameters:
string - to check
Returns:
true if string has an integer suffix.

removeIntegerSuffix

public static java.lang.String removeIntegerSuffix(java.lang.String string)
Removes integer suffix and returns the remainder.

Parameters:
string - input string
Returns:
everything except the integer suffix

integerSuffixOf

public static int integerSuffixOf(java.lang.String string)
Returns the integer value of the suffix of the string.

Parameters:
string - string to parse an integer suffix from
Returns:
integer value of suffix

hasIntegerPrefix

public static boolean hasIntegerPrefix(java.lang.String string)
Returns true if the given string has an integer prefix.

Parameters:
string - string to check
Returns:
true if the beginning of a string is an integer

removeIntegerPrefix

public static java.lang.String removeIntegerPrefix(java.lang.String string)
Removes any integer prefix and returns the remainder of the String.

Parameters:
string - string to strip the integer prefix from
Returns:
everything except the integer prefix

integerPrefixOf

public static int integerPrefixOf(java.lang.String string)
Attempts to parse a integer prefix for the given string and return it as an integer.

Parameters:
string - string to parse
Returns:
value of integer prefix

fill

public static java.lang.String fill(int desiredLength,
                                    java.lang.String filler)
Returns a String constructed by repeating the filler pattern until the result is the desired length. If necessary, truncates the last instance of the pattern such that the String is exactly the requested length.

Parameters:
desiredLength - length of returned string
filler - repeated pattern to fill string with
Returns:
string of desired length consisting of filler repeated

leftPad

public static java.lang.String leftPad(java.lang.String original,
                                       int desiredLength,
                                       java.lang.String filler)
Returns a String of the desired length, padded with filler at the beginning and with the original String at the end.

Parameters:
original - unpadded original, becomes suffix of result
desiredLength - length of entire result string
filler - padding repeated to form prefix of result
Returns:
string of desired length consisting of (padding + original)

rightPad

public static java.lang.String rightPad(java.lang.String original,
                                        int desiredLength,
                                        java.lang.String filler)
Returns a String of the desired length, with the original String at the beginning and padded with filler at the end.

Parameters:
original - unpadded original, becomes prefix of result
desiredLength - length of entire result string
filler - padding repeated to form suffix of result
Returns:
string of desired length consisting of (original + padding)

trimAndNullIfBlank

public static java.lang.String trimAndNullIfBlank(java.lang.String input)
Removes any whitespace from the beginning and end of the given string, returning the result or null if the result is empty.


longToHex

public static java.lang.String longToHex(long along)

intToHex

public static java.lang.String intToHex(int aint)

shortToHex

public static java.lang.String shortToHex(short aint)

longToBinary

public static java.lang.String longToBinary(long along)

intToBinary

public static java.lang.String intToBinary(int aint)

shortToBinary

public static java.lang.String shortToBinary(short aint)

split

public static java.lang.String[] split(java.lang.String original,
                                       char delimiter)
Very boneheaded split. Does not handle escaped delimiters at all. Fast, though.


replace

public static java.lang.String replace(java.lang.String string,
                                       java.lang.String oldStr,
                                       java.lang.String newStr)

findLineIndex

public static int findLineIndex(java.lang.String str,
                                int lineToFind)

findLineIndex

public static int findLineIndex(java.lang.String str,
                                int startFrom,
                                int startFromLine,
                                int lineToFind)
Continues a search from a known starting point and line number.

Parameters:
str -
startFrom -
startFromLine -
lineToFind -
Returns:

join

public static java.lang.String join(java.lang.String delimiter,
                                    java.lang.Iterable<?> list)

join

public static java.lang.String join(java.lang.String delimiter,
                                    java.lang.Object... list)

format

public static java.lang.String format(java.lang.String format,
                                      java.lang.Object... values)
A smarter version of String.format() that snoops the format string and does appropriate data conversions.

Parameters:
format -
values -
Returns: