org.shlublu.javax.lang
Class StringSubstitutor

java.lang.Object
  |
  +--org.shlublu.javax.lang.StringSubstitutor

public class StringSubstitutor
extends java.lang.Object

String convenience tool for substitutions.

Since:
0.1

Constructor Summary
StringSubstitutor()
          Empty constructor
StringSubstitutor(java.lang.String strDataGiven)
          Convenience constructor
 
Method Summary
 int count(java.lang.String strToken)
          Return the number of occurences of the token in the contained string
 int count(java.lang.String strToken, int iStartIndex)
          Return the number of occurences of the token in the contained string, starting the search from iStartIndex.
 int delete(java.lang.String strToken)
          Parse the contained string to remove the strToken occurences.
 int delete(java.lang.String strToken, int iStart)
          Parse the contained string starting from the given index, removing the strToken occurences.
 java.util.Vector getOccurences(java.lang.String strToken)
          Return the occurences of strToken in the contained string.
 java.util.Vector getOccurences(java.lang.String strToken, int iStart)
          Return the occurences of strToken located after iStart in the contained string.
 int replace(java.lang.String strToken, java.lang.String strBy)
          Parse the contained string to replace strToken by strBy.
 int replace(java.lang.String strToken, java.lang.String strBy, int iStart)
          Parse the contained string starting from the given index, replacing strToken by strBy.
 void setData(java.lang.String strData)
          Set the string to parse.
 java.lang.String toString()
          Return the parsed string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StringSubstitutor

public StringSubstitutor(java.lang.String strDataGiven)
Convenience constructor
Parameters:
String - strData The string to parse

StringSubstitutor

public StringSubstitutor()
Empty constructor
Method Detail

setData

public final void setData(java.lang.String strData)
Set the string to parse.
Parameters:
strData - The string to parse. Shouldn't be null if you plan to call replace

toString

public final java.lang.String toString()
Return the parsed string.
Overrides:
toString in class java.lang.Object
Returns:
The parsed string, can be null if initialized so

replace

public final int replace(java.lang.String strToken,
                         java.lang.String strBy)
Parse the contained string to replace strToken by strBy.
This method is just a shortcut to call replace(strToken, strBy, 0)
Parameters:
strToken - The token to replace. Musn't be null.
strBy - The replace by sequence. Musn't be null.
Returns:
The number of done replacements
See Also:
replace(java.lang.String,java.lang.String,int)

replace

public final int replace(java.lang.String strToken,
                         java.lang.String strBy,
                         int iStart)
Parse the contained string starting from the given index, replacing strToken by strBy.
Parameters:
strToken - The token to replace. Musn't be null.
strBy - The replace by sequence. Musn't be null.
iStart - The starting index (included)
Returns:
The number of done replacements
Throws:
NullPointerException - when one of the argument or the source string is null
java.lang.IllegalArgumentException - when iStart is < 0

delete

public final int delete(java.lang.String strToken)
Parse the contained string to remove the strToken occurences.
Parameters:
strToken - The token to replace. Musn't be null.
Returns:
The number of done deletions
Throws:
NullPointerException - when one of the argument or the source string is null
java.lang.IllegalArgumentException - when iStart is < 0
Since:
0.7

delete

public final int delete(java.lang.String strToken,
                        int iStart)
Parse the contained string starting from the given index, removing the strToken occurences.
Parameters:
strToken - The token to replace. Musn't be null.
iStart - The starting index (included)
Returns:
The number of done deletions
Throws:
NullPointerException - when one of the argument or the source string is null
java.lang.IllegalArgumentException - when iStart is < 0
Since:
0.7

count

public final int count(java.lang.String strToken)
Return the number of occurences of the token in the contained string
Parameters:
strToken - The token
Returns:
The number of occurences of strToken
Since:
0.7

count

public final int count(java.lang.String strToken,
                       int iStartIndex)
Return the number of occurences of the token in the contained string, starting the search from iStartIndex.
Parameters:
strToken - The token
iStartIndex - The beginning index
Returns:
The number of occurences of strToken
Since:
0.7

getOccurences

public final java.util.Vector getOccurences(java.lang.String strToken)
Return the occurences of strToken in the contained string. If no occurence is found, null is returned. The occurences are stored as Integer wrappers. Too bad for the perfs but that's the only way.
Parameters:
strToken - The token string
Returns:
The occurences Vector, or null if none
Since:
0.7

getOccurences

public final java.util.Vector getOccurences(java.lang.String strToken,
                                            int iStart)
Return the occurences of strToken located after iStart in the contained string. If no occurence is found, null is returned. The occurences are stored as Integer wrappers. Too bad for the perfs but that's the only way.
Parameters:
strToken - The token string
iStart - The starting index in the contained string
Returns:
The occurences Vector, or null if none
Since:
0.7