From 928950c9bf3a61fb51d1c291526ee0e1f8c8baf6 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 1 Nov 2009 17:10:02 +0000 Subject: [PATCH] LANG-493 - Remove allElementsOfType as generics handles this pretty well now git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@831709 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/lang/Validate.java | 57 ------------------- .../org/apache/commons/lang/ValidateTest.java | 40 ------------- 2 files changed, 97 deletions(-) diff --git a/src/java/org/apache/commons/lang/Validate.java b/src/java/org/apache/commons/lang/Validate.java index 5387dd047..78f363fba 100644 --- a/src/java/org/apache/commons/lang/Validate.java +++ b/src/java/org/apache/commons/lang/Validate.java @@ -550,63 +550,6 @@ public class Validate { return collection; } - // allElementsOfType collection - //--------------------------------------------------------------------------------- - - /** - *

Validate an argument, throwing IllegalArgumentException - * if the argument collection is null or has elements that - * are not of type clazz or a subclass.

- * - *
-     * Validate.allElementsOfType(collection, String.class, "Collection has invalid elements");
-     * 
- * - * @param collection the collection to check, not null - * @param clazz the Class which the collection's elements are expected to be, not null - * @param message the exception message if the Collection has elements not of type clazz - * @since 2.1 - */ - public static void allElementsOfType(Collection collection, Class clazz, String message) { - Validate.notNull(collection); - Validate.notNull(clazz); - for (Iterator it = collection.iterator(); it.hasNext(); ) { - if (clazz.isInstance(it.next()) == false) { - throw new IllegalArgumentException(message); - } - } - } - - /** - *

- * Validate an argument, throwing IllegalArgumentException if the argument collection is - * null or has elements that are not of type clazz or a subclass. - *

- * - *
-     * Validate.allElementsOfType(collection, String.class);
-     * 
- * - *

- * The message in the exception is 'The validated collection contains an element not of type clazz at index: '. - *

- * - * @param collection the collection to check, not null - * @param clazz the Class which the collection's elements are expected to be, not null - * @since 2.1 - */ - public static void allElementsOfType(Collection collection, Class clazz) { - Validate.notNull(collection); - Validate.notNull(clazz); - int i = 0; - for (Iterator it = collection.iterator(); it.hasNext(); i++) { - if (clazz.isInstance(it.next()) == false) { - throw new IllegalArgumentException("The validated collection contains an element not of type " - + clazz.getName() + " at index: " + i); - } - } - } - // validIndex array //--------------------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/lang/ValidateTest.java b/src/test/org/apache/commons/lang/ValidateTest.java index 2b17f5dee..bc9caa07c 100644 --- a/src/test/org/apache/commons/lang/ValidateTest.java +++ b/src/test/org/apache/commons/lang/ValidateTest.java @@ -624,46 +624,6 @@ public class ValidateTest extends TestCase { assertSame(coll, test); } - //----------------------------------------------------------------------- - //----------------------------------------------------------------------- - public void testAllElementsOfType() { - List coll = new ArrayList(); - coll.add("a"); - coll.add("b"); - Validate.allElementsOfType(coll, String.class, "MSG"); - Validate.allElementsOfType(coll, String.class); - try { - Validate.allElementsOfType(coll, Integer.class, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - coll.set(1, Boolean.FALSE); - try { - Validate.allElementsOfType(coll, String.class); - fail("Expecting IllegalArgumentException"); - } catch (IllegalArgumentException ex) { - assertEquals("The validated collection contains an element not of type java.lang.String at index: 1", ex.getMessage()); - } - - coll = new ArrayList(); - coll.add(new Integer(5)); - coll.add(new Double(2.0d)); - Validate.allElementsOfType(coll, Number.class, "MSG"); - try { - Validate.allElementsOfType(coll, Integer.class, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.allElementsOfType(coll, Double.class, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - //----------------------------------------------------------------------- //----------------------------------------------------------------------- public void testConstructor() {