org.simoes.util
Class StringUtil

java.lang.Object
  extended byorg.simoes.util.StringUtil

public class StringUtil
extends java.lang.Object

Utility class for manipulating Strings in Java that I have found useful.

Author:
Chris Simoes

Constructor Summary
StringUtil()
           
 
Method Summary
static java.lang.String checkYOrN(java.lang.String str)
           
static java.lang.String constructURL(java.lang.String webpage, java.util.Properties params)
          Creates a URL from the passed in parameters.
static java.lang.String containsAnyStrings(java.lang.String data, java.util.ArrayList matches)
          Returns true if the String data contains any of the Strings contained in the ArrayList.
static java.lang.String containsOnlyString(java.lang.String data, java.util.ArrayList matches, boolean ignoreCase)
          Returns true if the String data exactly matches one of the strings in contained in the ArrayList matches.
static java.lang.String createFixedLengthString(java.lang.String s, int length)
          Constructs a String of the fixed length given.
static java.util.Vector getLines(java.lang.String multiLine)
          Creates a Vector of lines parsed on newline characters.
static boolean isEmpty(java.lang.String str)
           
static void main(java.lang.String[] args)
           
static java.lang.String map2String(java.util.Map map)
          Converts the Map passed in to a string containing "key=value" pairs separated by \n characters.
static java.lang.String null2Empty(java.lang.String str)
          Returns an empty string "" if str is null.
static java.util.Vector parseCommand(byte[] command)
          Creates a Vector of byte[] from the command passed in.
static java.util.Vector parsePrintFileName(java.lang.String header)
          This parses the "name" field passed in the header of the control file or the data files.
static java.lang.String replaceString(java.lang.String line, java.lang.String replace, java.lang.String replaceWith)
          Replaces the "replace" String with the "replaceWith" String in the "line" String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

parseCommand

public static java.util.Vector parseCommand(byte[] command)
Creates a Vector of byte[] from the command passed in.

Parameters:
command - the bytes read in from the lpr client
Returns:
Vector Created by parsing on white space the command byte[] passed in

parsePrintFileName

public static java.util.Vector parsePrintFileName(java.lang.String header)
This parses the "name" field passed in the header of the control file or the data files. Example: Control File header = cfa001MyComputer Example: Data File header = dfa001MyComputer


replaceString

public static java.lang.String replaceString(java.lang.String line,
                                             java.lang.String replace,
                                             java.lang.String replaceWith)
Replaces the "replace" String with the "replaceWith" String in the "line" String. All occurances are replaced. If "replace" can't be found in "line" then the String "line" is returned. If "replace" or "replaceWith" are null then "line" is returned.

Parameters:
line - - String operated on
replace - - text we will be replacing
replaceWith - - text that will be substituted for "replace" text.
Returns:
String - the result of the replace

map2String

public static java.lang.String map2String(java.util.Map map)
Converts the Map passed in to a string containing "key=value" pairs separated by \n characters.


containsAnyStrings

public static java.lang.String containsAnyStrings(java.lang.String data,
                                                  java.util.ArrayList matches)
Returns true if the String data contains any of the Strings contained in the ArrayList.

Parameters:
data - - A string that we will search
matches - - An ArrayList that contains only Strings. We will search data to see if any of the Strings in matches are found in data.
Returns:
String - the first string in matches that was found in data, or null if no match was found.

containsOnlyString

public static java.lang.String containsOnlyString(java.lang.String data,
                                                  java.util.ArrayList matches,
                                                  boolean ignoreCase)
Returns true if the String data exactly matches one of the strings in contained in the ArrayList matches.

Parameters:
data - - A string that we will search
matches - - An ArrayList that contains only Strings. We will search data to see if any of the Strings in matches are found in data.
ignoreCase - - true = ignore case when comparing
Returns:
String - the first string in matches that was found in data, or null if no match was found.

null2Empty

public static java.lang.String null2Empty(java.lang.String str)
Returns an empty string "" if str is null. If str is not null then str is returned.


isEmpty

public static boolean isEmpty(java.lang.String str)

checkYOrN

public static java.lang.String checkYOrN(java.lang.String str)

constructURL

public static java.lang.String constructURL(java.lang.String webpage,
                                            java.util.Properties params)
Creates a URL from the passed in parameters. It has the following look:
webpage?param1=value1¶m2=value2......

Parameters:
webpage - - the destination we are headed to
params - - the parameters we append to the Destination, note the order of these parameters is random
Returns:
String - the constructed Destination

getLines

public static java.util.Vector getLines(java.lang.String multiLine)
Creates a Vector of lines parsed on newline characters.


createFixedLengthString

public static java.lang.String createFixedLengthString(java.lang.String s,
                                                       int length)
Constructs a String of the fixed length given. If the string passed in is greater than length, then the string is truncated to length. If the string is greater than length then the string is padded with spaces. If s is empty or null, then an empty string of spaces is returned.

Parameters:
s - - string to operate on
length - - desired length
Returns:
- fixed length String

main

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