Skip to content

Commit 7c20295

Browse files
committed
ClassUtils: clean up CacheMap
Improves the javadoc, adding more information and fixing refactoring artifacts (such as references to Field or Method in the general base class)
1 parent b71dc5c commit 7c20295

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

src/main/java/org/scijava/util/ClassUtils.java

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -758,33 +758,43 @@ public static Type getGenericType(final Field field, final Class<?> type) {
758758
// -- Helper classes --
759759

760760
/**
761-
* Convenience class to further type narrow {@link CacheMap} to {@link Field}
762-
* s.
761+
* Convenience class for a {@link CacheMap} that stores annotated
762+
* {@link Field}s.
763763
*/
764764
private static class FieldCache extends CacheMap<Field> {}
765765

766766
/**
767-
* Convenience class to further type narrow {@link CacheMap} to {@link Method}
768-
* s.
767+
* Convenience class for a {@link CacheMap} that stores annotated
768+
* {@link Method}s.
769769
*/
770770
private static class MethodCache extends CacheMap<Method> {}
771771

772772
/**
773773
* Convenience class for {@code Map > Map > List} hierarchy. Cleans up
774774
* generics and contains helper methods for traversing the two map levels.
775+
* <p>
776+
* The intent for this class is to allow subclasses to specify the generic
777+
* parameter ultimately referenced by the at the end of these maps.
778+
* </p>
779+
* <p>
780+
* The first map key is a base class, presumably with various types of
781+
* annotations. The second map key is the annotation class, for example
782+
* {@link Method} or {@link Field}. The list then contains all instances of
783+
* the annotated type within the original base class.
784+
* </p>
775785
*
776-
* @param <T> - {@link AnnotatedElement} {@link List} ultimately referenced by
777-
* this map
786+
* @param <T> - The type of {@link AnnotatedElement} contained by the
787+
* {@link List} ultimately referenced by these {@link Map}s
778788
*/
779789
private static class CacheMap<T extends AnnotatedElement> extends
780790
HashMap<Class<?>, Map<Class<? extends Annotation>, List<T>>>
781791
{
782792

783793
/**
784-
* @param c Base class
785-
* @param annotationClass Annotation type
786-
* @return Cached list of Methods in the base class with the specified
787-
* annotation, or null if a cached list does not exist.
794+
* @param c Base class of interest
795+
* @param annotationClass {@link Annotation type within the base class
796+
* @return A {@link List} of instances in the base class with the specified
797+
* {@link Annotation}, or null if a cached list does not exist.
788798
*/
789799
public List<T> getList(final Class<?> c,
790800
final Class<? extends Annotation> annotationClass)
@@ -798,44 +808,45 @@ public List<T> getList(final Class<?> c,
798808
}
799809

800810
/**
801-
* Populates the provided list with {@link Method} entries of the given base
802-
* class which are annotated with the specified annotation type.
811+
* Creates a {@code base class > annotation > list of elements} mapping to
812+
* the provided list, creating the intermediate map if needed.
803813
*
804-
* @param c Base class
805-
* @param annotationClass Annotation type
806-
* @param annotatedMethods Method list to populate
814+
* @param c Base class of interest
815+
* @param annotationClass {@link Annotation} type of interest
816+
* @param annotatedElements List of {@link AnnotatedElement}s to map
807817
*/
808818
public void putList(final Class<?> c,
809819
final Class<? extends Annotation> annotationClass,
810-
final List<T> annotatedMethods)
820+
final List<T> annotatedElements)
811821
{
812822
Map<Class<? extends Annotation>, List<T>> map = get(c);
813823
if (map == null) {
814824
map = new HashMap<Class<? extends Annotation>, List<T>>();
815825
put(c, map);
816826
}
817827

818-
map.put(annotationClass, annotatedMethods);
828+
map.put(annotationClass, annotatedElements);
819829
}
820830

821831
/**
822-
* As {@link #getList(Class, Class)} but ensures an array is created and
823-
* mapped, if it doesn't already exist.
832+
* Generates mappings as in {@link #putList(Class, Class, List)}, but also
833+
* creates the {@link List} if it doesn't already exist. Returns the final
834+
* list at this mapping, for external population.
824835
*
825-
* @param c Base class
826-
* @param annotationClass Annotation type
827-
* @return Cached list of Fields in the base class with the specified
828-
* annotation.
836+
* @param c Base class of interest
837+
* @param annotationClass {@link Annotation} type of interest
838+
* @return Cached list of {@link AnnotatedElement}s in the base class with
839+
* the specified {@link Annotation}.
829840
*/
830841
public List<T> makeList(final Class<?> c,
831842
final Class<? extends Annotation> annotationClass)
832843
{
833-
List<T> methods = getList(c, annotationClass);
834-
if (methods == null) {
835-
methods = new ArrayList<T>();
836-
putList(c, annotationClass, methods);
844+
List<T> elements = getList(c, annotationClass);
845+
if (elements == null) {
846+
elements = new ArrayList<T>();
847+
putList(c, annotationClass, elements);
837848
}
838-
return methods;
849+
return elements;
839850
}
840851

841852
}

0 commit comments

Comments
 (0)