xbn.string
Class StringOrBuffer

java.lang.Object
  |
  +--xbn.XBNObject
        |
        +--xbn.string.StringOrBuffer
Direct Known Subclasses:
SOBString, SOBStringBuffer

public abstract class StringOrBuffer
extends XBNObject

Base class of "wrappers" for Strings and StringBuffers, to prevent duplication of functions used by both.

Source code:  StringOrBuffer.java.  Unit tests:  xbn_junit.JUTStringOrBuffer.java.


Fields inherited from class xbn.XBNObject
bFALSE_IN_PRODUCTION, bTRUE_IN_PRODUCTION, sCNSTR, sES, sLINE_SEP
 
Constructor Summary
StringOrBuffer()
           
 
Method Summary
abstract  void append(char c_toAppend)
          Append a character onto the end (right).
abstract  void append(String s_toAppend)
          Append a string onto the end (right).
abstract  void appendToLeft(char c_toAppend)
          Append a character to the start.
abstract  void appendToLeft(String s_toAppend)
          Append a string to the start.
abstract  char charAt(int i_dx)
          Get the character located at the requested array index.
abstract  void delete(int i_idxLeft, int i_idxAfterRight)
          Delete a range of characters.
 void deleteAll()
          Delete all characters.
abstract  void deleteCharAt(int i_dx)
          Delete a character.
abstract  boolean endsWith(String s_toSearchFor)
          Is the search string found at the end of the StringOrBuffer?
abstract  String getTrimmed()
          Get the value of this StringOrBuffer, after trimming whitespace from the ends.
 int indexOf(char c_toSearchFor)
          Get the array index of the right-most occurance of the search string.
 int indexOf(char c_toSearchFor, int i_idxLeft)
          Get the array index of the right-most occurance of the search string.
 int indexOf(char c_toSearchFor, int i_idxLeft, int i_idxAfterRight)
          Get the array index of the right-most occurance of the search string.
 int indexOf(char c_toSearchFor, int i_idxLeft, int i_idxAfterRight, boolean b_bounded)
          Get the array index of the left-most occurance of the search string.
 int indexOf(String s_toSearchFor)
          Get the array index of the right-most occurance of the search string.
 int indexOf(String s_toSearchFor, int i_idxLeft)
          Get the array index of the right-most occurance of the search string.
 int indexOf(String s_toSearchFor, int i_idxLeft, int i_idxAfterRight)
          Get the array index of the right-most occurance of the search string.
 int indexOf(String s_toSearchFor, int i_idxLeft, int i_idxAfterRight, boolean b_bounded)
          Get the array index of the left-most occurance of the search string.
abstract  void insert(int i_dx, char c_toInsert)
          Insert a character.
abstract  void insert(int i_dx, String s_toInsert)
          Insert a string.
 boolean isEmpty()
          Are there zero characters in this StringOrBuffer?
abstract  boolean isString()
          Does this StringOrBuffer contain a String?
 boolean isStringAt(String s_toSearchFor, int i_dx)
          Is the search string found at the specific array index?
 boolean isStringBuffer()
          Does this StringOrBuffer contain a StringBuffer?
 int lastIndexOf(char c_toSearchFor)
          Get the array index of the right-most occurance of the search string.
 int lastIndexOf(char c_toSearchFor, int i_idxAfterRight)
          Get the array index of the right-most occurance of the search string.
 int lastIndexOf(char c_toSearchFor, int i_idxAfterRight, boolean b_bounded)
          Get the array index of the right-most occurance of the search string.
 int lastIndexOf(char c_toSearchFor, int i_idxLeft, int i_idxAfterRight)
          Get the array index of the right-most occurance of the search string.
 int lastIndexOf(char c_toSearchFor, int i_idxLeft, int i_idxAfterRight, boolean b_bounded)
          Get the array index of the right-most occurance of the search string.
 int lastIndexOf(String s_toSearchFor)
          Get the array index of the right-most occurance of the search string.
 int lastIndexOf(String s_toSearchFor, int i_idxAfterRight)
          Get the array index of the right-most occurance of the search string.
 int lastIndexOf(String s_toSearchFor, int i_idxAfterRight, boolean b_bounded)
          Get the array index of the right-most occurance of the search string.
 int lastIndexOf(String s_toSearchFor, int i_idxLeft, int i_idxAfterRight)
          Get the array index of the right-most occurance of the search string.
 int lastIndexOf(String s_toSearchFor, int i_idxLeft, int i_idxAfterRight, boolean b_bounded)
          Get the array index of the right-most occurance of the search string.
