public class StrReplacer
extends java.lang.Object
Provides the ability to generate large string with the possibility of using substitutional parameters. Substitutional parameters are defined within the string in curly brackets, for example: {PARAMETER_NAME}.
The parameters are substituted with their values at the time of reading the resulting string.
Reading the resulting string is executed with method call toString().
Parameters values are defined with the method prm(String, String).
| Constructor and Description |
|---|
StrReplacer()
Constructs a string replacer with no characters in it and an initial capacity of 16 characters.
|
StrReplacer(int capacity)
Constructs a string replacer with no characters in it and an initial capacity specified by the
capacity argument. |
| Modifier and Type | Method and Description |
|---|---|
StrReplacer |
add(char c)
Appends a character as a character
|
StrReplacer |
add(char[] str)
The same as
add(char[], int, int), but takes the array entirely |
StrReplacer |
add(char[] str,
int offset,
int len)
Appends the string representation of a subarray of the
char array argument to this
sequence. |
StrReplacer |
add(java.lang.CharSequence s)
Appends third-party string entirely
|
StrReplacer |
add(java.lang.CharSequence s,
int start,
int end)
Appends a part of third-party string
|
StrReplacer |
add(int i)
Appends an integer, converting it to a string in the same manner as the method does
String.valueOf(int) |
StrReplacer |
add(java.lang.Integer i)
Appends an integer, converting it to a string in the same manner as the method does
String.valueOf(int) |
StrReplacer |
add(long l)
Appends an integer, converting it to a string in the same manner as the method does
String.valueOf(long) |
StrReplacer |
add(java.lang.Long l)
Appends an integer, converting it to a string in the same manner as the method does
String.valueOf(long) |
StrReplacer |
add(java.lang.StringBuffer sb) |
StrReplacer |
add(java.lang.StringBuilder sb) |
StrReplacer |
add(StrReplacer sr) |
void |
appendResultTo(java.lang.StringBuilder target)
Appends resulting text into specified
StringBuilder |
void |
decLen(int decValue)
Decreases the length of the text by the specified number of characters.
|
java.lang.StringBuilder |
generateResultStringBuilder()
Generates resulting
StringBuilder, where instead of the parameters their values are |
int |
getLen()
Get the lenght (number of characters) of current generated text (without substitution of values
of parameters)
|
StrReplacer |
prm(java.lang.String key,
java.lang.String value)
Sets the value of the parameter
|
void |
setLen(int newLen)
Sets the length of the character sequence.
|
java.lang.String |
toString()
Generates the resulting string, where instead of the parameters their values are
|
static StrReplacer |
wrap(java.lang.CharSequence charSequence)
Wraps a string replacer that contains the same characters as the specified
CharSequence. |
public StrReplacer()
public StrReplacer(int capacity)
capacity argument.capacity - the initial capacity.java.lang.NegativeArraySizeException - if the capacity argument is less than 0.public static StrReplacer wrap(java.lang.CharSequence charSequence)
CharSequence. The initial capacity of the string builder is 16 plus
the length of the CharSequence argument.charSequence - the sequence to copy.java.lang.NullPointerException - if charSequence is nullpublic StrReplacer add(java.lang.CharSequence s)
s - third-party string to be appendedthispublic StrReplacer add(java.lang.CharSequence s, int start, int end)
s - third-party stringstart - start of part to be appended in third-party stringend - end of part to be appended in third-party stringthispublic StrReplacer add(int i)
String.valueOf(int)i - number to be appendedthispublic StrReplacer add(char c)
c - a character to be appendedthispublic StrReplacer add(char[] str, int offset, int len)
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[], int, int), and the characters of that string were then
appended to this character sequence.
str - the characters to be appended.offset - the index of the first char to append.len - the number of chars to append.java.lang.IndexOutOfBoundsException - if offset < 0 or len < 0 or offset+len > str.lengthpublic StrReplacer add(char[] str)
add(char[], int, int), but takes the array entirelystr - array to be appended entirelythispublic StrReplacer add(java.lang.Integer i)
String.valueOf(int)i - number to be appendedthispublic StrReplacer add(long l)
String.valueOf(long)l - number to be appendedthispublic StrReplacer add(java.lang.Long l)
String.valueOf(long)l - number to be appendedthispublic StrReplacer add(java.lang.StringBuilder sb)
public StrReplacer add(java.lang.StringBuffer sb)
public StrReplacer add(StrReplacer sr)
public StrReplacer prm(java.lang.String key, java.lang.String value)
key - parameter keyvalue - parameter valuethispublic java.lang.StringBuilder generateResultStringBuilder()
StringBuilder, where instead of the parameters their values arepublic void appendResultTo(java.lang.StringBuilder target)
StringBuildertarget - a place where result is appendedpublic java.lang.String toString()
toString in class java.lang.Objectpublic int getLen()
public void setLen(int newLen)
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.
newLen - the new lengthjava.lang.IndexOutOfBoundsException - if the newLength argument is negative.public void decLen(int decValue)
decValue - size by which the text is decreased