From 7e8f61ea957986fb9fd3b3ddbbc00934ffad1c61 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Tue, 26 Dec 2017 00:35:32 +0100 Subject: [PATCH] Added StringUtils.equalsAny methods and tests. --- src/fr/devinsy/util/strings/StringsUtils.java | 38 +++++++++++++++++++ .../util/strings/StringsUtilsTest.java | 14 +++++++ 2 files changed, 52 insertions(+) diff --git a/src/fr/devinsy/util/strings/StringsUtils.java b/src/fr/devinsy/util/strings/StringsUtils.java index d583387..022a296 100644 --- a/src/fr/devinsy/util/strings/StringsUtils.java +++ b/src/fr/devinsy/util/strings/StringsUtils.java @@ -260,6 +260,44 @@ public class StringsUtils return result; } + /** + * Checks if is contained. + * + * @param token + * the token + * @param strings + * the strings + * @return true, if is contained + */ + public static boolean equalsAny(final String token, final String... strings) + { + boolean result; + + result = new StringList(strings).contains(token); + + // + return result; + } + + /** + * Checks if is contained ignore case. + * + * @param token + * the token + * @param strings + * the strings + * @return true, if is contained ignore case + */ + public static boolean equalsAnyIgnoreCase(final String token, final String... strings) + { + boolean result; + + result = new StringList(strings).containsIgnoreCase(token); + + // + return result; + } + /** * Find longest. * diff --git a/test/fr/devinsy/util/strings/StringsUtilsTest.java b/test/fr/devinsy/util/strings/StringsUtilsTest.java index 5402f92..aa9d2b6 100644 --- a/test/fr/devinsy/util/strings/StringsUtilsTest.java +++ b/test/fr/devinsy/util/strings/StringsUtilsTest.java @@ -189,4 +189,18 @@ public class StringsUtilsTest source.set(1, null); Assert.assertTrue(StringsUtils.containsNull(source)); } + + @Test + public void testIsContained01() + { + Assert.assertTrue(StringsUtils.equalsAny("abc", "aaa", "bbb", "abc")); + Assert.assertFalse(StringsUtils.equalsAny("abc", "aaa", "bbb", "aBc")); + } + + @Test + public void testIsContainedIgnoreCase01() + { + Assert.assertTrue(StringsUtils.equalsAnyIgnoreCase("abc", "aaa", "bbb", "abc")); + Assert.assertTrue(StringsUtils.equalsAnyIgnoreCase("abc", "aaa", "bbb", "aBc")); + } }