Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.eireneh.util
Class StringUtil  view StringUtil download StringUtil.java

java.lang.Object
  extended bycom.eireneh.util.StringUtil

public final class StringUtil
extends java.lang.Object

A generic class of String utils. It would be good if we could put this stuff in java.lang ...
Distribution Licence:
Project B is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
The License is available on the internet here, by writing to Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, Or locally at the Licence link below.
The copyright to this program is held by it's authors.


Field Summary
private static char[] hexDigit
          A table of hex digits
protected static Logger log
          The log stream
static java.lang.String NEWLINE
          The newline character
 
Constructor Summary
StringUtil()
           
 
Method Summary
static java.lang.String blankIfNull(java.lang.String param)
          Returns an empty string if null was passed in
static java.lang.String cat(java.lang.String[] arr, int start, int end, java.lang.String sep)
          Take a String array and create a String out of some elements EG:
static java.lang.String cat(java.lang.String[] arr, int start, java.lang.String sep)
          Take a String array and create a String out of some elements EG:
static java.lang.String cat(java.lang.String[] arr, java.lang.String sep)
          Take a String array and create a String out of all elements
static java.lang.String chain(int num, char ch)
          Create a string consisting of num chars
static java.lang.String chain(int num, java.lang.String str)
          Create a string consisting of num chars
static java.lang.String chop(java.lang.String orig, java.lang.String start_delim, java.lang.String end_delim)
          Strips the text between a pair of delimitters.
static int countInstancesOf(java.lang.String str, char ch)
          Count the instances of a character in a string
static java.lang.String createJavaName(java.lang.String variable)
          This function creates a Java style name from a variable name type input.
static java.lang.String createTitle(java.lang.String variable)
          This function creates a readable title from a variable name type input.
static java.lang.String escape(java.lang.String orig)
          Escapes certain characters from an original string.
static java.lang.String[] escape(java.lang.String[] orig)
          Escapes certain characters from an original string.
static java.lang.String fileNameToJavaPackage(java.lang.String filename)
          This function creates a Java Package name from a file name and the system default classpath.
static java.lang.String fileNameToJavaPackage(java.lang.String filename, java.lang.String classpath)
          This function creates a Java Class/Package name from a file name and a classpath.
static java.lang.String findClasspathEntry(java.lang.String classname)
          This function find the first matching filename for a Java class file from the classpath, if none is found it returns null.
static java.lang.String findClasspathEntry(java.lang.String classname, java.lang.String classpath)
          This function find the first matching filename for a Java class file from the classpath, if none is found it returns null.
static java.lang.String getCapitals(java.lang.String words)
          For example getCapitals("Java DataBase Connectivity") = "JDBC" and getCapitals("Church of England") = "CE".
static java.lang.String getInitials(java.lang.String words)
          For example getInitials("Java DataBase Connectivity") = "JDC" and getInitials("Church of England") = "CoE".
static java.net.URL getLocalURL(java.lang.String name)
          Get a URL from a class name.
static java.lang.String getNewline()
          Returns the newline character
static java.lang.String[] getStringArray(java.lang.Object[] objs)
          Turns an array of Objects into an array of Strings
static java.lang.String[] getStringArray(java.util.Vector vec)
          Turns a Vector of Strings into an array of Strings
static java.lang.String nullIfBlank(java.lang.String param)
          Returns an null if an empty string was passed in
static int parseInt(java.lang.String str, int defaultval)
          Helper for parsing Integers
static java.lang.String read(java.io.Reader in)
          This method reads an InputStream In its entirety, and passes The text back as a string.
static java.lang.String removeChar(java.lang.String orig, char x)
          Removes a character from a String
static java.lang.String removeChars(java.lang.String orig, java.lang.String x)
          Removes a character from a String
static java.lang.String setLength(java.lang.String str, int len)
          Ensure a string is of a fixed length by truncating it or by adding spaces untill it is.
static java.lang.String[] shift(java.lang.String[] cmd)
          Reduce the size of the array by dropping element zero
static java.lang.String swap(java.lang.String orig, java.lang.String x, java.lang.String y)
          Search and replace in a String
static char toHexChar(byte nibble)
          Convert a nibble to a hex character
static java.lang.String toHexString(int i)
          Convert a int to a hex string
