com.ibm.redback.redbeans
Class RbString

java.lang.Object
  |
  +--com.ibm.redback.redbeans.RbString
Direct Known Subclasses:
RedField

public class RbString
extends java.lang.Object


Constructor Summary
RbString()
          Construct a new RbString with no characters.
RbString(java.lang.String sval)
          Construct a new RbString object, setting its initial value to that of the passed string.
 
Method Summary
 boolean alpha()
          Function to determine if the string value for this instance of a RbString object represents an 'alpha' string of characters.
static boolean alpha(java.lang.String sval)
          Function to determine if the passed string value is an 'alpha' string of characters.
 int col1()
          Return the column position of the first character less one, of the substring returned by the most recent field method invoked for this object instance.
 int col2()
          Return the column position of the last character plus one, of the substring returned by the most recent field method invoked for this object instance.
 void convert(java.lang.String oldStr, java.lang.String newStr)
          Convert 1 or more characters to other characters in the string value for this object instance.
static java.lang.String convert(java.lang.String sval, java.lang.String oldStr, java.lang.String newStr)
          Convert 1 or more characters to other characters in a string.
 int count(char pval)
          Return the number of times 1 character appears in this instance of a RbString object.
 int count(java.lang.String pval)
          Return the number of times 1 string appears in this instance of a RbString object.
static int count(java.lang.String sval, char pval)
          Return the number of times 1 character appears in a specified string.
static int count(java.lang.String sval, java.lang.String pval)
          Return the number of times 1 string appears in another specified string.
protected static int countStr(java.lang.String sval, java.lang.String pval, boolean dcount)
          Protected method used by the count method in this class, and the dcount method of RbDynString in this package.
 java.lang.String field(char dval, int occur)
          Return a substring of the string value for this instance of a RbString object, using a specified delimiter character, and an occurrence value for that delimiter.
static java.lang.String field(java.lang.String sval, char dval, int occur)
          Return a substring of the passed string value, using a specified delimiter character, and an occurrence value for that delimiter.
 java.lang.String field(java.lang.String dval, int occur)
          Return a substring of the string value for this instance of a RbString object, using a specified delimiter string, and an occurrence value for that delimiter.
static java.lang.String field(java.lang.String sval, java.lang.String dval, int occur)
          Return a substring of the passed string value, using a specified delimiter string, and an occurrence value for that delimiter.
 void fold(int length, char delim)
          Divide the string represented by this RbString object into a number of substrings separated by a specified delimiter character.
static java.lang.String fold(java.lang.String sval, int length, char delim)
          Fold is used to divide a string into a number of substrings separated by a specified delimiter character.
 int length()
          Return the length of the string value of this RbString in characters.
 boolean matches(java.lang.String pval)
          Test the current string value of this RbString object for a match on the specified pattern string.
static boolean matches(java.lang.String sval, java.lang.String pval)
          Test a passed string for a match on a 'pattern' defined by a second string.
 boolean num()
          Function to determine if the string value for this instance of a RbString object represents a numeric value.
static boolean num(java.lang.String sval)
          Function to determine if the passed string value represents a numeric value.
 void string(java.lang.String sval)
          Reset the RbString value to that of the passed string.
 void swap(java.lang.String oldStr, java.lang.String newStr)
          Swap (substitute) 1 string for another in a the current string value for this RbString object instance.
static java.lang.String swap(java.lang.String sval, java.lang.String oldStr, java.lang.String newStr)
          Swap (substitute) 1 string for another in a specified target string.
 java.lang.String toString()
          Return the string value of this RbString object.
 void trim(char dval)
          Function to 'trim' the string value for this instance of a RbString object.
 void trim(char dval, char mode)
          Function to 'trim' the string value for this instance of a RbString object.
static java.lang.String trim(java.lang.String sval, char dval)
          Function to 'trim' the passed string value.
static java.lang.String trim(java.lang.String sval, char dval, char mode)
          Function to 'trim' the passed string value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RbString

public RbString()
Construct a new RbString with no characters.

RbString

public RbString(java.lang.String sval)
Construct a new RbString object, setting its initial value to that of the passed string.
Parameters:
sval - a String
Method Detail

toString

public java.lang.String toString()
Return the string value of this RbString object.
Overrides:
toString in class java.lang.Object
Returns:
string a String

