diff --git a/src/fr/devinsy/util/strings/StringList.java b/src/fr/devinsy/util/strings/StringList.java index 922d88a..8b64bee 100644 --- a/src/fr/devinsy/util/strings/StringList.java +++ b/src/fr/devinsy/util/strings/StringList.java @@ -18,7 +18,6 @@ */ package fr.devinsy.util.strings; -import java.io.IOException; import java.text.Collator; import java.util.ArrayList; import java.util.Collection; @@ -83,6 +82,23 @@ public class StringList extends ArrayList implements CharSequence super(initialCapacity); } + /** + * Constructs a list of string from an Object array. + * + * @param source + */ + public StringList(final Object... source) + { + super(); + + if (source != null) + { + ensureCapacity(source.length); + + append(source); + } + } + /** * Constructs a list of string from a string array. * @@ -106,44 +122,20 @@ public class StringList extends ArrayList implements CharSequence } /** - * Appends the string of the array argument to this boolean list. + * Appends the string of the array argument to this string list. * * @param strings * @return */ - public StringList append(final boolean... items) + public StringList append(final boolean... values) { StringList result; - if (items != null) + if (values != null) { - for (boolean item : items) + for (boolean value : values) { - this.append(item); - } - } - - result = this; - - // - return result; - } - - /** - * Appends the string of the array argument to this byte list. - * - * @param strings - * @return - */ - public StringList append(final byte... items) - { - StringList result; - - if (items != null) - { - for (byte item : items) - { - this.append(item); + this.append(value); } } @@ -172,30 +164,6 @@ public class StringList extends ArrayList implements CharSequence return result; } - /** - * Appends the string of the array argument to this char list. - * - * @param strings - * @return - */ - public StringList append(final char... items) - { - StringList result; - - if (items != null) - { - for (char item : items) - { - this.append(item); - } - } - - result = this; - - // - return result; - } - /** * Appends the string of the specified collection, in the order they are * returned by the collection's iterator. @@ -272,6 +240,30 @@ public class StringList extends ArrayList implements CharSequence return result; } + /** + * Appends the string of the array argument to this string list. + * + * @param values + * @return + */ + public StringList append(final Long... values) + { + StringList result; + + if (values != null) + { + for (Long value : values) + { + this.append(value); + } + } + + result = this; + + // + return result; + } + /** * Appends the string representation of the int argument to this string * list. @@ -295,20 +287,20 @@ public class StringList extends ArrayList implements CharSequence } /** - * Appends the string of the array argument to this short list. + * Appends the string of the array argument to this string list. * * @param strings * @return */ - public StringList append(final short... items) + public StringList append(final Object... values) { StringList result; - if (items != null) + if (values != null) { - for (short item : items) + for (Object value : values) { - this.append(item); + this.append(value); } } @@ -372,7 +364,7 @@ public class StringList extends ArrayList implements CharSequence { for (String string : strings) { - this.add(string); + this.append(string); } } @@ -399,60 +391,6 @@ public class StringList extends ArrayList implements CharSequence return result; } - /** - * Appends the string of the array argument to this boolean list. - * - * @param items - * @return - */ - public StringList appendln(final boolean... items) - { - StringList result; - - append(items).appendln(); - - result = this; - - // - return result; - } - - /** - * Appends the string of the array argument to this byte list. - * - * @param items - * @return - */ - public StringList appendln(final byte... items) - { - StringList result; - - append(items).appendln(); - - result = this; - - // - return result; - } - - /** - * Appends the string of the array argument to this char list. - * - * @param strings - * @return - */ - public StringList appendln(final char... items) - { - StringList result; - - append(items).appendln(); - - result = this; - - // - return result; - } - /** * Appends the string representation of the char argument to this string * list, then append a break line too. @@ -538,6 +476,24 @@ public class StringList extends ArrayList implements CharSequence return result; } + /** + * Appends the string of the array argument to this string list. + * + * @param values + * @return + */ + public StringList appendln(final Object... values) + { + StringList result; + + append(values).appendln(); + + result = this; + + // + return result; + } + /** * Appendln. * @@ -555,24 +511,6 @@ public class StringList extends ArrayList implements CharSequence return result; } - /** - * Appends the string of the array argument to this short list. - * - * @param strings - * @return - */ - public StringList appendln(final short... items) - { - StringList result; - - append(items).appendln(); - - result = this; - - // - return result; - } - /** * Appendln. * @@ -1797,35 +1735,4 @@ public class StringList extends ArrayList implements CharSequence return result; } - /** - * Writes the strings of this list into a {@code PrintWriter}. - * - * @param out - * The {@code PrintWriter} where to write. - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public void writeInto(final java.io.PrintWriter out) throws IOException - { - for (String string : this) - { - out.write(string); - } - } - - /** - * Writes the strings of this list into a {@code Writer}. - * - * @param out - * The {@code Writer} where to write. - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public void writeInto(final java.io.Writer out) throws IOException - { - for (String string : this) - { - out.write(string); - } - } } diff --git a/src/fr/devinsy/util/strings/StringsUtils.java b/src/fr/devinsy/util/strings/StringsUtils.java index e96b82a..d583387 100644 --- a/src/fr/devinsy/util/strings/StringsUtils.java +++ b/src/fr/devinsy/util/strings/StringsUtils.java @@ -1004,6 +1004,266 @@ public class StringsUtils return result; } + public static StringList toStringList(final boolean... source) + { + StringList result; + + result = new StringList(); + + if (source != null) + { + result.ensureCapacity(source.length); + + for (boolean value : source) + { + result.append(value); + } + } + + // + return result; + } + + public static StringList toStringList(final Boolean... source) + { + StringList result; + + result = new StringList(); + + if (source != null) + { + result.ensureCapacity(source.length); + + for (Boolean value : source) + { + result.append(String.valueOf(value)); + } + } + + // + return result; + } + + public static StringList toStringList(final byte... source) + { + StringList result; + + result = new StringList(); + + if (source != null) + { + result.ensureCapacity(source.length); + + for (byte value : source) + { + result.append(value); + } + } + + // + return result; + } + + public static StringList toStringList(final Byte... source) + { + StringList result; + + result = new StringList(); + + if (source != null) + { + result.ensureCapacity(source.length); + + for (Byte value : source) + { + result.add(String.valueOf(value)); + } + } + + // + return result; + } + + public static StringList toStringList(final char... source) + { + StringList result; + + result = new StringList(); + + if (source != null) + { + result.ensureCapacity(source.length); + + for (char value : source) + { + result.append(value); + } + } + + // + return result; + } + + public static StringList toStringList(final double... source) + { + StringList result; + + result = new StringList(); + + if (source != null) + { + result.ensureCapacity(source.length); + + for (double value : source) + { + result.append(value); + } + } + + // + return result; + } + + public static StringList toStringList(final Double... source) + { + StringList result; + + result = new StringList(); + + if (source != null) + { + result.ensureCapacity(source.length); + + for (Double value : source) + { + result.add(String.valueOf(value)); + } + } + + // + return result; + } + + public static StringList toStringList(final float... source) + { + StringList result; + + result = new StringList(); + + if (source != null) + { + result.ensureCapacity(source.length); + + for (float value : source) + { + result.append(value); + } + } + + // + return result; + } + + public static StringList toStringList(final Float... source) + { + StringList result; + + result = new StringList(); + + if (source != null) + { + result.ensureCapacity(source.length); + + for (Float value : source) + { + result.add(String.valueOf(value)); + } + } + + // + return result; + } + + public static StringList toStringList(final long... source) + { + StringList result; + + result = new StringList(); + + if (source != null) + { + result.ensureCapacity(source.length); + + for (long value : source) + { + result.append(value); + } + } + + // + return result; + } + + public static StringList toStringList(final Long... source) + { + StringList result; + + result = new StringList(); + + if (source != null) + { + result.ensureCapacity(source.length); + + for (Long value : source) + { + result.add(String.valueOf(value)); + } + } + + // + return result; + } + + public static StringList toStringList(final short... source) + { + StringList result; + + result = new StringList(); + + if (source != null) + { + result.ensureCapacity(source.length); + + for (short value : source) + { + result.append(value); + } + } + + // + return result; + } + + public static StringList toStringList(final Short... source) + { + StringList result; + + result = new StringList(); + + if (source != null) + { + result.ensureCapacity(source.length); + + for (Short value : source) + { + result.add(String.valueOf(value)); + } + } + + // + return result; + } + /** * Concatenates the string from an array to a string. * @@ -1520,4 +1780,42 @@ public class StringsUtils source.addAll(values); } } + + /** + * Writes the strings of this list into a {@code PrintWriter}. + * + * @param out + * The {@code PrintWriter} where to write. + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public static void writeTo(final StringList source, final java.io.PrintWriter out) throws IOException + { + if (source != null) + { + for (String string : source) + { + out.write(string); + } + } + } + + /** + * Writes the strings of this list into a {@code Writer}. + * + * @param out + * The {@code Writer} where to write. + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public static void writeTo(final StringList source, final java.io.Writer out) throws IOException + { + if (source != null) + { + for (String string : source) + { + out.write(string); + } + } + } } diff --git a/src/fr/devinsy/util/strings/StringstUtils.java b/src/fr/devinsy/util/strings/StringstUtils.java deleted file mode 100644 index f046e5e..0000000 --- a/src/fr/devinsy/util/strings/StringstUtils.java +++ /dev/null @@ -1,1523 +0,0 @@ -/* - * Copyright (C) 2008-2010,2013-2016,2017 Christian Pierre MOMON - * - * This file is part of Devinsy-strings. - * - * Devinsy-strings is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Devinsy-strings is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Devinsy-strings. If not, see - */ -package fr.devinsy.util.strings; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.util.Collection; -import java.util.Iterator; - -import org.apache.commons.lang3.StringUtils; - -/** - * The {@code StringUtils} class defines helper methods to string collection. - * - * Operations that are null safe. - */ -public class StringstUtils -{ - public static final String DEFAULT_CHARSET_NAME = "UTF-8"; - - /** - * Instantiates a new stringst utils. - */ - private StringstUtils() - { - } - - /** - * Capitalize. - * - * @param sourceStringUtils - * .lo the source - */ - public static void capitalize(final StringList source) - { - if (source != null) - { - for (int index = 0; index < source.size(); index++) - { - source.set(index, StringUtils.capitalize(source.get(index))); - } - } - } - - /** - * Capitalize. - * - * @param source - * the source - */ - public static void capitalize(final StringSet source) - { - if (source != null) - { - StringList values = new StringList(source); - capitalize(values); - source.clear(); - source.addAll(values); - } - } - - /** - * Builds a string concatenating many times a source string. - * - * @param source - * The string to concatenate several time. - * @param multiplier - * The number of concatenate to produce. - * @return the string - */ - public static String concatenate(final String source, final int multiplier) - { - String result; - - result = repeat(source, multiplier).toString(); - - // - return result; - } - - /** - * Contains blank. - * - * @param source - * the source - * @return true, if successful - */ - public static boolean containsBlank(final Collection source) - { - boolean result; - - if (source == null) - { - result = false; - } - else if (source instanceof StringList) - { - result = ((StringList) source).containsBlank(); - } - else - { - result = new StringList(source).containsBlank(); - } - - // - return result; - } - - /** - * Contains blank. - * - * @param source - * the source - * @return true, if successful - */ - public static boolean containsBlank(final String... source) - { - boolean result; - - if (source == null) - { - result = false; - } - else - { - result = new StringList(source).containsBlank(); - } - - // - return result; - } - - /** - * Contains empty. - * - * @param source - * the source - * @return true, if successful - */ - public static boolean containsEmpty(final Collection source) - { - boolean result; - - if (source == null) - { - result = false; - } - else if (source instanceof StringList) - { - result = ((StringList) source).containsEmpty(); - } - else - { - result = new StringList(source).containsEmpty(); - } - - // - return result; - } - - /** - * Contains empty. - * - * @param source - * the source - * @return true, if successful - */ - public static boolean containsEmpty(final String... source) - { - boolean result; - - if (source == null) - { - result = false; - } - else - { - result = new StringList(source).containsEmpty(); - } - - // - return result; - } - - /** - * Contains null. - * - * @param source - * the source - * @return true, if successful - */ - public static boolean containsNull(final Collection source) - { - boolean result; - - if (source == null) - { - result = false; - } - else if (source instanceof StringList) - { - result = ((StringList) source).containsNull(); - } - else - { - result = new StringList(source).containsNull(); - } - - // - return result; - } - - /** - * Contains null. - * - * @param source - * the source - * @return true, if successful - */ - public static boolean containsNull(final String... source) - { - boolean result; - - if (source == null) - { - result = false; - } - else - { - result = new StringList(source).containsNull(); - } - - // - return result; - } - - /** - * Find longest. - * - * @param source - * the source - * @return the string - */ - public static String findLongest(final Collection source) - { - String result; - - if ((source == null) || (source.isEmpty())) - { - result = null; - } - else - { - int value = 0; - result = null; - - for (String string : source) - { - if ((string != null) && (string.length() > value)) - { - value = string.length(); - result = string; - } - } - } - - // - return result; - } - - /** - * Find longest length. - * - * @param source - * the source - * @return the int - */ - public static int findLongestLength(final Collection source) - { - int result; - - String string = findLongest(source); - if (string == null) - { - result = 0; - } - else - { - result = string.length(); - } - - // - return result; - } - - /** - * Find smallest. - * - * @param source - * the source - * @return the string - */ - public static String findShortest(final Collection source) - { - String result; - - if ((source == null) || (source.isEmpty())) - { - result = null; - } - else - { - int value = Integer.MAX_VALUE; - result = null; - - for (String string : source) - { - if ((string != null) && (string.length() < value)) - { - value = string.length(); - result = string; - } - } - } - - // - return result; - } - - /** - * Find smallest length. - * - * @param source - * the source - * @return the int - */ - public static int findShortestLength(final Collection source) - { - int result; - - String string = findShortest(source); - if (string == null) - { - result = 0; - } - else - { - result = string.length(); - } - - // - return result; - } - - /** - * Gets the complement. - * - * @param alpha - * the alpha - * @param bravo - * the bravo - * @return the complement - */ - public static StringSet getComplement(final Collection alpha, final Collection bravo) - { - StringSet result; - - result = getDifference(bravo, alpha); - - // - return result; - } - - /** - * Gets the difference. - * - * @param alpha - * the alpha - * @param bravo - * the bravo - * @return the difference - */ - public static StringSet getDifference(final Collection alpha, final Collection bravo) - { - StringSet result; - - result = new StringSet(alpha); - result.removeAll(bravo); - - // - return result; - } - - /** - * Gets the disjunction. - * - * @param alpha - * the alpha - * @param bravo - * the bravo - * @return the disjunction - */ - public static StringSet getDisjunction(final Collection alpha, final Collection bravo) - { - StringSet result; - - result = new StringSet(); - - for (String string : alpha) - { - if (!bravo.contains(string)) - { - result.add(string); - } - } - - for (String string : bravo) - { - if (!alpha.contains(string)) - { - result.add(string); - } - } - - // - return result; - } - - /** - * Gets the intersection of. - * - * @param alpha - * the alpha - * @param bravo - * the bravo - * @return the intersection of - */ - public static StringSet getIntersectionOf(final Collection alpha, final Collection bravo) - { - StringSet result; - - result = new StringSet(); - - for (String string : alpha) - { - if (bravo.contains(string)) - { - result.add(string); - } - } - - // - return result; - } - - /** - * Gets the union of. - * - * @param alpha - * the alpha - * @param bravo - * the bravo - * @return the union of - */ - public static StringSet getUnionOf(final Collection alpha, final Collection bravo) - { - StringSet result; - - result = new StringSet(alpha); - - for (String string : bravo) - { - result.add(string); - } - - // - return result; - } - - /** - * Checks if is blank. - * - * @param source - * the source - */ - public static boolean isBlank(final Collection source) - { - boolean result; - - if (source == null) - { - result = true; - } - else - { - Iterator iterator = source.iterator(); - boolean ended = false; - result = false; - while (!ended) - { - if (iterator.hasNext()) - { - String value = iterator.next(); - - if (StringUtils.isNotBlank(value)) - { - ended = true; - result = false; - } - } - else - { - ended = true; - result = true; - } - } - } - - // - return result; - } - - /** - * Checks if is empty. - * - * @param source - * the source - * @return true, if is empty - */ - public static boolean isEmptyFully(final Collection source) - { - boolean result; - - if ((source == null) || (source.isEmpty())) - { - result = true; - } - else - { - Iterator iterator = source.iterator(); - boolean ended = false; - result = false; - while (!ended) - { - if (iterator.hasNext()) - { - String value = iterator.next(); - if (StringUtils.isNotEmpty(value)) - { - ended = true; - result = false; - } - } - else - { - ended = true; - result = true; - } - } - } - - // - return result; - } - - /** - * Load. - * - * @param source - * the source - * @return the string list - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public static StringList load(final File source) throws IOException - { - StringList result; - - result = load(source, DEFAULT_CHARSET_NAME); - - // - return result; - } - - /** - * Load. - * - * @param file - * the file - * @param charsetName - * the charset name - * @return the string list - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public static StringList load(final File file, final String charsetName) throws IOException - { - StringList result; - - // - result = new StringList(); - - // - read(result, new FileInputStream(file), charsetName); - - // - return result; - } - - /** - * Load. - * - * @param source - * the source - * @return the string list - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public static StringList load(final URL source) throws IOException - { - StringList result; - - result = load(source, DEFAULT_CHARSET_NAME); - - // - return result; - } - - /** - * Load. - * - * @param source - * the source - * @param charsetName - * the charset name - * @return the string list - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public static StringList load(final URL source, final String charsetName) throws IOException - { - StringList result; - - // - result = new StringList(); - - // - read(result, source.openStream(), charsetName); - - // - return result; - } - - /** - * Lower case. - * - * @param source - * the source - */ - public static void lowerCase(final StringList source) - { - if (source != null) - { - for (int index = 0; index < source.size(); index++) - { - source.set(index, StringUtils.lowerCase(source.get(index))); - } - } - } - - /** - * Lower case. - * - * @param source - * the source - */ - public static void lowerCase(final StringSet source) - { - if (source != null) - { - StringList values = new StringList(source); - lowerCase(values); - source.clear(); - source.addAll(values); - } - } - - /** - * Read. - * - * @param out - * the out - * @param is - * the is - * @param charsetName - * the charset name - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public static void read(final StringList out, final InputStream is, final String charsetName) throws IOException - { - BufferedReader in = null; - try - { - in = new BufferedReader(new InputStreamReader(is, charsetName)); - - boolean ended = false; - - while (!ended) - { - String line = in.readLine(); - - if (line == null) - { - ended = true; - } - else - { - out.append(line); - } - } - } - finally - { - try - { - if (in != null) - { - in.close(); - } - } - catch (IOException exception) - { - exception.printStackTrace(); - } - } - } - - /** - * Builds a string list concatenating many times a source string. - * - * @param source - * The string to concatenate several time. - * @param multiplier - * The number of concatenate to produce. - * @return the string list - */ - public static StringList repeat(final String source, final int multiplier) - { - StringList result; - - result = new StringList(multiplier); - for (int count = 0; count < multiplier; count++) - { - result.append(source); - } - - // - return result; - } - - /** - * Save. - * - * @param file - * the file - * @param source - * the source - * @throws UnsupportedEncodingException - * the unsupported encoding exception - * @throws FileNotFoundException - * the file not found exception - */ - public static void save(final File file, final StringList source) throws UnsupportedEncodingException, FileNotFoundException - { - PrintWriter out = null; - try - { - out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), DEFAULT_CHARSET_NAME)); - - if (source != null) - { - for (String string : source) - { - out.println(string); - } - } - } - finally - { - if (out != null) - { - out.close(); - } - } - } - - /** - * Sorts the string list. - * - * @param source - * The string list to sort. - */ - public static void sort(final StringList source) - { - if (source != null) - { - source.sort(); - } - } - - /** - * Swap case. - * - * @param source - * the source - */ - public static void swapCase(final StringList source) - { - if (source != null) - { - for (int index = 0; index < source.size(); index++) - { - source.set(index, StringUtils.swapCase(source.get(index))); - } - } - } - - /** - * Swap case. - * - * @param source - * the source - */ - public static void swapCase(final StringSet source) - { - if (source != null) - { - StringList values = new StringList(source); - swapCase(values); - source.clear(); - source.addAll(values); - } - } - - /** - * Concatenates the string from an array to a string. - * - * @param source - * The string array to convert. - * - * @return A string concatenation of the argument. - */ - public static String toString(final String[] source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toString(); - } - - // - return result; - } - - /** - * To string. - * - * @param source - * the source - * @param prefix - * the prefix - * @param separator - * the separator - * @param postfix - * the postfix - * @return the string - */ - public static String toString(final String[] source, final String prefix, final String separator, final String postfix) - { - String result; - - if (source == null) - { - result = new StringList().toString(prefix, null, postfix); - } - else - { - result = new StringList(source).toString(prefix, separator, postfix); - } - - // - return result; - } - - /** - * To string. - * - * @param source - * the source - * @param prefix - * the prefix - * @param separator - * the separator - * @param postfix - * the postfix - * @return the string - */ - public static String toString(final StringList source, final String prefix, final String separator, final String postfix) - { - String result; - - if (source == null) - { - result = new StringList().toString(prefix, null, postfix); - } - else - { - result = source.toString(prefix, separator, postfix); - } - - // - return result; - } - - /** - * Converts a {@code Collection} to an array of {@code String}. - * - * @param source - * The string list to convert. - * - * @return The result of the conversion. - */ - public static String[] toStringArray(final Collection source) - { - String[] result; - - if (source == null) - { - result = new String[0]; - } - else - { - result = new StringList(source).toStringArray(); - } - - // - return result; - } - - /** - * Converts a {@code StringList} to an array of {@code String}. - * - * @param source - * The string list to convert. - * - * @return The result of the conversion. - */ - public static String[] toStringArray(final StringList source) - { - String[] result; - - if (source == null) - { - result = new String[0]; - } - else - { - result = source.toStringArray(); - } - - // - return result; - } - - /** - * Concatenates the string from an array to a string. - * - * @param source - * the source - * @return If argument is null then returns an empty string, otherwise - * returns a string concatenation of the argument. - */ - public static String toStringNotNull(final String[] source) - { - String result; - - result = toString(source); - - if (result == null) - { - result = ""; - } - - // - return result; - } - - /** - * To string separated by. - * - * @param source - * the source - * @param separator - * the separator - * @return the string - */ - public static String toStringSeparatedBy(final Collection source, final String separator) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringSeparatedBy(separator); - } - - // - return result; - } - - /** - * To string separated by. - * - * @param source - * the source - * @param separator - * the separator - * @return the string - */ - public static String toStringSeparatedBy(final String[] source, final String separator) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringSeparatedBy(separator); - } - - // - return result; - } - - /** - * To string separated by. - * - * @param source - * the source - * @param separator - * the separator - * @return the string - */ - public static String toStringSeparatedBy(final StringList source, final String separator) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = source.toStringSeparatedBy(separator); - } - - // - return result; - } - - /** - * To string with bracket. - * - * @param source - * the source - * @return the string - */ - public static String toStringWithBracket(final Collection source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithBracket(); - } - - // - return result; - } - - /** - * To string with bracket. - * - * @param source - * the source - * @return the string - */ - public static String toStringWithBracket(final String[] source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithBracket(); - } - - // - return result; - } - - /** - * To string with bracket. - * - * @param source - * the source - * @return the string - */ - public static String toStringWithBracket(final StringList source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = source.toStringWithBracket(); - } - - // - return result; - } - - /** - * To string with bracket not null. - * - * @param source - * the source - * @return the string - */ - public static String toStringWithBracketNotNull(final Collection source) - { - String result; - - result = toStringWithBracket(source); - - if (result == null) - { - result = ""; - } - - // - return result; - } - - /** - * To string with bracket not null. - * - * @param source - * the source - * @return the string - */ - public static String toStringWithBracketNotNull(final String[] source) - { - String result; - - result = toStringWithBracket(source); - - if (result == null) - { - result = ""; - } - - // - return result; - } - - /** - * To string with bracket not null. - * - * @param source - * the source - * @return the string - */ - public static String toStringWithBracketNotNull(final StringList source) - { - String result; - - result = toStringWithBracket(source); - - if (result == null) - { - result = ""; - } - - // - return result; - } - - /** - * To string with brackets. - * - * @param source - * the source - * @return the string - */ - public static String toStringWithBrackets(final Collection source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithBrackets(); - } - - // - return result; - } - - /** - * To string with brackets. - * - * @param source - * the source - * @return the string - */ - public static String toStringWithBrackets(final String[] source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithBrackets(); - } - - // - return result; - } - - /** - * To string with brackets. - * - * @param source - * the source - * @return the string - */ - public static String toStringWithBrackets(final StringList source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = source.toStringWithBrackets(); - } - - // - return result; - } - - /** - * To string with commas. - * - * @param source - * the source - * @return the string - */ - public static String toStringWithCommas(final Collection source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithCommas(); - } - - // - return result; - } - - /** - * To string with commas. - * - * @param source - * the source - * @return the string - */ - public static String toStringWithCommas(final String[] source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithCommas(); - } - - // - return result; - } - - /** - * To string with commas. - * - * @param source - * the source - * @return the string - */ - public static String toStringWithCommas(final StringList source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = source.toStringWithCommas(); - } - - // - return result; - } - - /** - * To string with french commas. - * - * @param source - * the source - * @return the string - */ - public static String toStringWithFrenchCommas(final Collection source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithFrenchCommas(); - } - - // - return result; - } - - /** - * To string with french commas. - * - * @param source - * the source - * @return the string - */ - public static String toStringWithFrenchCommas(final String[] source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithFrenchCommas(); - } - - // - return result; - } - - /** - * To string with french commas. - * - * @param source - * the source - * @return the string - */ - public static String toStringWithFrenchCommas(final StringList source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = source.toStringWithFrenchCommas(); - } - - // - return result; - } - - /** - * Uncapitalize. - * - * @param source - * the source - */ - public static void uncapitalize(final StringList source) - { - if (source != null) - { - for (int index = 0; index < source.size(); index++) - { - source.set(index, StringUtils.uncapitalize(source.get(index))); - } - } - } - - /** - * Uncapitalize. - * - * @param source - * the source - */ - public static void uncapitalize(final StringSet source) - { - if (source != null) - { - StringList values = new StringList(source); - uncapitalize(values); - source.clear(); - source.addAll(values); - } - } - - /** - * Upper case. - * - * @param source - * the source - */ - public static void upperCase(final StringList source) - { - if (source != null) - { - for (int index = 0; index < source.size(); index++) - { - source.set(index, StringUtils.upperCase(source.get(index))); - } - } - } - - public static void upperCase(final StringSet source) - { - if (source != null) - { - StringList values = new StringList(source); - upperCase(values); - source.clear(); - source.addAll(values); - } - } -} diff --git a/test/fr/devinsy/util/strings/StringsUtilsTest.java b/test/fr/devinsy/util/strings/StringsUtilsTest.java index 916b48e..41c0c09 100644 --- a/test/fr/devinsy/util/strings/StringsUtilsTest.java +++ b/test/fr/devinsy/util/strings/StringsUtilsTest.java @@ -54,11 +54,11 @@ public class StringsUtilsTest @Test public void testContainsBlank01() { - Assert.assertFalse(StringstUtils.containsBlank((Collection) null)); - Assert.assertFalse(StringstUtils.containsBlank(new StringList("aaa", "bbb", "ccc"))); - Assert.assertTrue(StringstUtils.containsBlank(new StringList("aaa", null, "ccc"))); - Assert.assertTrue(StringstUtils.containsBlank(new StringList("aaa", "", "ccc"))); - Assert.assertTrue(StringstUtils.containsBlank(new StringList("aaa", " ", "ccc"))); + Assert.assertFalse(StringsUtils.containsBlank((Collection) null)); + Assert.assertFalse(StringsUtils.containsBlank(new StringList("aaa", "bbb", "ccc"))); + Assert.assertTrue(StringsUtils.containsBlank(new StringList("aaa", null, "ccc"))); + Assert.assertTrue(StringsUtils.containsBlank(new StringList("aaa", "", "ccc"))); + Assert.assertTrue(StringsUtils.containsBlank(new StringList("aaa", " ", "ccc"))); } /** @@ -67,11 +67,11 @@ public class StringsUtilsTest @Test public void testContainsBlank02() { - Assert.assertFalse(StringstUtils.containsBlank((String[]) null)); - Assert.assertFalse(StringstUtils.containsBlank("aaa", "bbb", "ccc")); - Assert.assertTrue(StringstUtils.containsBlank("aaa", null, "ccc")); - Assert.assertTrue(StringstUtils.containsBlank("aaa", "", "ccc")); - Assert.assertTrue(StringstUtils.containsBlank("aaa", " ", "ccc")); + Assert.assertFalse(StringsUtils.containsBlank((String[]) null)); + Assert.assertFalse(StringsUtils.containsBlank("aaa", "bbb", "ccc")); + Assert.assertTrue(StringsUtils.containsBlank("aaa", null, "ccc")); + Assert.assertTrue(StringsUtils.containsBlank("aaa", "", "ccc")); + Assert.assertTrue(StringsUtils.containsBlank("aaa", " ", "ccc")); } /** @@ -80,18 +80,18 @@ public class StringsUtilsTest @Test public void testContainsBlank03() { - Assert.assertFalse(StringstUtils.containsBlank((ArrayList) null)); + Assert.assertFalse(StringsUtils.containsBlank((ArrayList) null)); ArrayList source = new ArrayList(); source.add("aaa"); source.add("bbb"); source.add("ccc"); - Assert.assertFalse(StringstUtils.containsBlank(source)); + Assert.assertFalse(StringsUtils.containsBlank(source)); source.set(1, null); - Assert.assertTrue(StringstUtils.containsBlank(source)); + Assert.assertTrue(StringsUtils.containsBlank(source)); source.set(1, ""); - Assert.assertTrue(StringstUtils.containsBlank(source)); + Assert.assertTrue(StringsUtils.containsBlank(source)); source.set(1, " "); - Assert.assertTrue(StringstUtils.containsBlank(source)); + Assert.assertTrue(StringsUtils.containsBlank(source)); } /** @@ -100,10 +100,10 @@ public class StringsUtilsTest @Test public void testContainsEmpty01() { - Assert.assertFalse(StringstUtils.containsEmpty((Collection) null)); - Assert.assertFalse(StringstUtils.containsEmpty(new StringList("aaa", "bbb", "ccc"))); - Assert.assertTrue(StringstUtils.containsEmpty(new StringList("aaa", null, "ccc"))); - Assert.assertTrue(StringstUtils.containsEmpty(new StringList("aaa", "", "ccc"))); + Assert.assertFalse(StringsUtils.containsEmpty((Collection) null)); + Assert.assertFalse(StringsUtils.containsEmpty(new StringList("aaa", "bbb", "ccc"))); + Assert.assertTrue(StringsUtils.containsEmpty(new StringList("aaa", null, "ccc"))); + Assert.assertTrue(StringsUtils.containsEmpty(new StringList("aaa", "", "ccc"))); } /** @@ -112,10 +112,10 @@ public class StringsUtilsTest @Test public void testContainsEmpty02() { - Assert.assertFalse(StringstUtils.containsEmpty((String[]) null)); - Assert.assertFalse(StringstUtils.containsEmpty("aaa", "bbb", "ccc")); - Assert.assertTrue(StringstUtils.containsEmpty("aaa", null, "ccc")); - Assert.assertTrue(StringstUtils.containsEmpty("aaa", "", "ccc")); + Assert.assertFalse(StringsUtils.containsEmpty((String[]) null)); + Assert.assertFalse(StringsUtils.containsEmpty("aaa", "bbb", "ccc")); + Assert.assertTrue(StringsUtils.containsEmpty("aaa", null, "ccc")); + Assert.assertTrue(StringsUtils.containsEmpty("aaa", "", "ccc")); } /** @@ -124,16 +124,16 @@ public class StringsUtilsTest @Test public void testContainsEmpty03() { - Assert.assertFalse(StringstUtils.containsEmpty((ArrayList) null)); + Assert.assertFalse(StringsUtils.containsEmpty((ArrayList) null)); ArrayList source = new ArrayList(); source.add("aaa"); source.add("bbb"); source.add("ccc"); - Assert.assertFalse(StringstUtils.containsEmpty(source)); + Assert.assertFalse(StringsUtils.containsEmpty(source)); source.set(1, null); - Assert.assertTrue(StringstUtils.containsEmpty(source)); + Assert.assertTrue(StringsUtils.containsEmpty(source)); source.set(1, ""); - Assert.assertTrue(StringstUtils.containsEmpty(source)); + Assert.assertTrue(StringsUtils.containsEmpty(source)); } /** @@ -142,9 +142,9 @@ public class StringsUtilsTest @Test public void testContainsNull01() { - Assert.assertFalse(StringstUtils.containsNull((Collection) null)); - Assert.assertFalse(StringstUtils.containsNull(new StringList("aaa", "bbb", "ccc"))); - Assert.assertTrue(StringstUtils.containsNull(new StringList("aaa", null, "ccc"))); + Assert.assertFalse(StringsUtils.containsNull((Collection) null)); + Assert.assertFalse(StringsUtils.containsNull(new StringList("aaa", "bbb", "ccc"))); + Assert.assertTrue(StringsUtils.containsNull(new StringList("aaa", null, "ccc"))); } /** @@ -153,9 +153,9 @@ public class StringsUtilsTest @Test public void testContainsNull02() { - Assert.assertFalse(StringstUtils.containsNull((String[]) null)); - Assert.assertFalse(StringstUtils.containsNull("aaa", "bbb", "ccc")); - Assert.assertTrue(StringstUtils.containsNull("aaa", null, "ccc")); + Assert.assertFalse(StringsUtils.containsNull((String[]) null)); + Assert.assertFalse(StringsUtils.containsNull("aaa", "bbb", "ccc")); + Assert.assertTrue(StringsUtils.containsNull("aaa", null, "ccc")); } /** @@ -164,14 +164,14 @@ public class StringsUtilsTest @Test public void testContainsNull03() { - Assert.assertFalse(StringstUtils.containsNull((ArrayList) null)); + Assert.assertFalse(StringsUtils.containsNull((ArrayList) null)); ArrayList source = new ArrayList(); source.add("aaa"); source.add("bbb"); source.add("ccc"); - Assert.assertFalse(StringstUtils.containsNull(source)); + Assert.assertFalse(StringsUtils.containsNull(source)); source.set(1, null); - Assert.assertTrue(StringstUtils.containsNull(source)); + Assert.assertTrue(StringsUtils.containsNull(source)); } /** @@ -181,13 +181,13 @@ public class StringsUtilsTest public void testFindSmallest01() { // TODO - Assert.assertFalse(StringstUtils.containsNull((ArrayList) null)); + Assert.assertFalse(StringsUtils.containsNull((ArrayList) null)); ArrayList source = new ArrayList(); source.add("aaa"); source.add("bbb"); source.add("ccc"); - Assert.assertFalse(StringstUtils.containsNull(source)); + Assert.assertFalse(StringsUtils.containsNull(source)); source.set(1, null); - Assert.assertTrue(StringstUtils.containsNull(source)); + Assert.assertTrue(StringsUtils.containsNull(source)); } }