static java.lang.String[] tokenize(java.lang.String command)
          Take a string and parse it (by the default delimiters) into an Array of Strings.
static java.lang.String[] tokenize(java.lang.String command, java.lang.String delim)
          Take a string and parse it into an Array of Strings.
static java.lang.String[] tokenize(java.lang.String command, java.lang.String delim, char escape)
          Take a string and parse it into an Array of Strings.
static java.lang.String[] tokenize(java.lang.String command, java.lang.String delim, java.lang.String qual)
          Take a string and parse it taking note of string qualifiers into an Array of Strings.
static byte[] tokenizeByte(java.lang.String command)
          Parses a String like "1 2 3 4" into a Byte Array like {1, 2, 3, 4}
static short[] tokenizeShort(java.lang.String command)
          Parses a String like "1 2 3 4" into a Byte Array like {1, 2, 3, 4}
static java.lang.String toString(java.lang.Object[] array)
          Create a debug version of an array by calling toString on all the objects in the array
static java.lang.String[] trim(java.lang.String[] cmd)
          Run String.trim on all the elements of this array
static java.lang.String unescape(java.lang.String orig)
          UnEscapes certain characters from an original string.
static java.lang.String[] unescape(java.lang.String[] orig)
          UnEscapes certain characters from an original string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hexDigit

private static final char[] hexDigit
A table of hex digits


NEWLINE

public static final java.lang.String NEWLINE
The newline character


log

protected static Logger log
The log stream

Constructor Detail

StringUtil

public StringUtil()
Method Detail

toString

public static java.lang.String toString(java.lang.Object[] array)
Create a debug version of an array by calling toString on all the objects in the array


nullIfBlank

public static java.lang.String nullIfBlank(java.lang.String param)
Returns an null if an empty string was passed in


blankIfNull

public static java.lang.String blankIfNull(java.lang.String param)
Returns an empty string if null was passed in


getNewline

public static java.lang.String getNewline()
Returns the newline character


tokenizeByte

public static byte[] tokenizeByte(java.lang.String command)
                           throws java.lang.NumberFormatException
Parses a String like "1 2 3 4" into a Byte Array like {1, 2, 3, 4}


tokenizeShort

public static short[] tokenizeShort(java.lang.String command)
                             throws java.lang.NumberFormatException
Parses a String like "1 2 3 4" into a Byte Array like {1, 2, 3, 4}


tokenize

public static java.lang.String[] tokenize(java.lang.String command)
Take a string and parse it (by the default delimiters) into an Array of Strings.


tokenize

public static java.lang.String[] tokenize(java.lang.String command,
                                          java.lang.String delim)
Take a string and parse it into an Array of Strings.


tokenize

public static java.lang.String[] tokenize(java.lang.String command,
                                          java.lang.String delim,
                                          char escape)
Take a string and parse it into an Array of Strings.


tokenize

public static java.lang.String[] tokenize(java.lang.String command,
                                          java.lang.String delim,
                                          java.lang.String qual)
Take a string and parse it taking note of string qualifiers into an Array of Strings.


escape

public static java.lang.String escape(java.lang.String orig)
Escapes certain characters from an original string.


escape

public static java.lang.String[] escape(java.lang.String[] orig)
Escapes certain characters from an original string.


unescape

public static java.lang.String unescape(java.lang.String orig)
UnEscapes certain characters from an original string.


unescape

public static java.lang.String[] unescape(java.lang.String[] orig)
UnEscapes certain characters from an original string.


swap

public static java.lang.String swap(java.lang.String orig,
                                    java.lang.String x,
                                    java.lang.String y)
Search and replace in a String


removeChars

public static java.lang.String removeChars(java.lang.String orig,
                                           java.lang.String x)
Removes a character from a String


removeChar

public static java.lang.String removeChar(java.lang.String orig,
                                          char x)
Removes a character from a String


cat

public static java.lang.String cat(java.lang.String[] arr,
                                   java.lang.String sep)
Take a String array and create a String out of all elements


cat

public static java.lang.String cat(java.lang.String[] arr,
                                   int start,
                                   java.lang.String sep)
Take a String array and create a String out of some elements EG:
   String[] arr = "a", "b", "c", "d", "e";
   StringUtil.cat(arr, 2, "-")) = "c-d-e"
 


cat

