Author: scolebourne Date: Sun Nov 1 17:10:02 2009 New Revision: 831709 URL: http://svn.apache.org/viewvc?rev=831709&view=rev Log: LANG-493 - Remove allElementsOfType as generics handles this pretty well now
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/Validate.java commons/proper/lang/trunk/src/test/org/apache/commons/lang/ValidateTest.java Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/Validate.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/Validate.java?rev=831709&r1=831708&r2=831709&view=diff ============================================================================== --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/Validate.java (original) +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/Validate.java Sun Nov 1 17:10:02 2009 @@ -550,63 +550,6 @@ return collection; } - // allElementsOfType collection - //--------------------------------------------------------------------------------- - - /** - * <p>Validate an argument, throwing <code>IllegalArgumentException</code> - * if the argument collection is <code>null</code> or has elements that - * are not of type <code>clazz</code> or a subclass.</p> - * - * <pre> - * Validate.allElementsOfType(collection, String.class, "Collection has invalid elements"); - * </pre> - * - * @param collection the collection to check, not null - * @param clazz the <code>Class</code> which the collection's elements are expected to be, not null - * @param message the exception message if the <code>Collection</code> has elements not of type <code>clazz</code> - * @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); - } - } - } - - /** - * <p> - * Validate an argument, throwing <code>IllegalArgumentException</code> if the argument collection is - * <code>null</code> or has elements that are not of type <code>clazz</code> or a subclass. - * </p> - * - * <pre> - * Validate.allElementsOfType(collection, String.class); - * </pre> - * - * <p> - * The message in the exception is 'The validated collection contains an element not of type clazz at index: '. - * </p> - * - * @param collection the collection to check, not null - * @param clazz the <code>Class</code> 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 //--------------------------------------------------------------------------------- Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/ValidateTest.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/ValidateTest.java?rev=831709&r1=831708&r2=831709&view=diff ============================================================================== --- commons/proper/lang/trunk/src/test/org/apache/commons/lang/ValidateTest.java (original) +++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/ValidateTest.java Sun Nov 1 17:10:02 2009 @@ -626,46 +626,6 @@ //----------------------------------------------------------------------- //----------------------------------------------------------------------- - public void testAllElementsOfType() { - List<Object> coll = new ArrayList<Object>(); - 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<Object>(); - 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() { assertNotNull(new Validate()); Constructor<?>[] cons = Validate.class.getDeclaredConstructors();