X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fstring%2FString2.java;h=705df579627140832f6197eb198592215a44d65b;hb=443c6a564efa9f5868fd81c0db23a480cbe3cab4;hp=2e9446a5fc3edf67c153d0e68a9f5a6055f9a51a;hpb=c8c84ff3c00094e9e87313753b659934f4d4ae72;p=svjatoslav_commons.git diff --git a/src/main/java/eu/svjatoslav/commons/string/String2.java b/src/main/java/eu/svjatoslav/commons/string/String2.java index 2e9446a..705df57 100755 --- a/src/main/java/eu/svjatoslav/commons/string/String2.java +++ b/src/main/java/eu/svjatoslav/commons/string/String2.java @@ -1,6 +1,6 @@ /* * Svjatoslav Commons - shared library of common functionality. - * Copyright ©2012-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License @@ -14,15 +14,10 @@ import java.util.List; public class String2 { - private final List chars; + private final List chars = new ArrayList<>(); public String2(String value) { - if (value == null) - value = ""; - - chars = new ArrayList<>(value.length()); - for (final Character c : value.toCharArray()) - chars.add(c); + addSuffix(value); } public String2 addPrefix(final String prefix) { @@ -54,6 +49,7 @@ public class String2 { return this; } + /** * Cut given amount of characters from the left of the string. * @@ -72,7 +68,7 @@ public class String2 { return this; } - public String2 trimPrefixIfExists(String prefix){ + public String2 trimPrefixIfExists(String prefix) { if (prefix == null) return this; @@ -82,7 +78,7 @@ public class String2 { return this; } - public String2 trimSuffixIfExists(String suffix){ + public String2 trimSuffixIfExists(String suffix) { if (hasSuffix(suffix)) trimSuffix(suffix.length()); @@ -91,13 +87,13 @@ public class String2 { public String2 trimSuffix(int charsToTrim) { - if (charsToTrim > chars.size()){ + if (charsToTrim > chars.size()) { chars.clear(); return this; } - for (int i = 0; i chars.size()) return false;