abstract  int length()
          How long is this StringOrBuffer?
abstract  void setLength(int i_newLength)
          Set the length.
abstract  boolean startsWith(String s_toSearchFor)
          Is the search string found at index 0?
abstract  String substring(int i_idxLeft)
          Get a range of characters starting at the requested index.
abstract  String substring(int i_idxLeft, int i_idxAfterRight)
          Get a range of characters.
abstract  void trim()
          Trim whitespace from the value of this StringOrBuffer.
 
Methods inherited from class xbn.XBNObject
getXMsgPrefix, sop, sopl, sopl, throwAX, throwAXIfBadStr, throwAXIfNull, throwAXSpoof
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringOrBuffer

public StringOrBuffer()
Method Detail

isString

public abstract boolean isString()

Does this StringOrBuffer contain a String?

Returns:
true If this StringOrBuffer contains a string.
false If it contains a StringBuffer.

isStringBuffer

public final boolean isStringBuffer()

Does this StringOrBuffer contain a StringBuffer?

Returns:
!isString()

length

public abstract int length()

How long is this StringOrBuffer?

Returns:
A number greater-than-or-equal-to zero, representing the number of characters.

isEmpty

public final boolean isEmpty()

Are there zero characters in this StringOrBuffer?

Returns:
(length() == 0)

startsWith

public abstract boolean startsWith(String s_toSearchFor)

Is the search string found at index 0?

Parameters:
s_toSearchFor - The string to search at index zero for. May not be null or zero characters in length.
Returns:
true If characters 0..[s_toSearchFor.length()] in the StringOrBuffer are equal to the corresponding characters in s_toSearchFor, with none missing.
false If not.

endsWith

public abstract boolean endsWith(String s_toSearchFor)

Is the search string found at the end of the StringOrBuffer?

Parameters:
s_toSearchFor - The string that should be searched for, at the end of the StringOrBuffer. May not be null or zero characters in length.
Returns:
true If every character starting at (length() - s_toSearchFor.length()) in the StringOrBuffer are equal to the corresponding characters in s_toSearchFor, with none missing.
false If not.

getTrimmed

public abstract String getTrimmed()

Get the value of this StringOrBuffer, after trimming whitespace from the ends. This does not alter the internally-held value.


trim

public abstract void trim()

Trim whitespace from the value of this StringOrBuffer. Unlike the java.lang.String version of this function, this does not return anything, but rather just trims the internally-held value. See getTrimmed().


charAt

public abstract char charAt(int i_dx)

Get the character located at the requested array index.

Parameters:
i_dx - The array index of the character you want. Must range 0..[length() - 1], inclusive.

append

public abstract void append(String s_toAppend)

Append a string onto the end (right).

Parameters:
s_toAppend - The string to append.

appendToLeft

public abstract void appendToLeft(String s_toAppend)

Append a string to the start.

Parameters:
s_toAppend - The string to append.

insert

public abstract void insert(int i_dx,
                            String s_toInsert)

Insert a string.

Parameters:
i_dx - The array index at which s_toInsert should be inserted. Must range 0..[length() - 1], inclusive.
s_toInsert - The string to insert.

append

public abstract void append(char c_toAppend)

Append a character onto the end (right).

Parameters:
s_toAppend - The character to insert.

appendToLeft

public abstract void appendToLeft(char c_toAppend)

Append a character to the start.

Parameters:
c_toAppend - The character to insert.

insert

public abstract void insert(int i_dx,
                            char c_toInsert)

Insert a character.

Parameters:
i_dx - The array index at which c_toInsert should be inserted. Must range 0..[length() - 1], inclusive.
c_toInsert - The character to insert.

deleteCharAt

public abstract void deleteCharAt(int i_dx)

Delete a character.

Parameters:
i_dx - The array index containing the character to delete. Must range 0..[length() - 1], inclusive.

delete

public abstract void delete(int i_idxLeft,
                            int i_idxAfterRight)

Delete a range of characters.

Parameters:
i_idxLeft - The array index of the left-most character to be deleted. Must range 0..[length() - 1], inclusive, and must be less than or equal to i_idxAfterRight.
i_idxAfterRight - The array index after the right-most to be retrieved. Must be between i_idxLeft and length, inclusive.

