You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/06/28 16:25:06 UTC
[commons-text] branch master updated: Small refactoring of common
code.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git
The following commit(s) were added to refs/heads/master by this push:
new c20f3a4 Small refactoring of common code.
c20f3a4 is described below
commit c20f3a4512141200eefbbf54cbed70e349e479e2
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jun 28 12:24:59 2020 -0400
Small refactoring of common code.
---
.../org/apache/commons/text/TextStringBuilder.java | 45 ++++++++++++----------
1 file changed, 24 insertions(+), 21 deletions(-)
diff --git a/src/main/java/org/apache/commons/text/TextStringBuilder.java b/src/main/java/org/apache/commons/text/TextStringBuilder.java
index 7936b94..ae44bd8 100644
--- a/src/main/java/org/apache/commons/text/TextStringBuilder.java
+++ b/src/main/java/org/apache/commons/text/TextStringBuilder.java
@@ -331,17 +331,10 @@ public class TextStringBuilder implements CharSequence, Appendable, Serializable
public TextStringBuilder append(final boolean value) {
if (value) {
ensureCapacity(size + TRUE_STRING_SIZE);
- buffer[size++] = 't';
- buffer[size++] = 'r';
- buffer[size++] = 'u';
- buffer[size++] = 'e';
+ appendTrue(size);
} else {
ensureCapacity(size + FALSE_STRING_SIZE);
- buffer[size++] = 'f';
- buffer[size++] = 'a';
- buffer[size++] = 'l';
- buffer[size++] = 's';
- buffer[size++] = 'e';
+ appendFalse(size);
}
return this;
}
@@ -857,6 +850,16 @@ public class TextStringBuilder implements CharSequence, Appendable, Serializable
return this;
}
+ /** Appends {@code "false"}. */
+ private void appendFalse(int index) {
+ buffer[index++] = 'f';
+ buffer[index++] = 'a';
+ buffer[index++] = 'l';
+ buffer[index++] = 's';
+ buffer[index] = 'e';
+ size += FALSE_STRING_SIZE;
+ }
+
/**
* Appends an object to the builder padding on the left to a fixed width. The {@code String.valueOf} of the
* {@code int} value is used. If the formatted value is larger than the length, the left hand side is lost.
@@ -1437,6 +1440,15 @@ public class TextStringBuilder implements CharSequence, Appendable, Serializable
}
}
+ /** Appends {@code "true"}. */
+ private void appendTrue(int index) {
+ buffer[index++] = 't';
+ buffer[index++] = 'r';
+ buffer[index++] = 'u';
+ buffer[index] = 'e';
+ size += TRUE_STRING_SIZE;
+ }
+
/**
* Appends an iterable placing separators between each value, but not before the first or after the last. Appending
* a null iterable will have no effect. Each object is appended using {@link #append(Object)}.
@@ -2192,25 +2204,16 @@ public class TextStringBuilder implements CharSequence, Appendable, Serializable
* @throws IndexOutOfBoundsException
* if the index is invalid
*/
- public TextStringBuilder insert(int index, final boolean value) {
+ public TextStringBuilder insert(final int index, final boolean value) {
validateIndex(index);
if (value) {
ensureCapacity(size + TRUE_STRING_SIZE);
System.arraycopy(buffer, index, buffer, index + TRUE_STRING_SIZE, size - index);
- buffer[index++] = 't';
- buffer[index++] = 'r';
- buffer[index++] = 'u';
- buffer[index] = 'e';
- size += TRUE_STRING_SIZE;
+ appendTrue(index);
} else {
ensureCapacity(size + FALSE_STRING_SIZE);
System.arraycopy(buffer, index, buffer, index + FALSE_STRING_SIZE, size - index);
- buffer[index++] = 'f';
- buffer[index++] = 'a';
- buffer[index++] = 'l';
- buffer[index++] = 's';
- buffer[index] = 'e';
- size += FALSE_STRING_SIZE;
+ appendFalse(index);
}
return this;
}