Class Index<A extends Annotation,I>

java.lang.Object
net.java.sezpoz.Index<A,I>
Record Components:
A - the type of annotation to load
I - the type of instance which will be created
All Implemented Interfaces:
Iterable<IndexItem<A,I>>

public final class Index<A extends Annotation,I> extends Object implements Iterable<IndexItem<A,I>>
Represents an index of a single annotation. Indices are not automatically cached (but reading them should be pretty cheap anyway).
  • Method Details

    • load

      public static <A extends Annotation, I> Index<A,I> load(Class<A> annotation, Class<I> instanceType) throws IllegalArgumentException
      Load an index for a given annotation type. Uses the thread's context class loader to find the index and load annotated classes.
      Parameters:
      annotation - the type of annotation to find
      instanceType - the type of instance to be created (use Void if all instances will be null)
      Returns:
      an index of all elements known to be annotated with it
      Throws:
      IllegalArgumentException - if the annotation type is not marked with Indexable or the instance type is not equal to or a supertype of the annotation's actual Indexable.type()
    • load

      public static <A extends Annotation, I> Index<A,I> load(Class<A> annotation, Class<I> instanceType, ClassLoader loader) throws IllegalArgumentException
      Load an index for a given annotation type.
      Parameters:
      annotation - the type of annotation to find
      instanceType - the type of instance to be created (use Void if all instances will be null)
      loader - a class loader in which to find the index and any annotated classes
      Returns:
      an index of all elements known to be annotated with it
      Throws:
      IllegalArgumentException - if the annotation type is not marked with Indexable or the instance type is not equal to or a supertype of the annotation's actual Indexable.type()
    • iterator

      public Iterator<IndexItem<A,I>> iterator()
      Find all items in the index. Calls to iterator methods may fail with IndexError as the index is parsed lazily.
      Specified by:
      iterator in interface Iterable<A extends Annotation>
      Returns:
      an iterator over items in the index