[java-support] branch master updated: JSPT-61 - ClassToInstanceMultiMap.get should be annotated as @Nonnull

Scott Cantor cantor.2 at osu.edu
Wed Mar 9 12:45:51 EST 2016


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch master
in repository java-support.

The following commit(s) were added to refs/heads/master by this push:
       new  2c8053d   JSPT-61 - ClassToInstanceMultiMap.get should be annotated as @Nonnull
2c8053d is described below

commit 2c8053df3f64225f6680ab836b541e1164cefe15
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Mar 9 12:45:48 2016 -0500

    JSPT-61 - ClassToInstanceMultiMap.get should be annotated as @Nonnull
    
    https://issues.shibboleth.net/jira/browse/JSPT-61
---
 .../collection/ClassToInstanceMultiMap.java        | 46 +++++++++++++---------
 .../LockableClassToInstanceMultiMap.java           | 10 +++--
 2 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/src/main/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMap.java b/src/main/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMap.java
index 0cb8ca8..40ab53d 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMap.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMap.java
@@ -17,6 +17,10 @@
 
 package net.shibboleth.utilities.java.support.collection;
 
+import net.shibboleth.utilities.java.support.annotation.constraint.Live;
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
+import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -25,6 +29,8 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.annotation.concurrent.NotThreadSafe;
 
 /**
@@ -43,10 +49,10 @@ public class ClassToInstanceMultiMap<B> {
     private final boolean indexSupertypes;
 
     /** Map which backs this map. */
-    private final HashMap<Class<?>, List<B>> backingMap;
+    @Nonnull private final HashMap<Class<?>, List<B>> backingMap;
 
     /** List of values that are indexed. */
