diff --git a/src/fr/devinsy/util/strings/StringListUtils.java b/src/fr/devinsy/util/strings/StringListUtils.java index a53461e..9ad0a7a 100644 --- a/src/fr/devinsy/util/strings/StringListUtils.java +++ b/src/fr/devinsy/util/strings/StringListUtils.java @@ -40,848 +40,999 @@ import java.util.Collection; */ public class StringListUtils { - public static final String DEFAULT_CHARSET_NAME = "UTF-8"; + public static final String DEFAULT_CHARSET_NAME = "UTF-8"; - /** + /** * - * @param target - * @return */ - public StringSet getComplement(final Collection alpha, final Collection bravo) - { - StringSet result; - - result = getDifference(bravo, alpha); - - // - return result; - } - - /** - * - * @param target - * @return - */ - public StringSet getDifference(final Collection alpha, final Collection bravo) - { - StringSet result; - - result = new StringSet(alpha); - result.removeAll(bravo); - - // - return result; - } - - /** - * - * @param target - * @return - */ - public 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; - } - - /** - * - * @param target - * @return - */ - public 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; - } - - /** - * - * @param target - * @return - */ - public StringSet getUnionOf(final Collection alpha, final Collection bravo) - { - StringSet result; - - result = new StringSet(alpha); - - for (String string : bravo) - { - result.add(string); - } - - // - return result; - } - - /** - * 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 - */ - public static String concatenate(final String source, final int multiplier) - { - String result; - - result = repeat(source, multiplier).toString(); - - // - return result; - } - - /** - * - * @param file - * @throws IOException - */ - public static StringList load(final File source) throws IOException - { - StringList result; - - result = load(source, DEFAULT_CHARSET_NAME); - - // - return result; - } - - /** - * - * @param file - * @throws IOException - */ - 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; - } - - /** - * - * @param file - * @return - * @throws IOException - */ - public static StringList load(final URL source) throws IOException - { - StringList result; - - result = load(source, DEFAULT_CHARSET_NAME); - - // - return result; - } - - /** - * - * @param file - * @throws IOException - */ - public static StringList load(final URL source, final String charsetName) throws IOException - { - StringList result; - - // - result = new StringList(); - - // - read(result, source.openStream(), charsetName); - - // - return result; - } - - /** - * - * @param file - * @throws IOException - */ - 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 - */ - 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; - } - - /** - * - * @param file - * @throws FileNotFoundException - * @throws UnsupportedEncodingException - */ - 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(); - } - } - - /** - * 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; - } - - /** - * - * @param prefix - * @param separator - * @param postfix - * @return - */ - 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; - } - - /** - * - * @param prefix - * @param separator - * @param postfix - * @return - */ - 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 strings - * The string array to convert. - * - * @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; - } - - /** - * - * @param source - * @return - */ - 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; - } - - /** - * - * @param strings - * @return - */ - 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; - } - - /** - * - * @param strings - * @return - */ - public static String toStringSeparatedBy(final StringList source, final String separator) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = source.toStringSeparatedBy(separator); - } - - // - return result; - } - - /** - * - * @param strings - * @return - */ - public static String toStringWithBracket(final Collection source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithBracket(); - } - - // - return result; - } - - /** - * - * @param strings - * @return - */ - public static String toStringWithBracket(final String[] source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithBracket(); - } - - // - return result; - } - - /** - * - * @param strings - * @return - */ - public static String toStringWithBracket(final StringList source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = source.toStringWithBracket(); - } - - // - return result; - } - - /** - * - * @param strings - * @return - */ - public static String toStringWithBracketNotNull(final Collection source) - { - String result; - - result = toStringWithBracket(source); - - if (result == null) - { - result = ""; - } - - // - return result; - } - - /** - * - * @param strings - * @return - */ - public static String toStringWithBracketNotNull(final String[] source) - { - String result; - - result = toStringWithBracket(source); - - if (result == null) - { - result = ""; - } - - // - return result; - } - - /** - * - * @param strings - * @return - */ - public static String toStringWithBracketNotNull(final StringList source) - { - String result; - - result = toStringWithBracket(source); - - if (result == null) - { - result = ""; - } - - // - return result; - } - - /** - * - * @param source - * @return - */ - public static String toStringWithBrackets(final Collection source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithBrackets(); - } - - // - return result; - } - - /** - * - * @param source - * @return - */ - public static String toStringWithBrackets(final String[] source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithBrackets(); - } - - // - return result; - } - - /** - * - * @param source - * @return - */ - public static String toStringWithBrackets(final StringList source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = source.toStringWithBrackets(); - } - - // - return result; - } - - /** - * - * @param source - * @return - */ - public static String toStringWithCommas(final Collection source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithCommas(); - } - - // - return result; - } - - /** - * - * @param source - * @return - */ - public static String toStringWithCommas(final String[] source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithCommas(); - } - - // - return result; - } - - /** - * - * @param source - * @return - */ - public static String toStringWithCommas(final StringList source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = source.toStringWithCommas(); - } - - // - return result; - } - - /** - * - * @param source - * @return - */ - public static String toStringWithFrenchCommas(final Collection source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithFrenchCommas(); - } - - // - return result; - } - - /** - * - * @param source - * @return - */ - public static String toStringWithFrenchCommas(final String[] source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = new StringList(source).toStringWithFrenchCommas(); - } - - // - return result; - } - - /** - * - * @param source - * @return - */ - public static String toStringWithFrenchCommas(final StringList source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = source.toStringWithFrenchCommas(); - } - - // - return result; - } + private StringListUtils() + { + } + + /** + * 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 + */ + public static String concatenate(final String source, final int multiplier) + { + String result; + + result = repeat(source, multiplier).toString(); + + // + return result; + } + + /** + * + * @param source + * @return + */ + 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; + } + + /** + * + * @param source + * @return + */ + public static boolean containsBlank(final String... source) + { + boolean result; + + if (source == null) + { + result = false; + } + else + { + result = new StringList(source).containsBlank(); + } + + // + return result; + } + + /** + * + * @param source + * @return + */ + 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; + } + + /** + * + * @param source + * @return + */ + public static boolean containsEmpty(final String... source) + { + boolean result; + + if (source == null) + { + result = false; + } + else + { + result = new StringList(source).containsEmpty(); + } + + // + return result; + } + + /** + * + * @param source + * @return + */ + 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; + } + + /** + * + * @param source + * @return + */ + public static boolean containsNull(final String... source) + { + boolean result; + + if (source == null) + { + result = false; + } + else + { + result = new StringList(source).containsNull(); + } + + // + return result; + } + + /** + * + * @param target + * @return + */ + public static StringSet getComplement(final Collection alpha, final Collection bravo) + { + StringSet result; + + result = getDifference(bravo, alpha); + + // + return result; + } + + /** + * + * @param target + * @return + */ + public static StringSet getDifference(final Collection alpha, final Collection bravo) + { + StringSet result; + + result = new StringSet(alpha); + result.removeAll(bravo); + + // + return result; + } + + /** + * + * @param target + * @return + */ + 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; + } + + /** + * + * @param target + * @return + */ + 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; + } + + /** + * + * @param target + * @return + */ + 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; + } + + /** + * + * @param file + * @throws IOException + */ + public static StringList load(final File source) throws IOException + { + StringList result; + + result = load(source, DEFAULT_CHARSET_NAME); + + // + return result; + } + + /** + * + * @param file + * @throws IOException + */ + 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; + } + + /** + * + * @param file + * @return + * @throws IOException + */ + public static StringList load(final URL source) throws IOException + { + StringList result; + + result = load(source, DEFAULT_CHARSET_NAME); + + // + return result; + } + + /** + * + * @param file + * @throws IOException + */ + public static StringList load(final URL source, final String charsetName) throws IOException + { + StringList result; + + // + result = new StringList(); + + // + read(result, source.openStream(), charsetName); + + // + return result; + } + + /** + * + * @param file + * @throws IOException + */ + 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 + */ + 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; + } + + /** + * + * @param file + * @throws FileNotFoundException + * @throws UnsupportedEncodingException + */ + 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(); + } + } + + /** + * 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; + } + + /** + * + * @param prefix + * @param separator + * @param postfix + * @return + */ + 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; + } + + /** + * + * @param prefix + * @param separator + * @param postfix + * @return + */ + 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 strings + * The string array to convert. + * + * @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; + } + + /** + * + * @param source + * @return + */ + 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; + } + + /** + * + * @param strings + * @return + */ + 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; + } + + /** + * + * @param strings + * @return + */ + public static String toStringSeparatedBy(final StringList source, final String separator) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = source.toStringSeparatedBy(separator); + } + + // + return result; + } + + /** + * + * @param strings + * @return + */ + public static String toStringWithBracket(final Collection source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = new StringList(source).toStringWithBracket(); + } + + // + return result; + } + + /** + * + * @param strings + * @return + */ + public static String toStringWithBracket(final String[] source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = new StringList(source).toStringWithBracket(); + } + + // + return result; + } + + /** + * + * @param strings + * @return + */ + public static String toStringWithBracket(final StringList source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = source.toStringWithBracket(); + } + + // + return result; + } + + /** + * + * @param strings + * @return + */ + public static String toStringWithBracketNotNull(final Collection source) + { + String result; + + result = toStringWithBracket(source); + + if (result == null) + { + result = ""; + } + + // + return result; + } + + /** + * + * @param strings + * @return + */ + public static String toStringWithBracketNotNull(final String[] source) + { + String result; + + result = toStringWithBracket(source); + + if (result == null) + { + result = ""; + } + + // + return result; + } + + /** + * + * @param strings + * @return + */ + public static String toStringWithBracketNotNull(final StringList source) + { + String result; + + result = toStringWithBracket(source); + + if (result == null) + { + result = ""; + } + + // + return result; + } + + /** + * + * @param source + * @return + */ + public static String toStringWithBrackets(final Collection source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = new StringList(source).toStringWithBrackets(); + } + + // + return result; + } + + /** + * + * @param source + * @return + */ + public static String toStringWithBrackets(final String[] source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = new StringList(source).toStringWithBrackets(); + } + + // + return result; + } + + /** + * + * @param source + * @return + */ + public static String toStringWithBrackets(final StringList source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = source.toStringWithBrackets(); + } + + // + return result; + } + + /** + * + * @param source + * @return + */ + public static String toStringWithCommas(final Collection source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = new StringList(source).toStringWithCommas(); + } + + // + return result; + } + + /** + * + * @param source + * @return + */ + public static String toStringWithCommas(final String[] source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = new StringList(source).toStringWithCommas(); + } + + // + return result; + } + + /** + * + * @param source + * @return + */ + public static String toStringWithCommas(final StringList source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = source.toStringWithCommas(); + } + + // + return result; + } + + /** + * + * @param source + * @return + */ + public static String toStringWithFrenchCommas(final Collection source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = new StringList(source).toStringWithFrenchCommas(); + } + + // + return result; + } + + /** + * + * @param source + * @return + */ + public static String toStringWithFrenchCommas(final String[] source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = new StringList(source).toStringWithFrenchCommas(); + } + + // + return result; + } + + /** + * + * @param source + * @return + */ + public static String toStringWithFrenchCommas(final StringList source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = source.toStringWithFrenchCommas(); + } + + // + return result; + } } diff --git a/test/fr/devinsy/util/StringListTest.java b/test/fr/devinsy/util/strings/StringListTest.java similarity index 99% rename from test/fr/devinsy/util/StringListTest.java rename to test/fr/devinsy/util/strings/StringListTest.java index bb467d6..9afe379 100644 --- a/test/fr/devinsy/util/StringListTest.java +++ b/test/fr/devinsy/util/strings/StringListTest.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with Devinsy-utils. If not, see */ -package fr.devinsy.util; +package fr.devinsy.util.strings; import java.util.Iterator; diff --git a/test/fr/devinsy/util/strings/StringListUtilsTest.java b/test/fr/devinsy/util/strings/StringListUtilsTest.java new file mode 100644 index 0000000..097d37f --- /dev/null +++ b/test/fr/devinsy/util/strings/StringListUtilsTest.java @@ -0,0 +1,174 @@ +/** + * Copyright (C) 2013,2014 Christian Pierre MOMON + * + * This file is part of Devinsy-utils. + * + * Devinsy-utils 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-utils 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-utils. If not, see + */ +package fr.devinsy.util.strings; + +import java.util.ArrayList; +import java.util.Collection; + +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * + * @author Christian P. Momon + */ +public class StringListUtilsTest +{ + private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(StringListUtilsTest.class); + + /** + * + */ + @Before + public void before() + { + BasicConfigurator.configure(); + Logger.getRootLogger().setLevel(Level.ERROR); + } + + /** + * + */ + @Test + public void testContainsBlank01() + { + Assert.assertFalse(StringListUtils.containsBlank((Collection) null)); + Assert.assertFalse(StringListUtils.containsBlank(new StringList("aaa", "bbb", "ccc"))); + Assert.assertTrue(StringListUtils.containsBlank(new StringList("aaa", null, "ccc"))); + Assert.assertTrue(StringListUtils.containsBlank(new StringList("aaa", "", "ccc"))); + Assert.assertTrue(StringListUtils.containsBlank(new StringList("aaa", " ", "ccc"))); + } + + /** + * + */ + @Test + public void testContainsBlank02() + { + Assert.assertFalse(StringListUtils.containsBlank((String[]) null)); + Assert.assertFalse(StringListUtils.containsBlank("aaa", "bbb", "ccc")); + Assert.assertTrue(StringListUtils.containsBlank("aaa", null, "ccc")); + Assert.assertTrue(StringListUtils.containsBlank("aaa", "", "ccc")); + Assert.assertTrue(StringListUtils.containsBlank("aaa", " ", "ccc")); + } + + /** + * + */ + @Test + public void testContainsBlank03() + { + Assert.assertFalse(StringListUtils.containsBlank((ArrayList) null)); + ArrayList source = new ArrayList(); + source.add("aaa"); + source.add("bbb"); + source.add("ccc"); + Assert.assertFalse(StringListUtils.containsBlank(source)); + source.set(1, null); + Assert.assertTrue(StringListUtils.containsBlank(source)); + source.set(1, ""); + Assert.assertTrue(StringListUtils.containsBlank(source)); + source.set(1, " "); + Assert.assertTrue(StringListUtils.containsBlank(source)); + } + + /** + * + */ + @Test + public void testContainsEmpty01() + { + Assert.assertFalse(StringListUtils.containsEmpty((Collection) null)); + Assert.assertFalse(StringListUtils.containsEmpty(new StringList("aaa", "bbb", "ccc"))); + Assert.assertTrue(StringListUtils.containsEmpty(new StringList("aaa", null, "ccc"))); + Assert.assertTrue(StringListUtils.containsEmpty(new StringList("aaa", "", "ccc"))); + } + + /** + * + */ + @Test + public void testContainsEmpty02() + { + Assert.assertFalse(StringListUtils.containsEmpty((String[]) null)); + Assert.assertFalse(StringListUtils.containsEmpty("aaa", "bbb", "ccc")); + Assert.assertTrue(StringListUtils.containsEmpty("aaa", null, "ccc")); + Assert.assertTrue(StringListUtils.containsEmpty("aaa", "", "ccc")); + } + + /** + * + */ + @Test + public void testContainsEmpty03() + { + Assert.assertFalse(StringListUtils.containsEmpty((ArrayList) null)); + ArrayList source = new ArrayList(); + source.add("aaa"); + source.add("bbb"); + source.add("ccc"); + Assert.assertFalse(StringListUtils.containsEmpty(source)); + source.set(1, null); + Assert.assertTrue(StringListUtils.containsEmpty(source)); + source.set(1, ""); + Assert.assertTrue(StringListUtils.containsEmpty(source)); + } + + /** + * + */ + @Test + public void testContainsNull01() + { + Assert.assertFalse(StringListUtils.containsNull((Collection) null)); + Assert.assertFalse(StringListUtils.containsNull(new StringList("aaa", "bbb", "ccc"))); + Assert.assertTrue(StringListUtils.containsNull(new StringList("aaa", null, "ccc"))); + } + + /** + * + */ + @Test + public void testContainsNull02() + { + Assert.assertFalse(StringListUtils.containsNull((String[]) null)); + Assert.assertFalse(StringListUtils.containsNull("aaa", "bbb", "ccc")); + Assert.assertTrue(StringListUtils.containsNull("aaa", null, "ccc")); + } + + /** + * + */ + @Test + public void testContainsNull03() + { + Assert.assertFalse(StringListUtils.containsNull((ArrayList) null)); + ArrayList source = new ArrayList(); + source.add("aaa"); + source.add("bbb"); + source.add("ccc"); + Assert.assertFalse(StringListUtils.containsNull(source)); + source.set(1, null); + Assert.assertTrue(StringListUtils.containsNull(source)); + } +}