setLength

public abstract void setLength(int i_newLength)

Set the length.

Parameters:
i_newLength - The desired length. If less than length, then every character at and after (array index) i_newLength is deleted. If greater than length, then spaces are appended to the right hand side until the new length is achieved.

substring

public abstract String substring(int i_idxLeft)

Get a range of characters starting at the requested index.

This returns the same thing as substring(i_idxLeft, (length() - 1))

Parameters:
i_idxLeft - The array index of the left-most character to be retrieved. Must range 0..[length() - 1], inclusive, and must be less than or equal to i_idxAfterRight.

substring

public abstract String substring(int i_idxLeft,
                                 int i_idxAfterRight)

Get a range of characters.

See substring.

Parameters:
i_idxLeft - The array index of the left-most character to be retrieved. Must range 0..[length() - 1], inclusive, and must be less than or equal to i_idxAfterRight.
i_idxAfterRight - The array index after the right-most to be retrieved. Must be between i_idxLeft and length, inclusive.

deleteAll

public final void deleteAll()

Delete all characters.

Equal to setLength(0)


indexOf

public final int indexOf(String s_toSearchFor)

Get the array index of the right-most occurance of the search string.

Returns:
indexOf(s_toSearchFor, 0)

indexOf

public final int indexOf(String s_toSearchFor,
                         int i_idxLeft)

Get the array index of the right-most occurance of the search string.

Returns:
indexOf(s_toSearchFor, i_idxLeft, length())

indexOf

public final int indexOf(String s_toSearchFor,
                         int i_idxLeft,
                         int i_idxAfterRight)

Get the array index of the right-most occurance of the search string.

Returns:
indexOf(s_toSearchFor, i_idxLeft, i_idxAfterRight, true)

indexOf

public final int indexOf(String s_toSearchFor,
                         int i_idxLeft,
                         int i_idxAfterRight,
                         boolean b_bounded)

Get the array index of the left-most occurance of the search string.

Parameters:
s_toSearchFor - The string to search for.. May not be null or zero characters in length.
i_idxLeft - The array index of the left-most (first) character to search. Must be between 0 and (length() - 1), inclusive.
i_idxAfterRight - The array index of the first character after the end of the search area. Must be between i_idxLeft and length, inclusive.
b_bounded - If true, then the search string must be fully contained between i_idxLeft (inclusive) and i_idxAfterRight (exclusive). If false, the search string must start between i_idxLeft and i_idxAfterRight, but the search string may exceed i_idxAfterRight (as long as it exists fully in the string as a whole).
Returns:
A number between i_idxLeft and (i_idxAfterRight - 1) referring to the first character in the left-most occurance of the search string.
-1 If the search string is not found

Examples

Assume the value of this StringOrBuffer is "abcdef" and s_toSearchFor is "bcde"

i_idxLeft i_idxAfterRight b_bounded RETURNED INT
0 0 true -1
0 length() true 1
0 1 true -1
0 1 false 1
1 1 true -1
1 1 false 1
0 3 true -1
0 3 false 1
2 length() true -1
2 length() false -1


lastIndexOf

public final int lastIndexOf(String s_toSearchFor)

Get the array index of the right-most occurance of the search string.

Returns:
lastIndexOf(s_toSearchFor, length())

lastIndexOf

public final int lastIndexOf(String s_toSearchFor,
                             int i_idxAfterRight)

Get the array index of the right-most occurance of the search string.

Returns:
lastIndexOf(s_toSearchFor, i_idxAfterRight, true)

lastIndexOf

public final int lastIndexOf(String s_toSearchFor,
                             int i_idxAfterRight,
                             boolean b_bounded)

Get the array index of the right-most occurance of the search string.

Returns:
lastIndexOf(s_toSearchFor, 0, i_idxAfterRight, b_bounded)

lastIndexOf

public final int lastIndexOf(String s_toSearchFor,
                             int i_idxLeft,
                             int i_idxAfterRight)

Get the array index of the right-most occurance of the search string.

Returns:
lastIndexOf(s_toSearchFor, i_idxLeft, i_idxAfterRight, true)

lastIndexOf

public final int lastIndexOf(String s_toSearchFor,
                             int i_idxLeft,
                             int i_idxAfterRight,
                             boolean b_bounded)

