From d2d0990e052bc5646ce41abacf57a3882f60ab82 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sat, 23 May 2015 02:55:38 +0200 Subject: [PATCH] Adds some strins methods in StringlistUtils. --- .../devinsy/util/strings/StringListUtils.java | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/src/fr/devinsy/util/strings/StringListUtils.java b/src/fr/devinsy/util/strings/StringListUtils.java index 253af81..ab07b94 100644 --- a/src/fr/devinsy/util/strings/StringListUtils.java +++ b/src/fr/devinsy/util/strings/StringListUtils.java @@ -18,6 +18,8 @@ */ package fr.devinsy.util.strings; +import java.util.Collection; + /** * The {@code StringUtils} class defines helper methods to string collection. * @@ -163,6 +165,34 @@ public class StringListUtils return result; } + /** + * + * @param strings + * @return + */ + public static String toStringWithBracket(final Collection strings) + { + String result; + + if (strings == null) + { + result = null; + } + else + { + StringList buffer = new StringList(); + + buffer.append("["); + buffer.append(toStringWithCommas(strings)); + buffer.append("]"); + + result = buffer.toString(); + } + + // + return result; + } + /** * * @param strings @@ -191,6 +221,26 @@ public class StringListUtils return result; } + /** + * + * @param strings + * @return + */ + public static String toStringWithBracketNotNull(final Collection strings) + { + String result; + + result = toStringWithBrackets(strings); + + if (result == null) + { + result = ""; + } + + // + return result; + } + /** * * @param strings @@ -211,6 +261,35 @@ public class StringListUtils return result; } + /** + * + * @param source + * @return + */ + public static String toStringWithBrackets(final Collection source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + StringList buffer = new StringList(); + + for (String string : source) + { + buffer.append("[").append(string).append("]"); + } + + result = buffer.toString(); + } + + // + return result; + } + /** * * @param source @@ -240,6 +319,28 @@ public class StringListUtils return result; } + /** + * + * @param source + * @return + */ + public static String toStringWithCommas(final Collection source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = new StringList(source).toStringSeparatedBy(","); + } + + // + return result; + } + /** * * @param source @@ -262,6 +363,28 @@ public class StringListUtils return result; } + /** + * + * @param source + * @return + */ + public static String toStringWithFrenchCommas(final Collection source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = new StringList(source).toStringSeparatedBy(", "); + } + + // + return result; + } + /** * * @param source