public final class AnnotationTools extends Object
AnnotationTools
is a set of static utility methods for
manipulating Annotation
s and AnnotationType
s.
The methods allIn() and allOut() let you compare an Annotation to an AnnotationType and produce a new Annotation with only those properties explicitly constrained by or not constrained by the type. This could be of use when using an Annotation as a template for some object. You could use allOut to make an Annotation that has all the properties that do not fit into normal constructor properties, and pass that in as the Annotation bundle.
intersection(AnnotationType) and union(AnnotationType) return new AnnotationType instances that will accept every Annotation instance that is accepted by both or either respectively. It is particularly informative to compare the result of this to the AnnotationType.NONE to see if the two types are mutualy disjoint.
intersection(PropertyConstraint) and union(PropertyConstraint) return new PropertyConstraint instances that will accept every Object that is accepted by both or either one respectively.
FilterTools uses these methods when comparing filters on features by their Annotation bundles.Constructor and Description |
---|
AnnotationTools() |
Modifier and Type | Method and Description |
---|---|
static Annotation |
allIn(Annotation annotation,
AnnotationType annType)
Destructive down-cast an annotation to a type.
|
static Annotation |
allOut(Annotation annotation,
AnnotationType annType)
allOut returns a new Annotation
containing only those values in the Annotation
argument which are not of a type specified by
the AnnotationType . |
static AnnotationType |
intersection(AnnotationType ann1,
AnnotationType ann2)
Calculate an AnnotationType that matches all Annotation instances matched
by both types.
|
static CollectionConstraint |
intersection(CollectionConstraint cc1,
CollectionConstraint cc2)
Return the CollectionConstraint which accept only collections accepted by
both of those specified.
|
static PropertyConstraint |
intersection(PropertyConstraint pc1,
PropertyConstraint pc2)
Calculate the intersection of two PropertyConstraint instances.
|
static Set |
searchAnnotation(Annotation ann,
AnnotationType query)
Scans an Annotation with an AnnotationType and returns all Annotation
instances matching a Type.
|
static AnnotationType |
union(AnnotationType ann1,
AnnotationType ann2)
Create an AnnotationType that matches all Anntotations that are accepted
by two others.
|
static CollectionConstraint |
union(CollectionConstraint cc1,
CollectionConstraint cc2)
Calculate a CollectionConstaint that will accept all items accepted by
either constraint.
|
static PropertyConstraint |
union(PropertyConstraint pc1,
PropertyConstraint pc2)
Create a PropertyConstraint that matches all Objects that are accepted
by two others.
|
public AnnotationTools()
public static Annotation allIn(Annotation annotation, AnnotationType annType)
Destructive down-cast an annotation to a type.
allIn
returns a new Annotation
containing only those values in the Annotation
argument which are of a type specified by the
AnnotationType
.
annotation
- an Annotation
to scan.annType
- an AnnotationType
.Annotation
.public static Annotation allOut(Annotation annotation, AnnotationType annType)
allOut
returns a new Annotation
containing only those values in the Annotation
argument which are not of a type specified by
the AnnotationType
.annotation
- an Annotation
.annType
- an AnnotationType
.Annotation
value.public static Set searchAnnotation(Annotation ann, AnnotationType query)
Scans an Annotation with an AnnotationType and returns all Annotation instances matching a Type.
This differs from AnnotationType.instanceOf() as it will descend into properties of an Annotation if that property is itself an Annotation. This allows you to scan a tree of Annotations for nodes in the tree of a particular shape.
ann
- the Annotation to scanquery
- the AnnotationType to match against all nodes in the treepublic static AnnotationType intersection(AnnotationType ann1, AnnotationType ann2)
ann1
- the first AnnotationTypeann2
- the seccond AnnotationTypepublic static PropertyConstraint intersection(PropertyConstraint pc1, PropertyConstraint pc2)
pc1
- the first PropertyConstraintpc2
- the seccond PropertyConstraintpublic static AnnotationType union(AnnotationType ann1, AnnotationType ann2)
ann1
- the first AnnotationTypeann2
- the seccond AnnotationTypepublic static PropertyConstraint union(PropertyConstraint pc1, PropertyConstraint pc2)
pc1
- the first PropertyConstraintpc2
- the second PropertyConstraintpublic static CollectionConstraint intersection(CollectionConstraint cc1, CollectionConstraint cc2)
cc1
- the first CollectionConstraintcc2
- the seccond CollectionConstrantpublic static CollectionConstraint union(CollectionConstraint cc1, CollectionConstraint cc2)
cc1
- the first CollectionConstraintcc2
- the seccond collectionConstraintCopyright © 2014 BioJava. All rights reserved.