Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 51408 invoked from network); 17 Jul 2004 21:38:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 17 Jul 2004 21:38:37 -0000 Received: (qmail 12983 invoked by uid 500); 17 Jul 2004 21:38:35 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 12939 invoked by uid 500); 17 Jul 2004 21:38:34 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 12925 invoked by uid 500); 17 Jul 2004 21:38:34 -0000 Received: (qmail 12922 invoked by uid 99); 17 Jul 2004 21:38:34 -0000 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Sat, 17 Jul 2004 14:38:34 -0700 Received: (qmail 51382 invoked by uid 1529); 17 Jul 2004 21:38:33 -0000 Date: 17 Jul 2004 21:38:33 -0000 Message-ID: <20040717213833.51381.qmail@minotaur.apache.org> From: scolebourne@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections CollectionUtils.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N scolebourne 2004/07/17 14:38:33 Modified: collections RELEASE-NOTES.html collections/src/test/org/apache/commons/collections TestCollectionUtils.java collections/src/java/org/apache/commons/collections CollectionUtils.java Log: CollectionUtils.addIgnoreNull new method bug 30020, from Rafael U. C. Afonso Revision Changes Path 1.69 +3 -3 jakarta-commons/collections/RELEASE-NOTES.html Index: RELEASE-NOTES.html =================================================================== RCS file: /home/cvs/jakarta-commons/collections/RELEASE-NOTES.html,v retrieving revision 1.68 retrieving revision 1.69 diff -u -r1.68 -r1.69 --- RELEASE-NOTES.html 17 Jul 2004 21:02:47 -0000 1.68 +++ RELEASE-NOTES.html 17 Jul 2004 21:38:33 -0000 1.69 @@ -34,12 +34,12 @@

NEW CLASSES

    -
  • LoopingListIterator - When the end of the list is reached the iteration continues from the start
  • +
  • LoopingListIterator - When the end of the list is reached the iteration continues from the start [30166]

ENHANCEMENTS

    -
  • ........
  • +
  • CollectionUtils.addIgnoreNull - Adds to the collection if the value being added is not null [30020]

BUG FIXES

@@ -49,5 +49,5 @@

JAVADOC

    -
  • ........
  • +
  • MapUtils.safeAddToMap - Better comment
1.40 +17 -1 jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollectionUtils.java Index: TestCollectionUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollectionUtils.java,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- TestCollectionUtils.java 26 Jun 2004 10:00:42 -0000 1.39 +++ TestCollectionUtils.java 17 Jul 2004 21:38:33 -0000 1.40 @@ -965,6 +965,22 @@ assertEquals(new Integer(4), set.iterator().next()); } + //----------------------------------------------------------------------- + public void testAddIgnoreNull() { + Set set = new HashSet(); + set.add("1"); + set.add("2"); + set.add("3"); + assertEquals(false, CollectionUtils.addIgnoreNull(set, null)); + assertEquals(3, set.size()); + assertEquals(false, CollectionUtils.addIgnoreNull(set, "1")); + assertEquals(3, set.size()); + assertEquals(true, CollectionUtils.addIgnoreNull(set, "4")); + assertEquals(4, set.size()); + assertEquals(true, set.contains("4")); + } + + //----------------------------------------------------------------------- public void testPredicatedCollection() { Predicate predicate = new Predicate() { public boolean evaluate(Object o) { 1.62 +20 -7 jakarta-commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java Index: CollectionUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java,v retrieving revision 1.61 retrieving revision 1.62 diff -u -r1.61 -r1.62 --- CollectionUtils.java 27 Apr 2004 20:00:18 -0000 1.61 +++ CollectionUtils.java 17 Jul 2004 21:38:33 -0000 1.62 @@ -633,11 +633,24 @@ return outputCollection; } + //----------------------------------------------------------------------- + /** + * Adds an element to the collection unless the element is null. + * + * @param collection the collection to add to, must not be null + * @param object the object to add, if null it will not be added + * @return true if the collection changed + * @throws NullPointerException if the collection is null + */ + public static boolean addIgnoreNull(Collection collection, Object object) { + return (object == null ? false : collection.add(object)); + } + /** * Adds all elements in the iteration to the given collection. * - * @param collection the collection to add to - * @param iterator the iterator of elements to add, may not be null + * @param collection the collection to add to, must not be null + * @param iterator the iterator of elements to add, must not be null * @throws NullPointerException if the collection or iterator is null */ public static void addAll(Collection collection, Iterator iterator) { @@ -649,8 +662,8 @@ /** * Adds all elements in the enumeration to the given collection. * - * @param collection the collection to add to - * @param enumeration the enumeration of elements to add, may not be null + * @param collection the collection to add to, must not be null + * @param enumeration the enumeration of elements to add, must not be null * @throws NullPointerException if the collection or enumeration is null */ public static void addAll(Collection collection, Enumeration enumeration) { @@ -662,8 +675,8 @@ /** * Adds all elements in the array to the given collection. * - * @param collection the collection to add to, may not be null - * @param elements the array of elements to add, may not be null + * @param collection the collection to add to, must not be null + * @param elements the array of elements to add, must not be null * @throws NullPointerException if the collection or array is null */ public static void addAll(Collection collection, Object[] elements) { --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org