public static java.lang.String cat(java.lang.String[] arr,
                                   int start,
                                   int end,
                                   java.lang.String sep)
Take a String array and create a String out of some elements EG:
   String[] arr = "a", "b", "c", "d", "e";
   StringUtil.cat(arr, 2, 3, "-")) = "c-d"
 


trim

public static java.lang.String[] trim(java.lang.String[] cmd)
Run String.trim on all the elements of this array


shift

public static java.lang.String[] shift(java.lang.String[] cmd)
Reduce the size of the array by dropping element zero


chop

public static java.lang.String chop(java.lang.String orig,
                                    java.lang.String start_delim,
                                    java.lang.String end_delim)
Strips the text between a pair of delimitters. For example: chop("123(456)789", "(", ")") = "123789" Delimiters currently do not nest. So: chop("12(34(56)78)9", "(", ")") = Exception


read

public static java.lang.String read(java.io.Reader in)
                             throws java.io.IOException
This method reads an InputStream In its entirety, and passes The text back as a string. If you are reading from a source that can block then be preapred for a long wait for this to return.


getStringArray

public static java.lang.String[] getStringArray(java.util.Vector vec)
Turns a Vector of Strings into an array of Strings


getStringArray

public static java.lang.String[] getStringArray(java.lang.Object[] objs)
Turns an array of Objects into an array of Strings


chain

public static java.lang.String chain(int num,
                                     char ch)
Create a string consisting of num chars


chain

public static java.lang.String chain(int num,
                                     java.lang.String str)
Create a string consisting of num chars


setLength

public static java.lang.String setLength(java.lang.String str,
                                         int len)
Ensure a string is of a fixed length by truncating it or by adding spaces untill it is.


countInstancesOf

public static int countInstancesOf(java.lang.String str,
                                   char ch)
Count the instances of a character in a string


parseInt

public static int parseInt(java.lang.String str,
                           int defaultval)
Helper for parsing Integers


createTitle

public static java.lang.String createTitle(java.lang.String variable)
This function creates a readable title from a variable name type input. For example calling: StringUtil.createTitle("one_two") = "One Two" StringUtil.createTitle("oneTwo") = "One Two"


getInitials

public static java.lang.String getInitials(java.lang.String words)
For example getInitials("Java DataBase Connectivity") = "JDC" and getInitials("Church of England") = "CoE".


getCapitals

public static java.lang.String getCapitals(java.lang.String words)
For example getCapitals("Java DataBase Connectivity") = "JDBC" and getCapitals("Church of England") = "CE". A character is tested for capitalness using Character.isUpperCase and not Character.isUpperCase, which seems to be less correct from what I can see of the docs but works!


createJavaName

public static java.lang.String createJavaName(java.lang.String variable)
This function creates a Java style name from a variable name type input. For example calling: StringUtil.createTitle("one_two") = "OneTwo" StringUtil.createTitle("oneTwo") = "OneTwo"


fileNameToJavaPackage

public static java.lang.String fileNameToJavaPackage(java.lang.String filename,
                                                     java.lang.String classpath)
This function creates a Java Class/Package name from a file name and a classpath. For example: StringUtil.fileNameToJavaPackage("C:\\src\\fred\\Bing.class", "C:\\src") = "fred.Bing"


fileNameToJavaPackage

public static java.lang.String fileNameToJavaPackage(java.lang.String filename)
This function creates a Java Package name from a file name and the system default classpath. For example: StringUtil.fileNameToJavaPackage("C:\\src\\fred\\Bing.class") = "fred.Bing" given a classpath of "C:\\src"


findClasspathEntry

public static java.lang.String findClasspathEntry(java.lang.String classname,
                                                  java.lang.String classpath)
This function find the first matching filename for a Java class file from the classpath, if none is found it returns null.


findClasspathEntry

public static java.lang.String findClasspathEntry(java.lang.String classname)
This function find the first matching filename for a Java class file from the classpath, if none is found it returns null.


getLocalURL

public static java.net.URL getLocalURL(java.lang.String name)
Get a URL from a class name. If there are any problems then we return null, and we don't throw an Exception.


toHexChar

public static char toHexChar(byte nibble)
Convert a nibble to a hex character


toHexString

public static java.lang.String toHexString(int i)
Convert a int to a hex string