length

public int length()
Return the length of the string value of this RbString in characters.
Returns:
an int - Number of chars in string.

string

public void string(java.lang.String sval)
Reset the RbString value to that of the passed string.
Parameters:
sval - a String

count

public int count(java.lang.String pval)
Return the number of times 1 string appears in this instance of a RbString object. Provides functionality similar to the COUNT() function.
Parameters:
pval - a String that represents the value to be counted.
Returns:
an int that represents how many times pval was found in the string for this object.

count

public int count(char pval)
Return the number of times 1 character appears in this instance of a RbString object. Provides functionality similar to the COUNT() function.
Parameters:
pval - a char that represents the single character value to be counted.
Returns:
an int that represents how many times pval was found in the string for this object.

count

public static int count(java.lang.String sval,
                        java.lang.String pval)
Return the number of times 1 string appears in another specified string. Provides functionality similar to the COUNT() function.
Parameters:
sval - a String that represents the string in which occurrences of another string are to be counted.
pval - a String that represents the value to be counted.
Returns:
an int that represents how many times pval was found in the string sval.

count

public static int count(java.lang.String sval,
                        char pval)
Return the number of times 1 character appears in a specified string. Provides functionality similar to the COUNT() function.
Parameters:
sval - a String that represents the string in which occurrences of another string are to be counted.
pval - a char that represents the character value to be counted.
Returns:
an int that represents how many times pval was found in the string sval.

countStr

protected static int countStr(java.lang.String sval,
                              java.lang.String pval,
                              boolean dcount)
Protected method used by the count method in this class, and the dcount method of RbDynString in this package. This logic does the actual counting of values within a string.
Parameters:
sval - a String that represents the string in which values are to be counted.
pval - a String that represents the value to count.
dcount - a boolean flag to determines if the count action is to emulate a DOCUNT() (flag set 'true') or COUNT() (flag set false) function.
Returns:
an int that represents result of the count operation.

swap

public void swap(java.lang.String oldStr,
                 java.lang.String newStr)
Swap (substitute) 1 string for another in a the current string value for this RbString object instance.
Parameters:
oldStr - a String - represents the string that is to be swapped out. Ie: The 'old' value.
newStr - a String - represents the string that will replace oldStr in the target value. Ie: The 'new' string.

swap

public static java.lang.String swap(java.lang.String sval,
                                    java.lang.String oldStr,
                                    java.lang.String newStr)
Swap (substitute) 1 string for another in a specified target string.
Parameters:
sval - a String that represents the target string for the swap operation.
oldStr - a String - represents the string that is to be swapped out. Ie: The 'old' value.
newStr - a String - represents the string that will replace oldStr in the target value. Ie: The 'new' string.
Returns:
a String that represents the target string after the swap operation.

matches

public boolean matches(java.lang.String pval)
Test the current string value of this RbString object for a match on the specified pattern string. Provides functionality similar to the MATCHES operator.
Parameters:
pval - a String that defines the 'pattern' that is to be used to 'match' the current string value of this RbString. This pattern string can be made up of a number of elements. These are:
      nN - 'n' numeric digits, 0 indicates
           any number of numeric digits will
           be accepted. eg: 3N = 3 numeric
           digits are expected.
      nA - similar to above, but the test is
           on alpha chars. ie: A-Z and a-z
           nX - 'n' number of _any_ characters.
       # - 'wildcard' - same as '1A'
  'xxx' or "xxx" - match on literal text in quotes.
   other - expect exact match (like above)
Returns:
a boolean flag. True if match successful.

matches

public static boolean matches(java.lang.String sval,
                              java.lang.String pval)
Test a passed string for a match on a 'pattern' defined by a second string. Provides functionality similar to the MATCHES operator.
Parameters:
sval - a String that represents the target string for the match operation.
pval - a String that defines the 'pattern' that is to be used to 'match' the current string value of this RbString. This pattern string can be made up of a number of elements. These are:
      nN - 'n' numeric digits, 0 indicates
           any number of numeric digits will
           be accepted. eg: 3N = 3 numeric
           digits are expected.
      nA - similar to above, but the test is
           on alpha chars. ie: A-Z and a-z
           nX - 'n' number of _any_ characters.
       # - 'wildcard' - same as '1A'
  'xxx' or "xxx" - match on literal text in quotes.
   other - expect exact match (like above)
