public interface AnnotationList
extends java.lang.Iterable<java.lang.annotation.Annotation>
DistributeOnMethods and AnnotationReplacers.| Modifier and Type | Method and Description |
|---|---|
boolean |
any(@NotNull java.util.function.Predicate<java.lang.annotation.Annotation> predicate)
Tests whether any of the annotations in this list match
the given predicate
|
<T extends java.lang.annotation.Annotation> |
contains(@NotNull java.lang.Class<T> type)
Tests whether this list contains the given annotation or not
|
static @NotNull AnnotationList |
create(@NotNull java.lang.reflect.AnnotatedElement element)
Creates a new
AnnotationList for the given AnnotatedElement. |
static @NotNull AnnotationList |
create(@NotNull java.util.Collection<java.lang.annotation.Annotation> annotations)
Creates a new
AnnotationList for the given collection of annotations. |
static @NotNull AnnotationList |
create(@NotNull java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.lang.annotation.Annotation> annotations)
Creates a new
AnnotationList for the given map of annotations. |
static @NotNull AnnotationList |
empty()
Returns an empty
AnnotationList. |
<T extends java.lang.annotation.Annotation> |
get(@NotNull java.lang.Class<T> type)
Returns the given annotation, or
null if it's not annotated
with the given annotation (or distributed on, indirectly) |
boolean |
isEmpty()
Tests whether this list is empty or not
|
@NotNull @Unmodifiable java.util.Iterator<java.lang.annotation.Annotation> |
iterator()
Returns an unmodifiable
Iterator for this annotation list |
<R,T extends java.lang.annotation.Annotation> |
map(@NotNull java.lang.Class<T> type,
java.util.function.Function<T,R> function)
Performs a map function on the annotation if it is present, otherwise
returns
null if the annotation is not present. |
<R,T extends java.lang.annotation.Annotation> |
mapOr(@NotNull java.lang.Class<T> type,
java.util.function.Function<T,R> function,
R defaultValue)
Performs a map function on the annotation if it is present, otherwise
returns
defaultValue if the annotation is not present. |
<R,T extends java.lang.annotation.Annotation> |
mapOrGet(@NotNull java.lang.Class<T> type,
@NotNull java.util.function.Function<T,R> function,
@NotNull java.util.function.Supplier<R> defaultValue)
Performs a map function on the annotation if it is present, otherwise
supplies the value in
defaultValue if the annotation is not present. |
@NotNull AnnotationList |
replaceAnnotations(@NotNull java.lang.reflect.AnnotatedElement element,
@NotNull java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.Set<AnnotationReplacer<?>>> replacers)
Replaces the annotations in this type with any suitable
AnnotationReplacers in
the supplied replacers map, and returns a (possibly new) AnnotationList
with the replaced annotations. |
<T extends java.lang.annotation.Annotation> |
require(@NotNull java.lang.Class<T> type,
@NotNull java.lang.String errorMessage)
Gets the given annotation, otherwise throws an
IllegalStateException
if it is not present. |
@NotNull java.util.Map<java.lang.Class<?>,java.lang.annotation.Annotation> |
toMutableMap()
Returns a mutable map that contains the annotations contained
in this annotation list
|
default @NotNull AnnotationList |
withAnnotations(java.lang.annotation.Annotation... annotations)
Creates a new
AnnotationList that contains these annotations as well
as the given annotations. |
@NotNull AnnotationList |
withAnnotations(boolean overrideExisting,
java.lang.annotation.Annotation... annotations)
Creates a new
AnnotationList that contains these annotations as well
as the given annotations. |
@NotNull static @NotNull AnnotationList create(@NotNull @NotNull java.lang.reflect.AnnotatedElement element)
AnnotationList for the given AnnotatedElement. This
method will take into account DistributeOnMethods annotationselement - The annotated element to create from@NotNull static @NotNull AnnotationList create(@NotNull @NotNull java.util.Collection<java.lang.annotation.Annotation> annotations)
AnnotationList for the given collection of annotations. This
method will not take into account DistributeOnMethods annotationsannotations - The annotations in this list@NotNull static @NotNull AnnotationList create(@NotNull @NotNull java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.lang.annotation.Annotation> annotations)
AnnotationList for the given map of annotations. This
method will not take into account DistributeOnMethods annotationsannotations - The annotations in this list@Contract(pure=true) @NotNull static @NotNull AnnotationList empty()
AnnotationList.AnnotationList singleton.@Contract(pure=true)
@Nullable
<T extends java.lang.annotation.Annotation> T get(@NotNull
@NotNull java.lang.Class<T> type)
null if it's not annotated
with the given annotation (or distributed on, indirectly)T - The annotation type automatically casttype - The annotation typenull if not
present@Contract(pure=true)
@Nullable
<R,T extends java.lang.annotation.Annotation> R map(@NotNull
@NotNull java.lang.Class<T> type,
java.util.function.Function<T,R> function)
null if the annotation is not present.R - The type we are mapping toT - The annotation typetype - The annotation typefunction - The mapping function.null if the annotation is not present.@Contract(pure=true)
<R,T extends java.lang.annotation.Annotation> R mapOr(@NotNull
@NotNull java.lang.Class<T> type,
java.util.function.Function<T,R> function,
R defaultValue)
defaultValue if the annotation is not present.R - The type we are mapping toT - The annotation typetype - The annotation typefunction - The mapping function.defaultValue if the annotation is not present.@Contract(pure=true)
<R,T extends java.lang.annotation.Annotation> R mapOrGet(@NotNull
@NotNull java.lang.Class<T> type,
@NotNull
@NotNull java.util.function.Function<T,R> function,
@NotNull
@NotNull java.util.function.Supplier<R> defaultValue)
defaultValue if the annotation is not present.R - The type we are mapping toT - The annotation typetype - The annotation typefunction - The mapping function.defaultValue if the annotation is not present.@Contract(pure=true)
@NotNull
<T extends java.lang.annotation.Annotation> T require(@NotNull
@NotNull java.lang.Class<T> type,
@NotNull
@NotNull java.lang.String errorMessage)
IllegalStateException
if it is not present.T - The annotation typetype - Annotation type to check forerrorMessage - The error message to include in the error@Contract(pure=true)
<T extends java.lang.annotation.Annotation> boolean contains(@NotNull
@NotNull java.lang.Class<T> type)
T - The annotation typetype - The annotation type to check fortrue if the annotation is present, false if otherwise.boolean isEmpty()
@NotNull
@Contract(value="-> new",
pure=true)
@NotNull java.util.Map<java.lang.Class<?>,java.lang.annotation.Annotation> toMutableMap()
@NotNull @Contract(pure=true) @NotNull AnnotationList replaceAnnotations(@NotNull @NotNull java.lang.reflect.AnnotatedElement element, @NotNull @NotNull java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.Set<AnnotationReplacer<?>>> replacers)
AnnotationReplacers in
the supplied replacers map, and returns a (possibly new) AnnotationList
with the replaced annotations.
Note that this does not modify this AnnotationList.
This also will not deeply replace annotations. If a replacer produces a replaceable annotation, this annotation will not be replaced.
In cases of empty(), this will return the same annotation
list.
element - The annotated element. This provides additional context and allows
DistributeOnMethods annotationsreplacers - The annotation replacers to useAnnotationList with the newly replaced
annotations.@NotNull @Contract(pure=true) @NotNull @Unmodifiable java.util.Iterator<java.lang.annotation.Annotation> iterator()
Iterator for this annotation listiterator in interface java.lang.Iterable<java.lang.annotation.Annotation>@NotNull
@Contract(pure=true,
value="_, _ -> new")
@NotNull AnnotationList withAnnotations(boolean overrideExisting,
@NotNull
java.lang.annotation.Annotation... annotations)
AnnotationList that contains these annotations as well
as the given annotations.overrideExisting - Whether should existing annotations be overridden if
a similar annotation is suppliedannotations - The annotations to include in the new copy@NotNull
@Contract(pure=true,
value="_ -> new")
default @NotNull AnnotationList withAnnotations(@NotNull
java.lang.annotation.Annotation... annotations)
AnnotationList that contains these annotations as well
as the given annotations.annotations - The annotations to include in the new copy@Contract(pure=true)
boolean any(@NotNull
@NotNull java.util.function.Predicate<java.lang.annotation.Annotation> predicate)
predicate - Predicate to check with