Package org.linkki.util
Class MetaAnnotation<META extends Annotation>
- java.lang.Object
-
- org.linkki.util.MetaAnnotation<META>
-
- Type Parameters:
META- the meta-annotation
public class MetaAnnotation<META extends Annotation> extends Object
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stream<META>findAllOn(Annotation annotation)Returns all meta-annotations present on the givenAnnotation.Stream<Annotation>findAnnotatedAnnotationsOn(AnnotatedElement annotatedElement)Finds allAnnotationson the givenAnnotatedElementthat are annotated with the meta-annotation.Optional<META>findOn(Annotation annotation)Returns the meta-annotation if it is present on the givenAnnotation.booleanisPresentOn(Annotation annotation)booleanisPresentOnAnyAnnotationOn(AnnotatedElement annotatedElement)Returnstrueif the meta-annotation is present on anyAnnotationon the givenAnnotatedElement, otherwisefalse;booleanisRepeatable()Returnstrueif the meta-annotation is@Repeatable.Supplier<? extends IllegalArgumentException>missingAnnotation(Annotation annotation, AnnotatedElement annotatedElement, String checkerMethod)Creates aSupplierfor anIllegalArgumentExceptionthat names the givenAnnotationon theAnnotatedElementas not having the meta-annotation and suggests using thecheckerMethodto safeguard against this exception.static <META extends Annotation>
MetaAnnotation<META>of(Class<META> metaAnnotationClass)Creates a newMetaAnnotation<META>from the givenAnnotationclass.<A extends Annotation>
BinaryOperator<A>onlyOneOn(AnnotatedElement annotatedElement)Creates aBinaryOperatorusable for aStream.reduce(BinaryOperator)operation on a stream of annotations as returned byfindAnnotatedAnnotationsOn(AnnotatedElement)that throws anIllegalArgumentExceptionif there is more than one annotation in the stream.
-
-
-
Method Detail
-
of
public static <META extends Annotation> MetaAnnotation<META> of(Class<META> metaAnnotationClass)
Creates a newMetaAnnotation<META>from the givenAnnotationclass.- Type Parameters:
META- the meta-annotation class- Parameters:
metaAnnotationClass- the meta-annotation class- Returns:
- a
MetaAnnotationfor themetaAnnotationClass - Throws:
IllegalArgumentException- if the givenAnnotationclass is not a meta-annotation
-
isRepeatable
public boolean isRepeatable()
Returnstrueif the meta-annotation is@Repeatable.- Returns:
- whether the meta-annotation is
@Repeatable
-
isPresentOnAnyAnnotationOn
public boolean isPresentOnAnyAnnotationOn(AnnotatedElement annotatedElement)
Returnstrueif the meta-annotation is present on anyAnnotationon the givenAnnotatedElement, otherwisefalse;- Parameters:
annotatedElement- anAnnotatedElementto be checked for meta-annotations on its annotations- Returns:
- whether the meta-annotation is present on any
Annotationon the givenAnnotatedElement
-
isPresentOn
public boolean isPresentOn(@CheckForNull Annotation annotation)- Parameters:
annotation- anAnnotationto be checked for the meta-annotation- Returns:
- whether the meta-annotation is present on the given
Annotation
-
findOn
public Optional<META> findOn(Annotation annotation)
Returns the meta-annotation if it is present on the givenAnnotation.If this meta-annotation
is repeatable, this method returns anOptionalwith the single meta-annotation if it was not repeated but throws anIllegalArgumentExceptionif it was.- Parameters:
annotation- anAnnotation- Returns:
- the meta-annotation instance, if the annotation is annotated with it
- Throws:
IllegalArgumentException- if the meta-annotation is repeatable and present multiple times.- See Also:
findAllOn(Annotation) for repeatable annotations
-
findAllOn
public Stream<META> findAllOn(Annotation annotation)
Returns all meta-annotations present on the givenAnnotation.- Parameters:
annotation- anAnnotation- Returns:
- the meta-annotation instance, if the annotation is annotated with it
-
findAnnotatedAnnotationsOn
public Stream<Annotation> findAnnotatedAnnotationsOn(AnnotatedElement annotatedElement)
Finds allAnnotationson the givenAnnotatedElementthat are annotated with the meta-annotation.- Parameters:
annotatedElement- anAnnotatedElement- Returns:
- a
Streamof theAnnotationsannotated with the meta-annotation - See Also:
use if you expect there to be no more than one such annotation.
-
onlyOneOn
public <A extends Annotation> BinaryOperator<A> onlyOneOn(AnnotatedElement annotatedElement)
Creates aBinaryOperatorusable for aStream.reduce(BinaryOperator)operation on a stream of annotations as returned byfindAnnotatedAnnotationsOn(AnnotatedElement)that throws anIllegalArgumentExceptionif there is more than one annotation in the stream.- Parameters:
annotatedElement- theAnnotatedElementthat was passed tofindAnnotatedAnnotationsOn(AnnotatedElement); will be included in the exception message- Returns:
- a
BinaryOperatorusable for aStream.reduce(BinaryOperator)operation on a stream of annotations as returned byfindAnnotatedAnnotationsOn(AnnotatedElement)
-
missingAnnotation
public Supplier<? extends IllegalArgumentException> missingAnnotation(Annotation annotation, AnnotatedElement annotatedElement, String checkerMethod)
Creates aSupplierfor anIllegalArgumentExceptionthat names the givenAnnotationon theAnnotatedElementas not having the meta-annotation and suggests using thecheckerMethodto safeguard against this exception.- Parameters:
annotation- anAnnotationon theAnnotatedElementannotatedElement- anAnnotatedElementcheckerMethod- description of a method to be called before the method that throws this exception to safeguard against it- Returns:
- a
Supplierfor anIllegalArgumentException
-
-