Returns:
a boolean flag. True if match successful.

convert

public void convert(java.lang.String oldStr,
                    java.lang.String newStr)
Convert 1 or more characters to other characters in the string value for this object instance. Provides CONVERT functionality
Parameters:
oldStr - a String - represents the character (or characters) to be replaced in the sval string.
newStr - a String - represents the character(s) that will replace the corresponding characters in oldStr in string sval.

convert

public static java.lang.String convert(java.lang.String sval,
                                       java.lang.String oldStr,
                                       java.lang.String newStr)
Convert 1 or more characters to other characters in a string. Provides CONVERT functionality.
Parameters:
sval - a String that represents the target string for the swap operation.
oldStr - a String - represents the character (or characters) to be replaced in the sval string.
newStr - a String - represents the character(s) that will replace the corresponding characters in oldStr in string sval.
Returns:
a String that represents the target string after the replacement operation.

num

public boolean num()
Function to determine if the string value for this instance of a RbString object represents a numeric value.
Returns:
a boolean value set to true if the string is numeric, or false if it is not.

num

public static boolean num(java.lang.String sval)
Function to determine if the passed string value represents a numeric value.
Returns:
a boolean value set to true if the string is numeric, or false if it is not.

alpha

public boolean alpha()
Function to determine if the string value for this instance of a RbString object represents an 'alpha' string of characters. This is only true if all characters fall in the range 'A - Z' or 'a - z'.
Returns:
a boolean value set to true if the string is alphabetic, or false if it is not.

alpha

public static boolean alpha(java.lang.String sval)
Function to determine if the passed string value is an 'alpha' string of characters. This is only true if all characters fall in the range 'A - Z' or 'a - z'.
Returns:
a boolean value set to true if the string is alphabetic, or false if it is not.

trim

public void trim(char dval)
Function to 'trim' the string value for this instance of a RbString object. The string value will be stripped of leading, trailing and extraneous occurrences of the specified character. Extraneous occurrences are deemed to be repetitions of that character. This will be replaced will a single occurrence of that character. For example:
   RbString foo = new RbString("@this@@is@@@text@@");
   foo.trim('@');
will set the string value for object foo to be:
   'this@is@text'
Parameters:
dval - a char value that represents the character to be 'trimmed' from the object string.

trim

public void trim(char dval,
                 char mode)
Function to 'trim' the string value for this instance of a RbString object. The string value will be trimmed according to a defined mode value.
Parameters:
dval - a char value that represents the character to be 'trimmed' from the object string.
mode - a char value that indicates the type of trim operation required. Valid values are:
          A - remove ALL occurrences of dval from string.
          L - strip leading occurrences of dval
          T - strip trailing occurrences of dval
          R - remove leading, trailing and extraneous
              occurrences of dval. Extraneous occurrences
              are deemed to be repetitions of dval.

trim

public static java.lang.String trim(java.lang.String sval,
                                    char dval)
Function to 'trim' the passed string value. The string will be stripped of leading, trailing and extraneous occurrences of the specified character. Extraneous occurrences are deemed to be repetitions of that character. These will be replaced will a single occurrence of that character. For example:
   String foo = RbString.trim("@this@@is@@@text@@", '@');
will set the string value for object foo to be:
   'this@is@text'
Parameters:
sval - a String value that represents the target string for the trim operation.
dval - a char value that represents the character to be 'trimmed' from the string.
Returns:
a String that is the result of the trim operation.

trim

public static java.lang.String trim(java.lang.String sval,
                                    char dval,
                                    char mode)
Function to 'trim' the passed string value. The string will be trimmed according to a defined mode value.
Parameters:
sval - a String value that represents the target string for the trim operation.
dval - a char value that represents the character to be 'trimmed' from the string.
mode - a char value that indicates the type of trim operation required. Valid values are:
          A - remove ALL occurrences of dval from string.
          L - strip leading occurrences of dval
          T - strip trailing occurrences of dval
          R - remove leading, trailing and extraneous
              occurrences of dval. Extraneous occurrences
              are deemed to be repetitions of dval.
Returns:
a String that is the result of the trim operation.

field

public static java.lang.String field(java.lang.String sval,
                                     char dval,
                                     int occur)
