ecologylab.generic
Class StringTools

java.lang.Object
  extended by ecologylab.generic.Debug
      extended by ecologylab.generic.StringTools

public class StringTools
extends Debug

A set of lovely convenience methods for doing operations on String s and StringBuffers.


Field Summary
static java.lang.String EMPTY_STRING
           
static java.lang.String FIND_PUNCTUATION_REGEX
           
 
Constructor Summary
StringTools()
           
 
Method Summary
static void clear(java.lang.StringBuffer buffy)
          Reset the StringBuffer, so that is empty and ready for reuse.
static void clear(java.lang.StringBuilder buffy)
          Reset the StringBuffer, so that is empty and ready for reuse.
static boolean contains(java.lang.String in, char toMatch)
           
static boolean contains(java.lang.String in, java.lang.String toMatch)
           
static java.lang.String domain(java.lang.String hostString)
          Useful for finding common domains.
static java.lang.String domain(java.net.URL url)
           
static boolean endsWithSlash(java.lang.String path)
           
static int findMatchingParenLoc(java.lang.String relationFrag, int startLoc)
          Find the last parenthesis given the location of the first one
static java.lang.String hash(java.lang.String message)
           
static boolean isLowerCase(java.lang.String s)
          Return true iff all the characters in the argument are lower case.
static boolean isWhiteSpace(java.lang.CharSequence charSequence)
          Return true if all the chars in the CharSequence are whitespace.
static void main(java.lang.String[] s)
           
static void main2(java.lang.String[] s)
           
static java.lang.String noAnchorNoQueryPageString(java.net.URL u)
          Very efficiently forms String representation of url (better than URL.toExternalForm(), URL.toString()).
static java.lang.String noAnchorPageString(java.net.URL u)
           
static java.lang.String pageString(java.net.URL u)
           
static java.lang.String remove(java.lang.String string, char c)
          Remove all instances of @param c from @arg string
static java.lang.String removePunctuation(java.lang.String s)
          Turn punctuation into space delimiters.
static java.lang.String removePunctuation2(java.lang.String s)
           
static boolean sameDomain(java.net.URL url1, java.net.URL url2)
           
static java.lang.String[] seperateLowerUpperCase(java.lang.String in)
          Parse file name or variable name spellings, to convert to a set of words.
static void toLowerCase(java.lang.StringBuffer buffer)
          Changes the StringBuffer to lower case, in place, without any new storage allocation.
static void toLowerCase(java.lang.StringBuilder buffer)
          Changes the StringBuffer to lower case, in place, without any new storage allocation.
static java.lang.String toString(java.lang.StringBuffer buffer)
          Use this method to efficiently get a String from a StringBuffer on those occassions when you plan to keep using the StringBuffer, and want an efficiently made copy.
static java.lang.String toString(java.lang.StringBuilder buffer)
          Use this method to efficiently get a String from a StringBuffer, by copying, on those occassions when you plan to keep using the StringBuffer, and want an efficiently made copy.
static java.net.URL urlNoAnchor(java.net.URL source)
           
static java.net.URL urlRemoveAnchorIfNecessary(java.net.URL source)
           
 
Methods inherited from class ecologylab.generic.Debug
classSimpleName, closeLoggingFile, debug, debug, debug, debug, debugA, debugA, debugA, debugI, debugI, debugI, error, error, getClassName, getClassName, getInteractive, getPackageName, getPackageName, getPackageName, initialize, level, level, level, logToFile, print, print, println, println, println, println, println, println, printlnA, printlnA, printlnA, printlnI, printlnI, printlnI, printlnI, setLoggingFile, show, show, superString, toggleInteractive, toString, toString, warning, warning, weird, weird
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_STRING

public static final java.lang.String EMPTY_STRING
See Also:
Constant Field Values

FIND_PUNCTUATION_REGEX

public static final java.lang.String FIND_PUNCTUATION_REGEX
See Also:
Constant Field Values
Constructor Detail

