Class StrReplacer
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 Summary
ConstructorsConstructorDescriptionConstructs 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 thecapacityargument. -
Method Summary
Modifier and TypeMethodDescriptionadd(char c) Appends a character as a characteradd(char[] str) The same asadd(char[], int, int), but takes the array entirelyadd(char[] str, int offset, int len) Appends the string representation of a subarray of thechararray argument to this sequence.add(int i) Appends an integer, converting it to a string in the same manner as the method doesString.valueOf(int)add(long l) Appends an integer, converting it to a string in the same manner as the method doesString.valueOf(long)add(CharSequence s) Appends third-party string entirelyadd(CharSequence s, int start, int end) Appends a part of third-party stringAppends an integer, converting it to a string in the same manner as the method doesString.valueOf(int)Appends an integer, converting it to a string in the same manner as the method doesString.valueOf(long)add(StringBuffer sb) add(StringBuilder sb) add(StrReplacer sr) voidappendResultTo(StringBuilder target) Appends resulting text into specifiedStringBuildervoiddecLen(int decValue) Decreases the length of the text by the specified number of characters.Generates resultingStringBuilder, where instead of the parameters their values areintgetLen()Get the lenght (number of characters) of current generated text (without substitution of values of parameters)Sets the value of the parametervoidsetLen(int newLen) Sets the length of the character sequence.toString()Generates the resulting string, where instead of the parameters their values arestatic StrReplacerwrap(CharSequence charSequence) Wraps a string replacer that contains the same characters as the specifiedCharSequence.
-
Constructor Details
-
StrReplacer
public StrReplacer()Constructs a string replacer with no characters in it and an initial capacity of 16 characters. -
StrReplacer
public StrReplacer(int capacity) Constructs a string replacer with no characters in it and an initial capacity specified by thecapacityargument.- Parameters:
capacity- the initial capacity.- Throws:
NegativeArraySizeException- if thecapacityargument is less than0.
-
-
Method Details
-
wrap
Wraps a string replacer that contains the same characters as the specifiedCharSequence. The initial capacity of the string builder is16plus the length of theCharSequenceargument.- Parameters:
charSequence- the sequence to copy.- Throws:
NullPointerException- ifcharSequenceisnull
-
add
Appends third-party string entirely- Parameters:
s- third-party string to be appended- Returns:
this
-
add
Appends a part of third-party string- Parameters:
s- third-party stringstart- start of part to be appended in third-party stringend- end of part to be appended in third-party string- Returns:
this
-
add
Appends an integer, converting it to a string in the same manner as the method doesString.valueOf(int)- Parameters:
i- number to be appended- Returns:
this
-
add
Appends a character as a character- Parameters:
c- a character to be appended- Returns:
this
-
add
Appends the string representation of a subarray of thechararray argument to this sequence.Characters of the
chararraystr, starting at indexoffset, are appended, in order, to the contents of this sequence. The length of this sequence increases by the value oflen.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 thenappendedto this character sequence.- Parameters:
str- the characters to be appended.offset- the index of the firstcharto append.len- the number ofchars to append.- Returns:
- a reference to this object.
- Throws:
IndexOutOfBoundsException- ifoffset < 0orlen < 0oroffset+len > str.length
-
add
The same asadd(char[], int, int), but takes the array entirely- Parameters:
str- array to be appended entirely- Returns:
this
-
add
Appends an integer, converting it to a string in the same manner as the method doesString.valueOf(int)- Parameters:
i- number to be appended- Returns:
this
-
add
Appends an integer, converting it to a string in the same manner as the method doesString.valueOf(long)- Parameters:
l- number to be appended- Returns:
this
-
add
Appends an integer, converting it to a string in the same manner as the method doesString.valueOf(long)- Parameters:
l- number to be appended- Returns:
this
-
add
-
add
-
add
-
prm
Sets the value of the parameter- Parameters:
key- parameter keyvalue- parameter value- Returns:
this
-
generateResultStringBuilder
Generates resultingStringBuilder, where instead of the parameters their values are -
appendResultTo
Appends resulting text into specifiedStringBuilder- Parameters:
target- a place where result is appended
-
toString
Generates the resulting string, where instead of the parameters their values are -
getLen
public int getLen()Get the lenght (number of characters) of current generated text (without substitution of values of parameters)- Returns:
- the lenght of current text
-
setLen
public void setLen(int newLen) 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 thannewLength, 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
newLengthargument is less than the current length, the length is changed to the specified length.If the
newLengthargument is greater than or equal to the current length, sufficient null characters ('\u0000') are appended so that length becomes thenewLengthargument.The
newLengthargument must be greater than or equal to0.- Parameters:
newLen- the new length- Throws:
IndexOutOfBoundsException- if thenewLengthargument is negative.
-
decLen
public void decLen(int decValue) Decreases the length of the text by the specified number of characters. If resulting size is less than 0, no error occur, just the whole text is cleared- Parameters:
decValue- size by which the text is decreased
-