Return a substring of the passed string value, using a specified delimiter character, and an occurrence value for that delimiter. Provides functionality that emulates the FIELD function. For example:
   x = RbString.field("xxx.yyy.zzz", '.', 2)
   x now contains "yyy"
Parameters:
sval - a String that represents the string value to return a substring from.
dval - a char the delimiter character.
occur - an int specifies the occurrence of the substring to be returned. For example: if set to 3, then substring delimited by the second and third occurrence of the delimiter character will be returned.
Returns:
a String that represents the substring extracted from sval.

field

public static java.lang.String field(java.lang.String sval,
                                     java.lang.String dval,
                                     int occur)
Return a substring of the passed string value, using a specified delimiter string, and an occurrence value for that delimiter. Provides functionality that emulates the FIELD function. For example:
   x = RbString.field("xxxQQyyyQQzzz", "QQ", 2)
   x now contains "yyy"
Parameters:
sval - a String that represents the string value to return a substring from.
dval - a String - the delimiter.
occur - an int specifies the occurrence of the substring to be returned. For example: if set to 3, then substring delimited by the second and third occurrence of the delimiter character will be returned.
Returns:
a String that represents the substring extracted from sval.

field

public java.lang.String field(char dval,
                              int occur)
Return a substring of the string value for this instance of a RbString object, using a specified delimiter character, and an occurrence value for that delimiter. Provides functionality that emulates the FIELD function. For example:
   x = RbString.field("xxx.yyy.zzz", '.', 2)
   x now contains "yyy"
This method also sets 2 object instance variables for subsequent interrogation. These may be accessed by the col1() and col2() methods, and represent:
   col1() - returns an int that defines the
            start position less 1 of the substring.
   col2() - returns an int that defines the
            end position plus 1 of the substring.
Parameters:
dval - a char the delimiter character.
occur - an int specifies the occurrence of the substring to be returned. For example: if set to 3, then substring delimited by the second and third occurrence of the delimiter character will be returned.
Returns:
a String that represents the substring extracted from sval.

field

public java.lang.String field(java.lang.String dval,
                              int occur)
Return a substring of the string value for this instance of a RbString object, using a specified delimiter string, and an occurrence value for that delimiter. Provides functionality that emulates the FIELD function. For example:
   x = RbString.field("xxxQQyyyQQzzz", "QQ", 2)
   x now contains "yyy"
This method also sets 2 object instance variables for subsequent interrogation. These may be accessed by the col1() and col2() methods, and represent:
   col1() - returns an int that defines the
            start position less 1 of the substring.
   col2() - returns an int that defines the
            end position plus 1 of the substring.
Parameters:
dval - a String - the delimiter.
occur - an int specifies the occurrence of the substring to be returned. For example: if set to 3, then substring delimited by the second and third occurrence of the delimiter character will be returned.
Returns:
a String that represents the substring extracted from sval.

col1

public int col1()
Return the column position of the first character less one, of the substring returned by the most recent field method invoked for this object instance.
Returns:
an int the start less one, of the substring returned by the last field method.

col2

public int col2()
Return the column position of the last character plus one, of the substring returned by the most recent field method invoked for this object instance.
Returns:
an int the end, plus one, of the substring returned by the last field method. If this method returns -1, then the most recent field method returned a null string.

fold

public void fold(int length,
                 char delim)
Divide the string represented by this RbString object into a number of substrings separated by a specified delimiter character. The string is separated into substrings of a length less than or equal to a specified length value. The string is separated on blanks if possible, otherwise into substrings of the specified length. Note that if separated on a space character, the space will be replaced by the delimiter.
Parameters:
length - a int that represents the maximum character length of each substring.
delim - a char that represents the delimiter character to insert between substrings.

fold

public static java.lang.String fold(java.lang.String sval,
                                    int length,
                                    char delim)
Fold is used to divide a string into a number of substrings separated by a specified delimiter character. The string is separated into substrings of a length less than or equal to a specified length value. The string is separated on blanks if possible, otherwise into substrings of the specified length. Note that if separated on a space character, the space will be replaced by the delimiter.
Parameters:
sval - a String that represents the string on which the fold operation will be performed.
length - a int that represents the maximum character length of each substring.
delim - a char that represents the delimiter character to insert between substrings.
Returns:
a String that represents the 'folded' string result.