diff --git a/src/fr/devinsy/util/strings/StringList.java b/src/fr/devinsy/util/strings/StringList.java index fb9bb79..0ef2112 100644 --- a/src/fr/devinsy/util/strings/StringList.java +++ b/src/fr/devinsy/util/strings/StringList.java @@ -660,6 +660,51 @@ public class StringList extends ArrayList implements CharSequence, Appen return result; } + /** + * Contains. + * + * @param target + * the target + * @return true, if successful + */ + public boolean contains(final CharSequence target) + { + boolean result; + + if (super.contains(target)) + { + result = true; + } + else + { + result = super.contains(target.toString()); + } + + // + return result; + } + + /* (non-Javadoc) + * @see java.util.ArrayList#contains(java.lang.Object) + */ + @Override + public boolean contains(final Object target) + { + boolean result; + + if (super.contains(target)) + { + result = true; + } + else + { + result = super.contains(target.toString()); + } + + // + return result; + } + /** * Contains any. * @@ -752,6 +797,98 @@ public class StringList extends ArrayList implements CharSequence, Appen return result; } + /** + * Contains any ignore case. + * + * @param target + * the target + * @return true, if successful + */ + public boolean containsAnyIgnoreCase(final Collection target) + { + boolean result; + + if (target == null) + { + result = false; + } + else + { + boolean ended = false; + Iterator iterator = target.iterator(); + result = false; + while (!ended) + { + if (iterator.hasNext()) + { + String current = iterator.next(); + + if (this.containsIgnoreCase(current)) + { + ended = true; + result = true; + } + } + else + { + ended = true; + result = false; + } + } + } + + // + return result; + } + + /** + * Contains any ignore case. + * + * @param target + * the target + * @return true, if successful + */ + public boolean containsAnyIgnoreCase(final String... target) + { + boolean result; + + if (target == null) + { + result = false; + } + else + { + boolean ended = false; + int index = 0; + result = false; + while (!ended) + { + if (index < target.length) + { + String current = target[index]; + + if (this.containsIgnoreCase(current)) + { + ended = true; + result = true; + } + else + { + index += 1; + } + } + else + { + ended = true; + result = false; + } + } + } + + // + return result; + } + /** * Contains blank. * @@ -822,6 +959,43 @@ public class StringList extends ArrayList implements CharSequence, Appen return result; } + /** + * Contains ignore case. + * + * @param target + * the target + * @return true, if successful + */ + public boolean containsIgnoreCase(final CharSequence target) + { + boolean result; + + boolean ended = false; + Iterator iterator = iterator(); + result = false; + while (!ended) + { + if (iterator.hasNext()) + { + String line = iterator.next(); + + if (StringUtils.equalsIgnoreCase(target, line)) + { + ended = true; + result = true; + } + } + else + { + ended = true; + result = false; + } + } + + // + return result; + } + /** * Contains null. * diff --git a/test/fr/devinsy/util/strings/StringListTest.java b/test/fr/devinsy/util/strings/StringListTest.java index dbfa7fe..c9b2b37 100644 --- a/test/fr/devinsy/util/strings/StringListTest.java +++ b/test/fr/devinsy/util/strings/StringListTest.java @@ -209,6 +209,205 @@ public class StringListTest this.logger.debug("===== test done."); } + /** + * Test contains 01. + */ + @Test + public void testContains01() + { + // + this.logger.debug("===== test starting..."); + + StringList buffer = new StringList(); + buffer.append("abc"); + buffer.append("def"); + buffer.append("ghi"); + + Assert.assertTrue(buffer.contains("abc")); + Assert.assertTrue(buffer.contains("def")); + Assert.assertTrue(buffer.contains("ghi")); + + Assert.assertFalse(buffer.contains("lmn")); + + // + this.logger.debug("===== test done."); + } + + /** + * Test contains 02. + */ + @Test + public void testContains02() + { + // + this.logger.debug("===== test starting..."); + + StringList buffer = new StringList(); + buffer.append("abc"); + buffer.append("def"); + buffer.append("ghi"); + + Assert.assertTrue(buffer.contains(new StringBuffer().append("abc").toString())); + Assert.assertTrue(buffer.contains(new StringBuffer().append("def"))); + Assert.assertTrue(buffer.contains(new StringBuffer().append("ghi"))); + + Assert.assertFalse(buffer.contains(new StringBuffer().append("lmn"))); + + // + this.logger.debug("===== test done."); + } + + /** + * Test contains 02. + */ + @Test + public void testContains03() + { + // + this.logger.debug("===== test starting..."); + + StringList buffer = new StringList(); + buffer.append("abc"); + buffer.append("def"); + buffer.append("ghi"); + + Assert.assertTrue(buffer.contains(new StringList().append("abc"))); + Assert.assertTrue(buffer.contains(new StringList().append("def"))); + Assert.assertTrue(buffer.contains(new StringList().append("ghi"))); + + Assert.assertFalse(buffer.contains(new StringList().append("lmn"))); + + // + this.logger.debug("===== test done."); + } + + /** + * Test contains any 01. + */ + @Test + public void testContainsAny01() + { + // + this.logger.debug("===== test starting..."); + + StringList buffer = new StringList(); + buffer.append("abc"); + buffer.append("def"); + buffer.append("ghi"); + + Assert.assertTrue(buffer.containsAny("abc")); + Assert.assertTrue(buffer.containsAny("def")); + Assert.assertTrue(buffer.containsAny("ghi")); + + Assert.assertFalse(buffer.containsAny("aaa")); + + // + this.logger.debug("===== test done."); + } + + /** + * Test contains any 02. + */ + @Test + public void testContainsAny02() + { + // + this.logger.debug("===== test starting..."); + + StringList buffer = new StringList(); + buffer.append("abc"); + buffer.append("def"); + buffer.append("ghi"); + + Assert.assertTrue(buffer.containsAny("aaa", "bbb", "abc")); + Assert.assertTrue(buffer.containsAny("aaa", "bbb", "def")); + Assert.assertTrue(buffer.containsAny("aaa", "bbb", "ghi")); + + Assert.assertFalse(buffer.containsAny("aaa", "bbb", "ccc")); + + // + this.logger.debug("===== test done."); + } + + /** + * Test contains any 03. + */ + @Test + public void testContainsAny03() + { + // + this.logger.debug("===== test starting..."); + + StringList buffer = new StringList(); + buffer.append("abc"); + buffer.append("def"); + buffer.append("ghi"); + + Assert.assertTrue(buffer.containsAny(new StringList("aaa", "bbb", "abc"))); + Assert.assertTrue(buffer.containsAny(new StringList("aaa", "bbb", "def"))); + Assert.assertTrue(buffer.containsAny(new StringList("aaa", "bbb", "ghi"))); + + Assert.assertFalse(buffer.containsAny(new StringList("aaa", "bbb", "aBc"))); + Assert.assertFalse(buffer.containsAny(new StringList("aaa", "bbb", "ccc"))); + + // + this.logger.debug("===== test done."); + } + + /** + * Test contains any 01. + */ + @Test + public void testContainsAnyIgnoreCase01() + { + // + this.logger.debug("===== test starting..."); + + StringList buffer = new StringList(); + buffer.append("abc"); + buffer.append("def"); + buffer.append("ghi"); + + Assert.assertTrue(buffer.containsAnyIgnoreCase("aaa", "bbb", "abc")); + Assert.assertTrue(buffer.containsAnyIgnoreCase("aaa", "bbb", "dbf")); + Assert.assertTrue(buffer.containsAnyIgnoreCase("aaa", "bbb", "ghi")); + Assert.assertTrue(buffer.containsAnyIgnoreCase("aaa", "bbb", "Abc")); + Assert.assertTrue(buffer.containsAnyIgnoreCase("aaa", "bbb", "dEf")); + Assert.assertTrue(buffer.containsAnyIgnoreCase("aaa", "bbb", "ghI")); + + Assert.assertFalse(buffer.containsAnyIgnoreCase("aaa", "bbb", "ccc")); + + // + this.logger.debug("===== test done."); + } + + /** + * Test contains any ignore case 02. + */ + @Test + public void testContainsAnyIgnoreCase02() + { + // + this.logger.debug("===== test starting..."); + + StringList buffer = new StringList(); + buffer.append("abc"); + buffer.append("def"); + buffer.append("ghi"); + + Assert.assertTrue(buffer.containsAnyIgnoreCase(new StringList("aaa", "bbb", "abc"))); + Assert.assertTrue(buffer.containsAnyIgnoreCase(new StringList("aaa", "bbb", "def"))); + Assert.assertTrue(buffer.containsAnyIgnoreCase(new StringList("aaa", "bbb", "ghi"))); + Assert.assertTrue(buffer.containsAnyIgnoreCase(new StringList("aaa", "bbb", "Abc"))); + Assert.assertTrue(buffer.containsAnyIgnoreCase(new StringList("aaa", "bbb", "dEf"))); + Assert.assertTrue(buffer.containsAnyIgnoreCase(new StringList("aaa", "bbb", "ghI"))); + + Assert.assertFalse(buffer.containsAnyIgnoreCase(new StringList("aaa", "bbb", "ccc"))); + + // + this.logger.debug("===== test done."); + } + /** * Test iterator of char 01. */