-    private final List<B> values;
+    @Nonnull private final List<B> values;
 
     /** Constructor. Does not index supertypes. */
     public ClassToInstanceMultiMap() {
@@ -77,7 +83,7 @@ public class ClassToInstanceMultiMap<B> {
      * 
      * @return true if the map contains a mapping for the specified key
      */
-    public boolean containsKey(final Class<?> key) {
+    public boolean containsKey(@Nullable final Class<?> key) {
         if (key == null) {
             return false;
         }
@@ -92,7 +98,7 @@ public class ClassToInstanceMultiMap<B> {
      * 
      * @return true if the map contains a mapping to the specified value
      */
-    public boolean containsValue(final B value) {
+    public boolean containsValue(@Nonnull final B value) {
         if (value == null) {
             return false;
         }
@@ -101,14 +107,14 @@ public class ClassToInstanceMultiMap<B> {
     }
 
     /**
-     * Gets the instances mapped to the given type or an empty list, immutable, list otherwise.
+     * Gets the instances mapped to the given type or an empty list.
      * 
      * @param <T> type identifier
      * @param type map key
      * 
-     * @return instances mapped to the given type or an empty list, immutable, list otherwise
+     * @return instances mapped to the given type or an empty list
      */
-    public <T> List<T> get(final Class<T> type) {
+    @Nonnull @NonnullElements @Unmodifiable @Live public <T> List<T> get(@Nullable final Class<T> type) {
         if (type == null) {
             return Collections.emptyList();
         }
@@ -135,7 +141,7 @@ public class ClassToInstanceMultiMap<B> {
      * 
      * @return set of keys contained in this map
      */
-    public Set<Class<?>> keys() {
+    @Nonnull @NonnullElements @Unmodifiable @Live public Set<Class<?>> keys() {
         return Collections.unmodifiableSet(backingMap.keySet());
     }
 
@@ -149,7 +155,7 @@ public class ClassToInstanceMultiMap<B> {
      * 
      * @param value value to be stored in the map
      */
-    public void put(final B value) {
+    public void put(@Nonnull final B value) {
         if (value == null) {
             return;
         }
@@ -180,7 +186,7 @@ public class ClassToInstanceMultiMap<B> {
      * 
      * @see ClassToInstanceMultiMap#put(Object)
      */
-    public void putAll(final Iterable<? extends B> newValues) {
+    public void putAll(@Nullable @NonnullElements final Iterable<? extends B> newValues) {
         if (newValues == null) {
             return;
         }
@@ -199,7 +205,7 @@ public class ClassToInstanceMultiMap<B> {
      * 
      * @see ClassToInstanceMultiMap#put(Object)
      */
-    public void putAll(final ClassToInstanceMultiMap<? extends B> map) {
+    public void putAll(@Nullable @NonnullElements final ClassToInstanceMultiMap<? extends B> map) {
         if (map == null) {
             return;
         }
@@ -217,7 +223,7 @@ public class ClassToInstanceMultiMap<B> {
      * 
      * @param value the value to remove
      */
-    public void remove(final B value) {
+    public void remove(@Nonnull final B value) {
         if (value == null) {
             return;
         }
@@ -246,7 +252,7 @@ public class ClassToInstanceMultiMap<B> {
      * 
      * @param removeValues the values to remove
      */
-    public void removeAll(final Iterable<? extends B> removeValues) {
+    public void removeAll(@Nullable @NonnullElements final Iterable<? extends B> removeValues) {
         if (removeValues == null) {
             return;
         }
@@ -266,7 +272,7 @@ public class ClassToInstanceMultiMap<B> {
      * 
      * @param map the map containing the values to remove
      */
-    public void removeAll(final ClassToInstanceMultiMap<? extends B> map) {
+    public void removeAll(@Nullable @NonnullElements final ClassToInstanceMultiMap<? extends B> map) {
         if (map == null) {
             return;
         }
@@ -289,7 +295,7 @@ public class ClassToInstanceMultiMap<B> {
      * 
      * @param type the type of values to remove
      */
-    public void remove(final Class<?> type) {
+    public void remove(@Nullable final Class<?> type) {
         if (type == null) {
             return;
         }
@@ -304,13 +310,13 @@ public class ClassToInstanceMultiMap<B> {
     }
 
     /**
-     * The collection of values currently present in the map. This collection is backed by the map so changeds to the
+     * The collection of values currently present in the map. This collection is backed by the map so changes to the
      * map will be reflected in the collection. However the collection does not allow direct modification so any changes
      * must be done through this map.
      * 
      * @return collection of values currently present in the map
      */
-    public Collection<? extends B> values() {
+    @Nonnull @NonnullElements @Unmodifiable @Live public Collection<? extends B> values() {
         return Collections.unmodifiableList(values);
     }
 
@@ -320,7 +326,7 @@ public class ClassToInstanceMultiMap<B> {
      * @param value the value to index
      * @return the set of classes by which to index the value
      */
-    private Set<Class<?>> getIndexTypes(final B value) {
+    @Nonnull @NonnullElements private Set<Class<?>> getIndexTypes(@Nonnull final B value) {
         final HashSet<Class<?>> indexTypes = new HashSet<>();
         indexTypes.add(value.getClass());
 
@@ -337,7 +343,8 @@ public class ClassToInstanceMultiMap<B> {
      * @param clazz class for which supertypes will be determined
      * @param accumulator collection to which supertypes are added as they are determined
      */
-    private void getSuperTypes(final Class<?> clazz, Set<Class<?>> accumulator) {
+    private void getSuperTypes(@Nonnull final Class<?> clazz,
+            @Nonnull @NonnullElements final Set<Class<?>> accumulator) {
         final Class<?> superclass = clazz.getSuperclass();
         if (superclass != null && superclass != Object.class) {
             accumulator.add(superclass);
@@ -370,4 +377,5 @@ public class ClassToInstanceMultiMap<B> {
         }
         return false;
     }
+    
 }
\ No newline at end of file
diff --git a/src/main/java/net/shibboleth/utilities/java/support/collection/LockableClassToInstanceMultiMap.java b/src/main/java/net/shibboleth/utilities/java/support/collection/LockableClassToInstanceMultiMap.java
index e5be0d5..5d7d658 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/collection/LockableClassToInstanceMultiMap.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/collection/LockableClassToInstanceMultiMap.java
@@ -20,6 +20,8 @@ package net.shibboleth.utilities.java.support.collection;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
+import javax.annotation.Nonnull;
+
 /**
  * A specialization of {@link ClassToInstanceMultiMap} which exposes a map-specific
  * instance of {@link ReadWriteLock}. Callers of the map are responsible for explicitly locking
@@ -31,7 +33,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 public class LockableClassToInstanceMultiMap<B> extends ClassToInstanceMultiMap<B> {
     
     /** The map's read write lock. */
-    private ReadWriteLock readWriteLock;
+    @Nonnull private final ReadWriteLock readWriteLock;
 
     /**
      * Constructor.
@@ -45,7 +47,7 @@ public class LockableClassToInstanceMultiMap<B> extends ClassToInstanceMultiMap<
      *
      * @param isIndexingSupertypes indicates whether supertypes of a value should be indexed
      */
-    public LockableClassToInstanceMultiMap(boolean isIndexingSupertypes) {
+    public LockableClassToInstanceMultiMap(final boolean isIndexingSupertypes) {
         super(isIndexingSupertypes);
         readWriteLock = new ReentrantReadWriteLock(true);
     }
@@ -60,8 +62,8 @@ public class LockableClassToInstanceMultiMap<B> extends ClassToInstanceMultiMap<
      * 
      * @return Returns the rwlock.
      */
-    public ReadWriteLock getReadWriteLock() {
+    @Nonnull public ReadWriteLock getReadWriteLock() {
         return readWriteLock;
     }
 
-}
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list