Get the array index of the right-most occurance of the search string.

Parameters:
s_toSearchFor - The string to search for. May not be null or zero characters in length.
i_idxLeft - The array index of the left-most (first) character to search. Must be between 0 and (length() - 1), inclusive.
i_idxAfterRight - The array index of the first character after the end of the search area. Must be between i_idxLeft and length, inclusive.
b_bounded - If true, then the search string must be fully contained between i_idxLeft (inclusive) and i_idxAfterRight (exclusive). If false, the search string must start between i_idxLeft and i_idxAfterRight, but the search string may exceed i_idxAfterRight (as long as it exists fully in the string as a whole). Note: The default behavior of java.lang.String.lastIndexOf(s,i) is for the search to not be bounded (as if this were equal to false).
Returns:
A number between i_idxLeft and (i_idxAfterRight - 1) referring to the first character in the left-most occurance of the search string.
-1 If the search string does not exist completely between the search bounds.

Examples

Assume the value of this StringOrBuffer is "abcdef" and s_toSearchFor is "bcde"

i_idxLeft i_idxAfterRight b_bounded RETURNED INT
0 0 true -1
0 length() true 1
0 1 true -1
0 1 false 1
1 1 true -1
1 1 false 1
0 3 true -1
0 3 false 1
2 length() true -1
2 length() false -1


indexOf

public final int indexOf(char c_toSearchFor)

Get the array index of the right-most occurance of the search string.

Returns:
indexOf((new Character(c_toSearchFor)).toString())

indexOf

public final int indexOf(char c_toSearchFor,
                         int i_idxLeft)

Get the array index of the right-most occurance of the search string.

Returns:
indexOf((new Character(c_toSearchFor)).toString())

indexOf

public final int indexOf(char c_toSearchFor,
                         int i_idxLeft,
                         int i_idxAfterRight)

Get the array index of the right-most occurance of the search string.

Returns:
indexOf((new Character(c_toSearchFor)).toString(), i_idxLeft, i_idxAfterRight)

indexOf

public final int indexOf(char c_toSearchFor,
                         int i_idxLeft,
                         int i_idxAfterRight,
                         boolean b_bounded)

Get the array index of the left-most occurance of the search string.

Returns:
lastIndexOf((new Character(c_toSearchFor)).toString(), i_idxLeft, i_idxAfterRight)

lastIndexOf

public final int lastIndexOf(char c_toSearchFor)

Get the array index of the right-most occurance of the search string.

Returns:
lastIndexOf((new Character(c_toSearchFor)).toString())

lastIndexOf

public final int lastIndexOf(char c_toSearchFor,
                             int i_idxAfterRight)

Get the array index of the right-most occurance of the search string.

Returns:
lastIndexOf((new Character(c_toSearchFor)).toString(), i_idxAfterRight)

lastIndexOf

public final int lastIndexOf(char c_toSearchFor,
                             int i_idxAfterRight,
                             boolean b_bounded)

Get the array index of the right-most occurance of the search string.

Returns:
lastIndexOf((new Character(c_toSearchFor)).toString(), i_idxAfterRight, b_bounded)

lastIndexOf

public final int lastIndexOf(char c_toSearchFor,
                             int i_idxLeft,
                             int i_idxAfterRight)

Get the array index of the right-most occurance of the search string.

Returns:
lastIndexOf((new Character(c_toSearchFor)).toString(), i_idxLeft, i_idxAfterRight)

lastIndexOf

public final int lastIndexOf(char c_toSearchFor,
                             int i_idxLeft,
                             int i_idxAfterRight,
                             boolean b_bounded)

Get the array index of the right-most occurance of the search string.

Returns:
lastIndexOf((new Character(c_toSearchFor)).toString(), i_idxLeft, i_idxAfterRight)

isStringAt

public final boolean isStringAt(String s_toSearchFor,
                                int i_dx)

Is the search string found at the specific array index?

Parameters:
s_toSearchFor - What to search for. May not be null or zero characters in length.
i_dx - The array index at which s_toSearchFor should begin. Must be between zero and (length() - 1), inclusive.
Returns:
true If s_toSearchFor, as a whole, was found at i_dx
false If not.



Copyright 1997-2003, Jeff Epstein, All Rights Reserved. See top of source code files for copyright notice.

 

http://sourceforge.net/projects/xbnjava

 

SourceForge.net Logo