StringTools

public StringTools()
Method Detail

toLowerCase

public static final void toLowerCase(java.lang.StringBuilder buffer)
Changes the StringBuffer to lower case, in place, without any new storage allocation.


toLowerCase

public static final void toLowerCase(java.lang.StringBuffer buffer)
Changes the StringBuffer to lower case, in place, without any new storage allocation.


sameDomain

public static final boolean sameDomain(java.net.URL url1,
                                       java.net.URL url2)

domain

public static final java.lang.String domain(java.net.URL url)

domain

public static final java.lang.String domain(java.lang.String hostString)
Useful for finding common domains.


toString

public static final java.lang.String toString(java.lang.StringBuffer buffer)
Use this method to efficiently get a String from a StringBuffer on those occassions when you plan to keep using the StringBuffer, and want an efficiently made copy. In those cases, much better than new String(StringBuffer)


toString

public static final java.lang.String toString(java.lang.StringBuilder buffer)
Use this method to efficiently get a String from a StringBuffer, by copying, on those occassions when you plan to keep using the StringBuffer, and want an efficiently made copy. In those cases, much better than new String(StringBuffer)


contains

public static final boolean contains(java.lang.String in,
                                     java.lang.String toMatch)

contains

public static final boolean contains(java.lang.String in,
                                     char toMatch)

noAnchorNoQueryPageString

public static final java.lang.String noAnchorNoQueryPageString(java.net.URL u)
Very efficiently forms String representation of url (better than URL.toExternalForm(), URL.toString()). Doesn't include query or anchor.


noAnchorPageString

public static final java.lang.String noAnchorPageString(java.net.URL u)

pageString

public static final java.lang.String pageString(java.net.URL u)

urlRemoveAnchorIfNecessary

public static final java.net.URL urlRemoveAnchorIfNecessary(java.net.URL source)

urlNoAnchor

public static final java.net.URL urlNoAnchor(java.net.URL source)

seperateLowerUpperCase

public static java.lang.String[] seperateLowerUpperCase(java.lang.String in)
Parse file name or variable name spellings, to convert to a set of words.

Parameters:
in - input String, for example: "isFileName".
Returns:
An array of Strings, for example: "is", "file", "name".

remove

public static java.lang.String remove(java.lang.String string,
                                      char c)
Remove all instances of @param c from @arg string


removePunctuation

public static java.lang.String removePunctuation(java.lang.String s)
Turn punctuation into space delimiters.


removePunctuation2

public static java.lang.String removePunctuation2(java.lang.String s)

main

public static void main(java.lang.String[] s)

main2

public static void main2(java.lang.String[] s)

clear

public static final void clear(java.lang.StringBuffer buffy)
Reset the StringBuffer, so that is empty and ready for reuse. Do this with a minimum of overhead, given the latest vagaries of the JDK implementation.


clear

public static final void clear(java.lang.StringBuilder buffy)
Reset the StringBuffer, so that is empty and ready for reuse. Do this with a minimum of overhead, given the latest vagaries of the JDK implementation.


isLowerCase

public static boolean isLowerCase(java.lang.String s)
Return true iff all the characters in the argument are lower case.

Parameters:
s -
Returns:

endsWithSlash

public static boolean endsWithSlash(java.lang.String path)
Parameters:
path -
Returns:
true if the String ends with a forward slash, like a nice directory.

findMatchingParenLoc

public static int findMatchingParenLoc(java.lang.String relationFrag,
                                       int startLoc)
Find the last parenthesis given the location of the first one

Parameters:
relationFrag - The relation
startLoc - The open parenthesis location in the string
Returns:
The location of the close parenthesis matching the open one

hash

public static final java.lang.String hash(java.lang.String message)

isWhiteSpace

public static final boolean isWhiteSpace(java.lang.CharSequence charSequence)
Return true if all the chars in the CharSequence are whitespace.

Parameters:
charSequence -
Returns: