[utilities COMMIT] in /java-support/trunk: pom.xml src/main/java/net/shibboleth/utilities/java/support/chrono/Stopwat...

noreply at shibboleth.net noreply at shibboleth.net
Tue Dec 27 13:11:37 GMT 2011


Author: lajoie
Date: Tue Dec 27 13:11:37 2011
New Revision: 179

URL: http://svn.shibboleth.net/view/utilities?rev=179&view=rev
Log:
Remove codec package, just use commons-codec
Stopwatch unit tests and bug fix

Added:
    java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/chrono/
    java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/chrono/StopwatchTest.java   (with props)
Removed:
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/codec/
Modified:
    java-support/trunk/pom.xml
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/chrono/Stopwatch.java
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/CollectionSupport.java
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/security/RandomIdentifierGenerationStrategy.java

Modified: java-support/trunk/pom.xml
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/pom.xml?rev=179&r1=178&r2=179&view=diff
==============================================================================
--- java-support/trunk/pom.xml (original)
+++ java-support/trunk/pom.xml Tue Dec 27 13:11:37 2011
@@ -24,6 +24,12 @@
             <artifactId>httpclient</artifactId>
             <optional>true</optional>
         </dependency>
+        <dependency>
+            <!-- Required by RandomIdentifierGenerationStrategy  -->
+            <groupId>commons-codec</groupId>
+            <artifactId>commons-codec</artifactId>
+            <optional>true</optional>
+        </dependency>
 
         <!-- Provided Dependencies -->
 

Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/chrono/Stopwatch.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/chrono/Stopwatch.java?rev=179&r1=178&r2=179&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/chrono/Stopwatch.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/chrono/Stopwatch.java Tue Dec 27 13:11:37 2011
@@ -65,7 +65,7 @@
      * @return time that elapsed while the stopwatch was running, 0 if the stopwatch has not yet been stopped
      */
     public long elapsedTime(@NotNull final TimeUnit unit) {
-        return TimeUnit.MILLISECONDS.convert(elapsedTime, unit);
+        return unit.convert(elapsedTime, TimeUnit.MILLISECONDS);
     }
 
     /**

Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/CollectionSupport.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/CollectionSupport.java?rev=179&r1=178&r2=179&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/CollectionSupport.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/CollectionSupport.java Tue Dec 27 13:11:37 2011
@@ -20,6 +20,8 @@
 import java.util.Collection;
 import java.util.Iterator;
 
+import net.shibboleth.utilities.java.support.annotation.constraint.NotNull;
+import net.shibboleth.utilities.java.support.annotation.constraint.Null;
 import net.shibboleth.utilities.java.support.logic.Assert;
 
 /** Set of helper methods for working with collections. */
@@ -34,16 +36,47 @@
      * 
      * @param <T> type of the collection elements
      * @param collection collection to which the element is added
-     * @param element element to be added to the collection, may be null
+     * @param element element to be added to the collection
      * 
      * @return true if this operation resulted in a change to the collection, false otherwise
      */
-    public static <T> boolean nonNullAdd(final Collection<T> collection, final T element) {
+    public static <T> boolean nonNullAdd(@NotNull final Collection<T> collection, @Null final T element) {
+        Assert.isNotNull(collection, "Collection can not be null");
+        
         if (element == null) {
             return false;
         }
 
         return collection.add(element);
+    }
+    
+    /**
+     * Copies all the non-null elements from the source collection to the target collection in iteration order. If
+     * either the source or target collection is <code>null</code> this method simply returns.
+     * 
+     * @param <CollectionType> type of the target collection
+     * @param <T> type of elements
+     * @param source source collection, may be null
+     * @param target target collection, may be null
+     * 
+     * @return the target collection
+     */
+    @NotNull public static <CollectionType extends Collection<T>, T> CollectionType nonNullAdd(
+            @NotNull final Collection<? extends T> source, final CollectionType target) {
+        if (source == null || source.isEmpty() || target == null) {
+            return target;

[... 121 lines stripped ...]


More information about the commits mailing list