CPD Results
The following document contains the results of PMD's CPD 6.55.0.
Duplications
File |
Line |
org/apache/commons/text/StrTokenizer.java |
764 |
org/apache/commons/text/StringTokenizer.java |
786 |
private int readWithQuotes(final char[] srcChars, final int start, final int len, final StrBuilder workArea,
final List<String> tokenList, final int quoteStart, final int quoteLen) {
// Loop until we've found the end of the quoted
// string or the end of the input
workArea.clear();
int pos = start;
boolean quoting = quoteLen > 0;
int trimStart = 0;
while (pos < len) {
// quoting mode can occur several times throughout a string
// we must switch between quoting and non-quoting until we
// encounter a non-quoted delimiter, or end of string
if (quoting) {
// In quoting mode
// If we've found a quote character, see if it's
// followed by a second quote. If so, then we need
// to actually put the quote character into the token
// rather than end the token.
if (isQuote(srcChars, pos, len, quoteStart, quoteLen)) {
if (isQuote(srcChars, pos + quoteLen, len, quoteStart, quoteLen)) {
// matched pair of quotes, thus an escaped quote
workArea.append(srcChars, pos, quoteLen);
pos += quoteLen * 2;
trimStart = workArea.size();
continue;
}
// end of quoting
quoting = false;
pos += quoteLen;
continue;
}
} else {
// Not in quoting mode
// check for delimiter, and thus end of token
final int delimLen = getDelimiterMatcher().isMatch(srcChars, pos, start, len);
if (delimLen > 0) {
// return condition when end of token found
addToken(tokenList, workArea.substring(0, trimStart));
return pos + delimLen;
}
// check for quote, and thus back into quoting mode
if (quoteLen > 0 && isQuote(srcChars, pos, len, quoteStart, quoteLen)) {
quoting = true;
pos += quoteLen;
continue;
}
// check for ignored (outside quotes), and ignore
final int ignoredLen = getIgnoredMatcher().isMatch(srcChars, pos, start, len);
if (ignoredLen > 0) {
pos += ignoredLen;
continue;
}
// check for trimmed character
// don't yet know if its at the end, so copy to workArea
// use trimStart to keep track of trim at the end
final int trimmedLen = getTrimmerMatcher().isMatch(srcChars, pos, start, len);
if (trimmedLen > 0) {
workArea.append(srcChars, pos, trimmedLen);
pos += trimmedLen;
continue;
}
}
// copy regular character from inside quotes
workArea.append(srcChars[pos++]);
trimStart = workArea.size();
}
// return condition when end of string found
addToken(tokenList, workArea.substring(0, trimStart));
return -1;
}
/**
* Unsupported ListIterator operation.
*
* @throws UnsupportedOperationException always
*/
@Override
public void remove() {
throw new UnsupportedOperationException("remove() is unsupported");
}
/**
* Resets this tokenizer, forgetting all parsing and iteration already completed.
* <p>
* This method allows the same tokenizer to be reused for the same String.
*
* @return this, to enable chaining
*/
public StrTokenizer reset() { |
File |
Line |
org/apache/commons/text/StrBuilder.java |
2867 |
org/apache/commons/text/TextStringBuilder.java |
3033 |
public StrBuilder setNullText(String nullText) {
if (nullText != null && nullText.isEmpty()) {
nullText = null;
}
this.nullText = nullText;
return this;
}
/**
* Gets the length of the string builder.
* <p>
* This method is the same as {@link #length()} and is provided to match the
* API of Collections.
* </p>
*
* @return The length
*/
public int size() {
return size;
}
/**
* Checks whether this builder starts with the specified string.
* <p>
* Note that this method handles null input quietly, unlike String.
* </p>
*
* @param str the string to search for, null returns false
* @return true if the builder starts with the string
*/
public boolean startsWith(final String str) {
if (str == null) {
return false;
}
final int len = str.length();
if (len == 0) {
return true;
}
if (len > size) {
return false;
}
for (int i = 0; i < len; i++) {
if (buffer[i] != str.charAt(i)) {
return false;
}
}
return true;
}
/**
* {@inheritDoc}
*/
@Override
public CharSequence subSequence(final int startIndex, final int endIndex) {
if (startIndex < 0) {
throw new StringIndexOutOfBoundsException(startIndex);
}
if (endIndex > size) {
throw new StringIndexOutOfBoundsException(endIndex);
}
if (startIndex > endIndex) {
throw new StringIndexOutOfBoundsException(endIndex - startIndex);
}
return substring(startIndex, endIndex);
}
/**
* Extracts a portion of this string builder as a string.
*
* @param start the start index, inclusive, must be valid
* @return The new string
* @throws IndexOutOfBoundsException if the index is invalid
*/
public String substring(final int start) {
return substring(start, size);
}
/**
* Extracts a portion of this string builder as a string.
* <p>
* Note: This method treats an endIndex greater than the length of the
* builder as equal to the length of the builder, and continues
* without error, unlike StringBuffer or String.
*
* @param startIndex the start index, inclusive, must be valid
* @param endIndex the end index, exclusive, must be valid except
* that if too large it is treated as end of string
* @return The new string
* @throws IndexOutOfBoundsException if the index is invalid
*/
public String substring(final int startIndex, int endIndex) {
endIndex = validateRange(startIndex, endIndex);
return new String(buffer, startIndex, endIndex - startIndex);
}
/**
* Copies the builder's character array into a new character array.
*
* @return a new array that represents the contents of the builder
*/
public char[] toCharArray() {
return size == 0 ? ArrayUtils.EMPTY_CHAR_ARRAY : Arrays.copyOf(buffer, size);
}
/**
* Copies part of the builder's character array into a new character array.
*
* @param startIndex the start index, inclusive, must be valid
* @param endIndex the end index, exclusive, must be valid except that
* if too large it is treated as end of string
* @return a new array that holds part of the contents of the builder
* @throws IndexOutOfBoundsException if startIndex is invalid,
* or if endIndex is invalid (but endIndex greater than size is valid)
*/
public char[] toCharArray(final int startIndex, int endIndex) {
endIndex = validateRange(startIndex, endIndex);
final int len = endIndex - startIndex; |
File |
Line |
org/apache/commons/text/StrTokenizer.java |
556 |
org/apache/commons/text/StringTokenizer.java |
573 |
public StrMatcher getTrimmerMatcher() {
return trimmerMatcher;
}
/**
* Checks whether there are any more tokens.
*
* @return true if there are more tokens
*/
@Override
public boolean hasNext() {
checkTokenized();
return tokenPos < tokens.length;
}
/**
* Checks whether there are any previous tokens that can be iterated to.
*
* @return true if there are previous tokens
*/
@Override
public boolean hasPrevious() {
checkTokenized();
return tokenPos > 0;
}
/**
* Gets whether the tokenizer currently returns empty tokens as null.
* The default for this property is false.
*
* @return true if empty tokens are returned as null
*/
public boolean isEmptyTokenAsNull() {
return this.emptyAsNull;
}
/**
* Gets whether the tokenizer currently ignores empty tokens.
* The default for this property is true.
*
* @return true if empty tokens are not returned
*/
public boolean isIgnoreEmptyTokens() {
return ignoreEmptyTokens;
}
/**
* Checks if the characters at the index specified match the quote
* already matched in readNextToken().
*
* @param srcChars the character array being tokenized
* @param pos the position to check for a quote
* @param len the length of the character array being tokenized
* @param quoteStart the start position of the matched quote, 0 if no quoting
* @param quoteLen the length of the matched quote, 0 if no quoting
* @return true if a quote is matched
*/
private boolean isQuote(final char[] srcChars,
final int pos,
final int len,
final int quoteStart,
final int quoteLen) {
for (int i = 0; i < quoteLen; i++) {
if (pos + i >= len || srcChars[pos + i] != srcChars[quoteStart + i]) {
return false;
}
}
return true;
}
/**
* Gets the next token.
*
* @return The next String token
* @throws NoSuchElementException if there are no more elements
*/
@Override
public String next() {
if (hasNext()) {
return tokens[tokenPos++];
}
throw new NoSuchElementException();
}
/**
* Gets the index of the next token to return.
*
* @return The next token index
*/
@Override
public int nextIndex() {
return tokenPos;
}
/**
* Gets the next token from the String.
* Equivalent to {@link #next()} except it returns null rather than
* throwing {@link NoSuchElementException} when no tokens remain.
*
* @return The next sequential token, or null when no more tokens are found
*/
public String nextToken() {
if (hasNext()) {
return tokens[tokenPos++];
}
return null;
}
/**
* Gets the token previous to the last returned token.
*
* @return The previous token
*/
@Override
public String previous() {
if (hasPrevious()) {
return tokens[--tokenPos];
}
throw new NoSuchElementException();
}
/**
* Gets the index of the previous token.
*
* @return The previous token index
*/
@Override
public int previousIndex() {
return tokenPos - 1;
}
/**
* Gets the previous token from the String.
*
* @return The previous sequential token, or null when no more tokens are found
*/
public String previousToken() {
if (hasPrevious()) {
return tokens[--tokenPos];
}
return null;
}
/**
* Reads character by character through the String to get the next token.
*
* @param srcChars the character array being tokenized
* @param start the first character of field
* @param len the length of the character array being tokenized
* @param workArea a temporary work area
* @param tokenList the list of parsed tokens
* @return The starting position of the next field (the character
* immediately after the delimiter), or -1 if end of string found
*/
private int readNextToken(final char[] srcChars,
int start,
final int len,
final StrBuilder workArea, |
File |
Line |
org/apache/commons/text/StrTokenizer.java |
713 |
org/apache/commons/text/StringTokenizer.java |
731 |
final StrBuilder workArea,
final List<String> tokenList) {
// skip all leading whitespace, unless it is the
// field delimiter or the quote character
while (start < len) {
final int removeLen = Math.max(
getIgnoredMatcher().isMatch(srcChars, start, start, len),
getTrimmerMatcher().isMatch(srcChars, start, start, len));
if (removeLen == 0
|| getDelimiterMatcher().isMatch(srcChars, start, start, len) > 0
|| getQuoteMatcher().isMatch(srcChars, start, start, len) > 0) {
break;
}
start += removeLen;
}
// handle reaching end
if (start >= len) {
addToken(tokenList, StringUtils.EMPTY);
return -1;
}
// handle empty token
final int delimLen = getDelimiterMatcher().isMatch(srcChars, start, start, len);
if (delimLen > 0) {
addToken(tokenList, StringUtils.EMPTY);
return start + delimLen;
}
// handle found token
final int quoteLen = getQuoteMatcher().isMatch(srcChars, start, start, len);
if (quoteLen > 0) {
return readWithQuotes(srcChars, start + quoteLen, len, workArea, tokenList, start, quoteLen);
}
return readWithQuotes(srcChars, start, len, workArea, tokenList, 0, 0);
}
/**
* Reads a possibly quoted string token.
*
* @param srcChars the character array being tokenized
* @param start the first character of field
* @param len the length of the character array being tokenized
* @param workArea a temporary work area
* @param tokenList the list of parsed tokens
* @param quoteStart the start position of the matched quote, 0 if no quoting
* @param quoteLen the length of the matched quote, 0 if no quoting
* @return The starting position of the next field (the character
* immediately after the delimiter, or if end of string found,
* then the length of string
*/
private int readWithQuotes(final char[] srcChars, final int start, final int len, final StrBuilder workArea, |
File |
Line |
org/apache/commons/text/StrBuilder.java |
1320 |
org/apache/commons/text/TextStringBuilder.java |
1366 |
public StrBuilder appendSeparator(final String standard, final String defaultIfEmpty) {
final String str = isEmpty() ? defaultIfEmpty : standard;
if (str != null) {
append(str);
}
return this;
}
/**
* Appends current contents of this {@code StrBuilder} to the
* provided {@link Appendable}.
* <p>
* This method tries to avoid doing any extra copies of contents.
* </p>
*
* @param appendable the appendable to append data to
* @throws IOException if an I/O error occurs
*
* @see #readFrom(Readable)
*/
public void appendTo(final Appendable appendable) throws IOException {
if (appendable instanceof Writer) {
((Writer) appendable).write(buffer, 0, size);
} else if (appendable instanceof StringBuilder) {
((StringBuilder) appendable).append(buffer, 0, size);
} else if (appendable instanceof StringBuffer) {
((StringBuffer) appendable).append(buffer, 0, size);
} else if (appendable instanceof CharBuffer) {
((CharBuffer) appendable).put(buffer, 0, size);
} else {
appendable.append(this);
}
} |
File |
Line |
org/apache/commons/text/StrBuilder.java |
2743 |
org/apache/commons/text/TextStringBuilder.java |
2883 |
final StrMatcher matcher, final String replaceStr,
final int from, int to, int replaceCount) {
if (matcher == null || size == 0) {
return this;
}
final int replaceLen = replaceStr == null ? 0 : replaceStr.length();
for (int i = from; i < to && replaceCount != 0; i++) {
final char[] buf = buffer;
final int removeLen = matcher.isMatch(buf, i, from, to);
if (removeLen > 0) {
replaceImpl(i, i + removeLen, removeLen, replaceStr, replaceLen);
to = to - removeLen + replaceLen;
i = i + replaceLen - 1;
if (replaceCount > 0) {
replaceCount--;
}
}
}
return this;
} |
File |
Line |
org/apache/commons/text/StrBuilder.java |
2429 |
org/apache/commons/text/TextStringBuilder.java |
2515 |
}
/**
* Extracts the leftmost characters from the string builder without
* throwing an exception.
* <p>
* This method extracts the left {@code length} characters from
* the builder. If this many characters are not available, the whole
* builder is returned. Thus the returned string may be shorter than the
* length requested.
* </p>
*
* @param length the number of characters to extract, negative returns empty string
* @return The new string
*/
public String leftString(final int length) {
if (length <= 0) {
return StringUtils.EMPTY;
}
if (length >= size) {
return new String(buffer, 0, size);
}
return new String(buffer, 0, length);
}
/**
* Gets the length of the string builder.
*
* @return The length
*/
@Override
public int length() {
return size;
}
/**
* Extracts some characters from the middle of the string builder without
* throwing an exception.
* <p>
* This method extracts {@code length} characters from the builder
* at the specified index.
* If the index is negative it is treated as zero.
* If the index is greater than the builder size, it is treated as the builder size.
* If the length is negative, the empty string is returned.
* If insufficient characters are available in the builder, as much as possible is returned.
* Thus the returned string may be shorter than the length requested.
* </p>
*
* @param index the index to start at, negative means zero
* @param length the number of characters to extract, negative returns empty string
* @return The new string
*/
public String midString(int index, final int length) {
if (index < 0) {
index = 0;
}
if (length <= 0 || index >= size) {
return StringUtils.EMPTY;
}
if (size <= index + length) {
return new String(buffer, index, size - index);
}
return new String(buffer, index, length);
}
/**
* Minimizes the capacity to the actual length of the string.
*
* @return this, to enable chaining
*/
public StrBuilder minimizeCapacity() { |
File |
Line |
org/apache/commons/text/similarity/LevenshteinDetailedDistance.java |
243 |
org/apache/commons/text/similarity/LevenshteinDetailedDistance.java |
386 |
return n <= threshold ? new LevenshteinResults(n, 0, n, 0) : new LevenshteinResults(-1, 0, 0, 0);
}
boolean swapped = false;
if (n > m) {
// swap the two strings to consume less memory
final CharSequence tmp = left;
left = right;
right = tmp;
n = m;
m = right.length();
swapped = true;
}
int[] p = new int[n + 1]; // 'previous' cost array, horizontally
int[] d = new int[n + 1]; // cost array, horizontally
int[] tempD; // placeholder to assist in swapping p and d
final int[][] matrix = new int[m + 1][n + 1];
//filling the first row and first column values in the matrix
for (int index = 0; index <= n; index++) {
matrix[0][index] = index;
}
for (int index = 0; index <= m; index++) {
matrix[index][0] = index;
} |
File |
Line |
org/apache/commons/text/similarity/LevenshteinDetailedDistance.java |
271 |
org/apache/commons/text/similarity/LevenshteinDistance.java |
172 |
final int boundary = Math.min(n, threshold) + 1;
for (int i = 0; i < boundary; i++) {
p[i] = i;
}
// these fills ensure that the value above the rightmost entry of our
// stripe will be ignored in following loop iterations
Arrays.fill(p, boundary, p.length, Integer.MAX_VALUE);
Arrays.fill(d, Integer.MAX_VALUE);
// iterates through t
for (int j = 1; j <= m; j++) {
final char rightJ = right.charAt(j - 1); // jth character of right
d[0] = j;
// compute stripe indices, constrain to array size
final int min = Math.max(1, j - threshold);
final int max = j > Integer.MAX_VALUE - threshold ? n : Math.min(
n, j + threshold);
// the stripe may lead off of the table if s and t are of different sizes
if (min > max) { |
File |
Line |
org/apache/commons/text/StrBuilder.java |
2769 |
org/apache/commons/text/TextStringBuilder.java |
2928 |
public StrBuilder reverse() {
if (size == 0) {
return this;
}
final int half = size / 2;
final char[] buf = buffer;
for (int leftIdx = 0, rightIdx = size - 1; leftIdx < half; leftIdx++, rightIdx--) {
final char swap = buf[leftIdx];
buf[leftIdx] = buf[rightIdx];
buf[rightIdx] = swap;
}
return this;
}
/**
* Extracts the rightmost characters from the string builder without
* throwing an exception.
* <p>
* This method extracts the right {@code length} characters from
* the builder. If this many characters are not available, the whole
* builder is returned. Thus the returned string may be shorter than the
* length requested.
* </p>
*
* @param length the number of characters to extract, negative returns empty string
* @return The new string
*/
public String rightString(final int length) {
if (length <= 0) {
return StringUtils.EMPTY;
}
if (length >= size) {
return new String(buffer, 0, size);
}
return new String(buffer, size - length, length);
}
/**
* Sets the character at the specified index.
*
* @see #charAt(int)
* @see #deleteCharAt(int)
* @param index the index to set
* @param ch the new character
* @return this, to enable chaining
* @throws IndexOutOfBoundsException if the index is invalid
*/
public StrBuilder setCharAt(final int index, final char ch) { |
File |
Line |
org/apache/commons/text/StrBuilder.java |
844 |
org/apache/commons/text/TextStringBuilder.java |
898 |
ensureCapacity(size + width);
String str = obj == null ? getNullText() : obj.toString();
if (str == null) {
str = StringUtils.EMPTY;
}
final int strLen = str.length();
if (strLen >= width) {
str.getChars(strLen - width, strLen, buffer, size);
} else {
final int padLen = width - strLen;
for (int i = 0; i < padLen; i++) {
buffer[size + i] = padChar;
}
str.getChars(0, strLen, buffer, size + padLen);
}
size += width;
}
return this;
}
/**
* Appends an object to the builder padding on the right to a fixed length.
* The {@code String.valueOf} of the {@code int} value is used.
* If the object is larger than the length, the right hand side is lost.
*
* @param value the value to append
* @param width the fixed field width, zero or negative has no effect
* @param padChar the pad character to use
* @return this, to enable chaining
*/
public StrBuilder appendFixedWidthPadRight(final int value, final int width, final char padChar) { |
File |
Line |
org/apache/commons/text/StrBuilder.java |
891 |
org/apache/commons/text/TextStringBuilder.java |
943 |
ensureCapacity(size + width);
String str = obj == null ? getNullText() : obj.toString();
if (str == null) {
str = StringUtils.EMPTY;
}
final int strLen = str.length();
if (strLen >= width) {
str.getChars(0, width, buffer, size);
} else {
final int padLen = width - strLen;
str.getChars(0, strLen, buffer, size);
for (int i = 0; i < padLen; i++) {
buffer[size + strLen + i] = padChar;
}
}
size += width;
}
return this;
}
/**
* Appends a boolean value followed by a new line to the string builder.
*
* @param value the value to append
* @return this, to enable chaining
*/
public StrBuilder appendln(final boolean value) { |
File |
Line |
org/apache/commons/text/StrBuilder.java |
1854 |
org/apache/commons/text/TextStringBuilder.java |
1947 |
public boolean equalsIgnoreCase(final StrBuilder other) {
if (this == other) {
return true;
}
if (this.size != other.size) {
return false;
}
final char[] thisBuf = this.buffer;
final char[] otherBuf = other.buffer;
for (int i = size - 1; i >= 0; i--) {
final char c1 = thisBuf[i];
final char c2 = otherBuf[i];
if (c1 != c2 && Character.toUpperCase(c1) != Character.toUpperCase(c2)) {
return false;
}
}
return true;
}
/**
* Converts this instance to a String.
*
* @return This instance as a String
* @see #toString()
* @since 1.12.0
*/
@Override
public String get() {
return toString();
} |
File |
Line |
org/apache/commons/text/StrBuilder.java |
583 |
org/apache/commons/text/StrBuilder.java |
632 |
public StrBuilder append(final StrBuilder str, final int startIndex, final int length) {
if (str == null) {
return appendNull();
}
if (startIndex < 0 || startIndex > str.length()) {
throw new StringIndexOutOfBoundsException("startIndex must be valid");
}
if (length < 0 || startIndex + length > str.length()) {
throw new StringIndexOutOfBoundsException("length must be valid");
}
if (length > 0) {
final int len = length();
ensureCapacity(len + length);
str.getChars(startIndex, startIndex + length, buffer, len);
size += length;
}
return this;
}
/**
* Appends a string to this string builder.
* Appending null will call {@link #appendNull()}.
*
* @param str the string to append
* @return this, to enable chaining
*/
public StrBuilder append(final String str) { |
File |
Line |
org/apache/commons/text/StrBuilder.java |
583 |
org/apache/commons/text/StrBuilder.java |
632 |
org/apache/commons/text/StrBuilder.java |
693 |
public StrBuilder append(final StrBuilder str, final int startIndex, final int length) {
if (str == null) {
return appendNull();
}
if (startIndex < 0 || startIndex > str.length()) {
throw new StringIndexOutOfBoundsException("startIndex must be valid");
}
if (length < 0 || startIndex + length > str.length()) {
throw new StringIndexOutOfBoundsException("length must be valid");
}
if (length > 0) {
final int len = length();
ensureCapacity(len + length);
str.getChars(startIndex, startIndex + length, buffer, len);
size += length;
}
return this;
}
/**
* Appends a string to this string builder.
* Appending null will call {@link #appendNull()}.
*
* @param str the string to append
* @return this, to enable chaining
*/
public StrBuilder append(final String str) { |
File |
Line |
org/apache/commons/text/TextStringBuilder.java |
671 |
org/apache/commons/text/TextStringBuilder.java |
720 |
org/apache/commons/text/TextStringBuilder.java |
757 |
public TextStringBuilder append(final String str, final int startIndex, final int length) {
if (str == null) {
return appendNull();
}
if (startIndex < 0 || startIndex > str.length()) {
throw new StringIndexOutOfBoundsException("startIndex must be valid");
}
if (length < 0 || startIndex + length > str.length()) {
throw new StringIndexOutOfBoundsException("length must be valid");
}
if (length > 0) {
final int len = length();
ensureCapacityInternal(len + length);
str.getChars(startIndex, startIndex + length, buffer, len);
size += length;
}
return this;
}
/**
* Calls {@link String#format(String, Object...)} and appends the result.
*
* @param format the format string
* @param objs the objects to use in the format string
* @return {@code this} to enable chaining
* @see String#format(String, Object...)
*/
public TextStringBuilder append(final String format, final Object... objs) { |
File |
Line |
org/apache/commons/text/StrBuilder.java |
583 |
org/apache/commons/text/StrBuilder.java |
632 |
org/apache/commons/text/StrBuilder.java |
693 |
org/apache/commons/text/StrBuilder.java |
742 |
public StrBuilder append(final StrBuilder str, final int startIndex, final int length) {
if (str == null) {
return appendNull();
}
if (startIndex < 0 || startIndex > str.length()) {
throw new StringIndexOutOfBoundsException("startIndex must be valid");
}
if (length < 0 || startIndex + length > str.length()) {
throw new StringIndexOutOfBoundsException("length must be valid");
}
if (length > 0) {
final int len = length();
ensureCapacity(len + length);
str.getChars(startIndex, startIndex + length, buffer, len);
size += length;
}
return this;
}
/**
* Appends a string to this string builder.
* Appending null will call {@link #appendNull()}.
*
* @param str the string to append
* @return this, to enable chaining
*/
public StrBuilder append(final String str) { |
File |
Line |
org/apache/commons/text/TextStringBuilder.java |
671 |
org/apache/commons/text/TextStringBuilder.java |
720 |
org/apache/commons/text/TextStringBuilder.java |
757 |
org/apache/commons/text/TextStringBuilder.java |
794 |
public TextStringBuilder append(final String str, final int startIndex, final int length) {
if (str == null) {
return appendNull();
}
if (startIndex < 0 || startIndex > str.length()) {
throw new StringIndexOutOfBoundsException("startIndex must be valid");
}
if (length < 0 || startIndex + length > str.length()) {
throw new StringIndexOutOfBoundsException("length must be valid");
}
if (length > 0) {
final int len = length();
ensureCapacityInternal(len + length);
str.getChars(startIndex, startIndex + length, buffer, len);
size += length;
}
return this;
}
/**
* Calls {@link String#format(String, Object...)} and appends the result.
*
* @param format the format string
* @param objs the objects to use in the format string
* @return {@code this} to enable chaining
* @see String#format(String, Object...)
*/
public TextStringBuilder append(final String format, final Object... objs) { |
File |
Line |
org/apache/commons/text/StrBuilder.java |
2365 |
org/apache/commons/text/TextStringBuilder.java |
2455 |
}
final int strLen = str.length();
if (strLen > 0 && strLen <= size) {
if (strLen == 1) {
return lastIndexOf(str.charAt(0), startIndex);
}
outer:
for (int i = startIndex - strLen + 1; i >= 0; i--) {
for (int j = 0; j < strLen; j++) {
if (str.charAt(j) != buffer[i + j]) {
continue outer;
}
}
return i;
}
} else if (strLen == 0) {
return startIndex;
}
return -1; |
File |
Line |
org/apache/commons/text/StrSubstitutor.java |
802 |
org/apache/commons/text/StringSubstitutor.java |
1043 |
final StrBuilder buf = new StrBuilder(length).append(source, offset, length);
if (!substitute(buf, 0, length)) {
return false;
}
source.replace(offset, offset + length, buf.toString());
return true;
}
/**
* Replaces all the occurrences of variables within the given source buffer
* with their matching values from the resolver.
* The buffer is updated with the result.
*
* @param source the buffer to replace in, updated, null returns zero
* @return true if altered
*/
public boolean replaceIn(final StringBuilder source) {
if (source == null) {
return false;
}
return replaceIn(source, 0, source.length());
}
/**
* Replaces all the occurrences of variables within the given source builder
* with their matching values from the resolver.
* The builder is updated with the result.
* <p>
* Only the specified portion of the buffer will be processed.
* The rest of the buffer is not processed, but it is not deleted.
* </p>
*
* @param source the buffer to replace in, updated, null returns zero
* @param offset the start offset within the array, must be valid
* @param length the length within the buffer to be processed, must be valid
* @return true if altered
*/
public boolean replaceIn(final StringBuilder source, final int offset, final int length) {
if (source == null) {
return false;
}
final StrBuilder buf = new StrBuilder(length).append(source, offset, length); |
File |
Line |
org/apache/commons/text/StrTokenizer.java |
392 |
org/apache/commons/text/StringTokenizer.java |
410 |
public StrTokenizer(final String input, final StrMatcher delim, final StrMatcher quote) {
this(input, delim);
setQuoteMatcher(quote);
}
/**
* Unsupported ListIterator operation.
* @param obj this parameter ignored.
* @throws UnsupportedOperationException always
*/
@Override
public void add(final String obj) {
throw new UnsupportedOperationException("add() is unsupported");
}
/**
* Adds a token to a list, paying attention to the parameters we've set.
*
* @param list the list to add to
* @param tok the token to add
*/
private void addToken(final List<String> list, String tok) {
if (tok == null || tok.isEmpty()) {
if (isIgnoreEmptyTokens()) {
return;
}
if (isEmptyTokenAsNull()) {
tok = null;
}
}
list.add(tok);
}
/**
* Checks if tokenization has been done, and if not then do it.
*/
private void checkTokenized() {
if (tokens == null) { |
|