+ private final List<Character> chars = new ArrayList<>();
+
+ public String2(String value) {
+ addSuffix(value);
+ }
+
+ public String2() {
+ }
+
+ public String2 repeat(int count){
+ String value = toString();
+
+ for (int i = 1; i < count; i++) {
+ addSuffix(value);
+ }
+ return this;
+ }
+
+ public String2 addPrefix(final String prefix) {
+ if (prefix == null)
+ return this;
+
+ int i = 0;
+ for (final char c : prefix.toCharArray())
+ chars.add(i++, c);
+
+ return this;
+ }
+
+ public String2 addSuffix(final String suffix) {
+ if (suffix == null)
+ return this;
+
+ for (final char c : suffix.toCharArray())
+ chars.add(c);
+
+ return this;
+ }
+
+ public String2 addSuffix(String separator, final String suffix) {
+ if (!isEmpty())
+ addSuffix(separator);
+
+ addSuffix(suffix);
+
+ return this;
+ }
+
+ public String2 addSuffix(String s, int times) {
+ for (int i = 0; i < times; i++) addSuffix(s);
+ return this;
+ }
+
+
+ /**
+ * Cut given amount of characters from the left of the string.
+ *
+ * @param cutAmount of characters to cut
+ * @return part that was cut.
+ */
+ public String2 trimPrefix(final int cutAmount) {
+
+ int actualCutAmount = cutAmount;
+
+ if (actualCutAmount > getLength())
+ actualCutAmount = getLength();
+
+ chars.subList(0, actualCutAmount).clear();
+
+ return this;
+ }
+
+ public String2 trimPrefixIfExists(String prefix) {
+ if (prefix == null)
+ return this;
+
+ if (hasPrefix(prefix))
+ trimPrefix(prefix.length());
+
+ return this;
+ }
+
+ public String2 trimSuffixIfExists(String suffix) {
+ if (hasSuffix(suffix))
+ trimSuffix(suffix.length());
+
+ return this;
+ }
+
+ public String2 trimSuffix(int charsToTrim) {
+
+ if (charsToTrim > chars.size()) {
+ chars.clear();
+ return this;
+ }
+
+ for (int i = 0; i < charsToTrim; i++)
+ chars.remove(chars.size() - 1);
+
+ return this;
+ }