| java.lang.Object org.wings.util.SStringBuilder
SStringBuilder | final public class SStringBuilder implements java.io.Serializable,CharSequence(Code) | | A mutable sequence of characters. This class provides an API compatible
with StringBuffer , but with no guarantee of synchronization.
This class is designed for use as a drop-in replacement for
StringBuffer in places where the string buffer was being
used by a single thread (as is generally the case). Where possible,
it is recommended that this class be used in preference to
StringBuffer as it will be faster under most implementations.
The principal operations on a StringBuilder are the
append and insert methods, which are
overloaded so as to accept data of any type. Each effectively
converts a given datum to a string and then appends or inserts the
characters of that string to the string builder. The
append method always adds these characters at the end
of the builder; the insert method adds the characters at
a specified point.
For example, if z refers to a string builder object
whose current contents are "start ", then
the method call z.append("le") would cause the string
builder to contain "startle ", whereas
z.insert(4, "le") would alter the string builder to
contain "starlet ".
In general, if sb refers to an instance of a StringBuilder ,
then sb.append(x) has the same effect as
sb.insert(sb.length(), x) .
Every string builder has a capacity. As long as the length of the
character sequence contained in the string builder does not exceed
the capacity, it is not necessary to allocate a new internal
buffer. If the internal buffer overflows, it is automatically made larger.
Instances of StringBuilder are not safe for
use by multiple threads. If such synchronization is required then it is
recommended that
java.lang.StringBuffer be used.
author: Michael McCloskey version: 1.9, 07/16/04 See Also: java.lang.StringBuffer See Also: java.lang.String since: 1.5 |
Field Summary | |
int | count The count is the number of characters used. | final static long | serialVersionUID | final static int[] | sizeTable | char | value The value is used for character storage. |
Constructor Summary | |
public | SStringBuilder() Constructs a string builder with no characters in it and an
initial capacity of 16 characters. | public | SStringBuilder(int capacity) Constructs a string builder with no characters in it and an
initial capacity specified by the capacity argument. | public | SStringBuilder(String str) Constructs a string builder initialized to the contents of the
specified string. | public | SStringBuilder(CharSequence seq) Constructs a string builder that contains the same characters
as the specified CharSequence . |
Method Summary | |
public SStringBuilder | append(Object obj) Appends the string representation of the Object
argument.
The argument is converted to a string as if by the method
String.valueOf , and the characters of that
string are then appended to this sequence.
Parameters: obj - an Object . | public SStringBuilder | append(String str) Appends the specified string to this character sequence.
The characters of the String argument are appended, in
order, increasing the length of this sequence by the length of the
argument. | public SStringBuilder | append(StringBuffer sb) | public SStringBuilder | append(CharSequence s, int start, int end) Appends a subsequence of the specified CharSequence to this
sequence.
Characters of the argument s , starting at
index start , are appended, in order, to the contents of
this sequence up to the (exclusive) index end . | public SStringBuilder | append(char str) Appends the string representation of the char array
argument to this sequence. | public SStringBuilder | append(char str, int offset, int len) Appends the string representation of a subarray of the
char array argument to this sequence.
Characters of the char array str , starting at
index offset , are appended, in order, to the contents
of this sequence. | public SStringBuilder | append(boolean b) Appends the string representation of the boolean
argument to the sequence.
The argument is converted to a string as if by the method
String.valueOf , and the characters of that
string are then appended to this sequence. | public SStringBuilder | append(char c) Appends the string representation of the char
argument to this sequence. | public SStringBuilder | append(int i) Appends the string representation of the int
argument to this sequence. | public SStringBuilder | append(long l) Appends the string representation of the long
argument to this sequence.
The argument is converted to a string as if by the method
String.valueOf , and the characters of that
string are then appended to this sequence.
Parameters: l - a long . | public SStringBuilder | append(float f) Appends the string representation of the float
argument to this sequence.
The argument is converted to a string as if by the method
String.valueOf , and the characters of that
string are then appended to this string sequence.
Parameters: f - a float . | public SStringBuilder | append(double d) Appends the string representation of the double
argument to this sequence.
The argument is converted to a string as if by the method
String.valueOf , and the characters of that
string are then appended to this sequence.
Parameters: d - a double . | public SStringBuilder | append(CharSequence s) | public int | capacity() Returns the current capacity. | public char | charAt(int index) Returns the char value in this sequence at the specified index.
The first char value is at index 0 , the next at index
1 , and so on, as in array indexing.
The index argument must be greater than or equal to
0 , and less than the length of this sequence.
If the char value specified by the index is a
surrogate, the surrogate
value is returned.
Parameters: index - the index of the desired char value. | public SStringBuilder | delete(int start, int end) Removes the characters in a substring of this sequence.
The substring begins at the specified start and extends to
the character at index end - 1 or to the end of the
sequence if no such character exists. | public SStringBuilder | deleteCharAt(int index) Removes the char at the specified position in this
sequence. | public void | ensureCapacity(int minimumCapacity) Ensures that the capacity is at least equal to the specified minimum.
If the current capacity is less than the argument, then a new internal
array is allocated with greater capacity. | void | expandCapacity(int minimumCapacity) This implements the expansion semantics of ensureCapacity with no
size check or synchronization. | public void | getChars(int srcBegin, int srcEnd, char dst, int dstBegin) Characters are copied from this sequence into the
destination character array dst . | final char[] | getValue() Needed by String for the contentEquals method. | public SStringBuilder | insert(int offset, String str) Inserts the string into this character sequence.
The characters of the String argument are inserted, in
order, into this sequence at the indicated offset, moving up any
characters originally above that position and increasing the length
of this sequence by the length of the argument. | public int | length() Returns the length (character count). | public void | setCharAt(int index, char ch) The character at the specified index is set to ch . | public void | setLength(int newLength) Sets the length of the character sequence.
The sequence is changed to a new character sequence
whose length is specified by the argument. | static int | stringSizeOfInt(int x) | static int | stringSizeOfLong(long x) | public CharSequence | subSequence(int start, int end) Returns a new character sequence that is a subsequence of this sequence.
An invocation of this method of the form
sb.subSequence(begin, end)
behaves in exactly the same way as the invocation
sb.substring(begin, end)
This method is provided so that this class can
implement the
CharSequence interface. | public String | substring(int start) Returns a new String that contains a subsequence of
characters currently contained in this character sequence. | public String | substring(int start, int end) Returns a new String that contains a subsequence of
characters currently contained in this sequence. | public String | toString() | public void | trimToSize() Attempts to reduce storage used for the character sequence.
If the buffer is larger than necessary to hold its current sequence of
characters, then it may be resized to become more space efficient. |
count | int count(Code) | | The count is the number of characters used.
|
serialVersionUID | final static long serialVersionUID(Code) | | use serialVersionUID for interoperability
|
sizeTable | final static int[] sizeTable(Code) | | |
value | char value(Code) | | The value is used for character storage.
|
SStringBuilder | public SStringBuilder()(Code) | | Constructs a string builder with no characters in it and an
initial capacity of 16 characters.
|
SStringBuilder | public SStringBuilder(int capacity)(Code) | | Constructs a string builder with no characters in it and an
initial capacity specified by the capacity argument.
Parameters: capacity - the initial capacity. throws: NegativeArraySizeException - if the capacity argument is less than 0 . |
SStringBuilder | public SStringBuilder(String str)(Code) | | Constructs a string builder initialized to the contents of the
specified string. The initial capacity of the string builder is
16 plus the length of the string argument.
Parameters: str - the initial contents of the buffer. throws: NullPointerException - if str is null |
SStringBuilder | public SStringBuilder(CharSequence seq)(Code) | | Constructs a string builder that contains the same characters
as the specified CharSequence . The initial capacity of
the string builder is 16 plus the length of the
CharSequence argument.
Parameters: seq - the sequence to copy. throws: NullPointerException - if seq is null |
append | public SStringBuilder append(Object obj)(Code) | | Appends the string representation of the Object
argument.
The argument is converted to a string as if by the method
String.valueOf , and the characters of that
string are then appended to this sequence.
Parameters: obj - an Object . a reference to this object. |
append | public SStringBuilder append(String str)(Code) | | Appends the specified string to this character sequence.
The characters of the String argument are appended, in
order, increasing the length of this sequence by the length of the
argument. If str is null , then the four
characters "null" are appended.
Let n be the length of this character sequence just prior to
execution of the append method. Then the character at
index k in the new character sequence is equal to the character
at index k in the old character sequence, if k is less
than n; otherwise, it is equal to the character at index
k-n in the argument str .
Parameters: str - a string. a reference to this object. |
append | public SStringBuilder append(CharSequence s, int start, int end)(Code) | | Appends a subsequence of the specified CharSequence to this
sequence.
Characters of the argument s , starting at
index start , are appended, in order, to the contents of
this sequence up to the (exclusive) index end . The length
of this sequence is increased by the value of end - start .
Let n be the length of this character sequence just prior to
execution of the append method. Then the character at
index k in this character sequence becomes equal to the
character at index k in this sequence, if k is less than
n; otherwise, it is equal to the character at index
k+start-n in the argument s .
If s is null , then this method appends
characters as if the s parameter was a sequence containing the four
characters "null" .
Parameters: s - the sequence to append. Parameters: start - the starting index of the subsequence to be appended. Parameters: end - the end index of the subsequence to be appended. a reference to this object. throws: IndexOutOfBoundsException - ifstart or end are negative, orstart is greater than end orend is greater than s.length() |
append | public SStringBuilder append(char str)(Code) | | Appends the string representation of the char array
argument to this sequence.
The characters of the array argument are appended, in order, to
the contents of this sequence. The length of this sequence
increases by the length of the argument.
The overall effect is exactly as if the argument were converted to
a string by the method
String.valueOf(char[]) and the
characters of that string were then
SStringBuilder.append(String) appended
to this character sequence.
Parameters: str - the characters to be appended. a reference to this object. |
append | public SStringBuilder append(char str, int offset, int len)(Code) | | Appends the string representation of a subarray of the
char array argument to this sequence.
Characters of the char array str , starting at
index offset , are appended, in order, to the contents
of this sequence. The length of this sequence increases
by the value of len .
The overall effect is exactly as if the arguments were converted to
a string by the method
String.valueOf(char[]intint) and the
characters of that string were then
SStringBuilder.append(String) appended to this character sequence.
Parameters: str - the characters to be appended. Parameters: offset - the index of the first char to append. Parameters: len - the number of char s to append. a reference to this object. |
append | public SStringBuilder append(boolean b)(Code) | | Appends the string representation of the boolean
argument to the sequence.
The argument is converted to a string as if by the method
String.valueOf , and the characters of that
string are then appended to this sequence.
Parameters: b - a boolean . a reference to this object. |
append | public SStringBuilder append(char c)(Code) | | Appends the string representation of the char
argument to this sequence.
The argument is appended to the contents of this sequence.
The length of this sequence increases by 1 .
The overall effect is exactly as if the argument were converted to
a string by the method
String.valueOf(char) and the character
in that string were then
SStringBuilder.append(String) appended to this
character sequence.
Parameters: c - a char . a reference to this object. |
append | public SStringBuilder append(int i)(Code) | | Appends the string representation of the int
argument to this sequence.
The argument is converted to a string as if by the method
String.valueOf , and the characters of that
string are then appended to this sequence.
Parameters: i - an int . a reference to this object. |
append | public SStringBuilder append(long l)(Code) | | Appends the string representation of the long
argument to this sequence.
The argument is converted to a string as if by the method
String.valueOf , and the characters of that
string are then appended to this sequence.
Parameters: l - a long . a reference to this object. |
append | public SStringBuilder append(float f)(Code) | | Appends the string representation of the float
argument to this sequence.
The argument is converted to a string as if by the method
String.valueOf , and the characters of that
string are then appended to this string sequence.
Parameters: f - a float . a reference to this object. |
append | public SStringBuilder append(double d)(Code) | | Appends the string representation of the double
argument to this sequence.
The argument is converted to a string as if by the method
String.valueOf , and the characters of that
string are then appended to this sequence.
Parameters: d - a double . a reference to this object. |
capacity | public int capacity()(Code) | | Returns the current capacity. The capacity is the amount of storage
available for newly inserted characters, beyond which an allocation
will occur.
the current capacity |
charAt | public char charAt(int index)(Code) | | Returns the char value in this sequence at the specified index.
The first char value is at index 0 , the next at index
1 , and so on, as in array indexing.
The index argument must be greater than or equal to
0 , and less than the length of this sequence.
If the char value specified by the index is a
surrogate, the surrogate
value is returned.
Parameters: index - the index of the desired char value. the char value at the specified index. throws: IndexOutOfBoundsException - if index is negative or greater than or equal to length() . |
delete | public SStringBuilder delete(int start, int end)(Code) | | Removes the characters in a substring of this sequence.
The substring begins at the specified start and extends to
the character at index end - 1 or to the end of the
sequence if no such character exists. If
start is equal to end , no changes are made.
Parameters: start - The beginning index, inclusive. Parameters: end - The ending index, exclusive. This object. throws: StringIndexOutOfBoundsException - if start is negative, greater than length() , orgreater than end . |
deleteCharAt | public SStringBuilder deleteCharAt(int index)(Code) | | Removes the char at the specified position in this
sequence. This sequence is shortened by one char .
Note: If the character at the given index is a supplementary
character, this method does not remove the entire character. If
correct handling of supplementary characters is required,
determine the number of char s to remove by calling
Character.charCount(thisSequence.codePointAt(index)) ,
where thisSequence is this sequence.
Parameters: index - Index of char to remove This object. throws: StringIndexOutOfBoundsException - if the index is negative or greater than or equal tolength() . |
ensureCapacity | public void ensureCapacity(int minimumCapacity)(Code) | | Ensures that the capacity is at least equal to the specified minimum.
If the current capacity is less than the argument, then a new internal
array is allocated with greater capacity. The new capacity is the
larger of:
- The
minimumCapacity argument.
- Twice the old capacity, plus
2 .
If the minimumCapacity argument is nonpositive, this
method takes no action and simply returns.
Parameters: minimumCapacity - the minimum desired capacity. |
expandCapacity | void expandCapacity(int minimumCapacity)(Code) | | This implements the expansion semantics of ensureCapacity with no
size check or synchronization.
|
getChars | public void getChars(int srcBegin, int srcEnd, char dst, int dstBegin)(Code) | | Characters are copied from this sequence into the
destination character array dst . The first character to
be copied is at index srcBegin ; the last character to
be copied is at index srcEnd-1 . The total number of
characters to be copied is srcEnd-srcBegin . The
characters are copied into the subarray of dst starting
at index dstBegin and ending at index:
dstbegin + (srcEnd-srcBegin) - 1
Parameters: srcBegin - start copying at this offset. Parameters: srcEnd - stop copying at this offset. Parameters: dst - the array to copy the data into. Parameters: dstBegin - offset into dst . throws: NullPointerException - if dst is null . throws: IndexOutOfBoundsException - if any of the following is true:srcBegin is negativedstBegin is negative- the
srcBegin argument is greater than the srcEnd argument. srcEnd is greater than this.length() .dstBegin+srcEnd-srcBegin is greater than dst.length
|
getValue | final char[] getValue()(Code) | | Needed by String for the contentEquals method.
|
insert | public SStringBuilder insert(int offset, String str)(Code) | | Inserts the string into this character sequence.
The characters of the String argument are inserted, in
order, into this sequence at the indicated offset, moving up any
characters originally above that position and increasing the length
of this sequence by the length of the argument. If
str is null , then the four characters
"null" are inserted into this sequence.
The character at index k in the new character sequence is
equal to:
- the character at index k in the old character sequence, if
k is less than
offset
- the character at index k
-offset in the
argument str , if k is not less than
offset but is less than offset+str.length()
- the character at index k
-str.length() in the
old character sequence, if k is not less than
offset+str.length()
The offset argument must be greater than or equal to
0 , and less than or equal to the length of this
sequence.
Parameters: offset - the offset. Parameters: str - a string. a reference to this object. throws: StringIndexOutOfBoundsException - if the offset is invalid. |
length | public int length()(Code) | | Returns the length (character count).
the length of the sequence of characters currently represented by this object |
setCharAt | public void setCharAt(int index, char ch)(Code) | | The character at the specified index is set to ch . This
sequence is altered to represent a new character sequence that is
identical to the old character sequence, except that it contains the
character ch at position index .
The index argument must be greater than or equal to
0 , and less than the length of this sequence.
Parameters: index - the index of the character to modify. Parameters: ch - the new character. throws: IndexOutOfBoundsException - if index is negative or greater than or equal to length() . |
setLength | public void setLength(int newLength)(Code) | | Sets the length of the character sequence.
The sequence is changed to a new character sequence
whose length is specified by the argument. For every nonnegative
index k less than newLength , the character at
index k in the new character sequence is the same as the
character at index k in the old sequence if k is less
than the length of the old character sequence; otherwise, it is the
null character '\u0000' .
In other words, if the newLength argument is less than
the current length, the length is changed to the specified length.
If the newLength argument is greater than or equal
to the current length, sufficient null characters
('\u0000' ) are appended so that
length becomes the newLength argument.
The newLength argument must be greater than or equal
to 0 .
Parameters: newLength - the new length throws: IndexOutOfBoundsException - if thenewLength argument is negative. |
stringSizeOfInt | static int stringSizeOfInt(int x)(Code) | | |
stringSizeOfLong | static int stringSizeOfLong(long x)(Code) | | |
subSequence | public CharSequence subSequence(int start, int end)(Code) | | Returns a new character sequence that is a subsequence of this sequence.
An invocation of this method of the form
sb.subSequence(begin, end)
behaves in exactly the same way as the invocation
sb.substring(begin, end)
This method is provided so that this class can
implement the
CharSequence interface.
Parameters: start - the start index, inclusive. Parameters: end - the end index, exclusive. the specified subsequence. throws: IndexOutOfBoundsException - if start or end are negative,if end is greater than length(),or if start is greater than end |
substring | public String substring(int start)(Code) | | Returns a new String that contains a subsequence of
characters currently contained in this character sequence. The
substring begins at the specified index and extends to the end of
this sequence.
Parameters: start - The beginning index, inclusive. The new string. throws: StringIndexOutOfBoundsException - if start isless than zero, or greater than the length of this object. |
substring | public String substring(int start, int end)(Code) | | Returns a new String that contains a subsequence of
characters currently contained in this sequence. The
substring begins at the specified start and
extends to the character at index end - 1 .
Parameters: start - The beginning index, inclusive. Parameters: end - The ending index, exclusive. The new string. throws: StringIndexOutOfBoundsException - if start or end are negative or greater thanlength() , or start isgreater than end . |
trimToSize | public void trimToSize()(Code) | | Attempts to reduce storage used for the character sequence.
If the buffer is larger than necessary to hold its current sequence of
characters, then it may be resized to become more space efficient.
Calling this method may, but is not required to, affect the value
returned by a subsequent call to the
SStringBuilder.capacity() method.
|
|
|