Hi,

In Qi4j we have an Annotations class that provides some utility methods for accessing and working with annotations. It used to have quite a few of methods, and they were mostly variations of each other. I wanted to remove the creation of the ArrayList that most of these had, and at the same time make it easier to work with.

So, it is now changed to have two types of methods. One category creates AnnotationSpecification's that are used for filtering. Then there's one method that takes an Iterable<Annotation> returns an Iterable<Annotation> of the ones that pass the spec, and which does the same but only returns the first match.

I have then implemented everything else as being variations of using these methods, which have cleaned things up quite a bit. Example: for( Annotation constraintAnnotation : filter( hasAnnotation(org.qi4j.api.constraint.ConstraintDeclaration.class ), constraintAnnotations) ) This example takes a list of annotations and iterates over the ones that have a ConstraintDeclaration on them.

Another example:
boolean optional = first( isType(Optional.class ), annotations) != null;
Check if a list of annotations contain the @Optional annotation.

And so on. Quite handy utility class.

/Rickard

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to