Class AnnotationTools
- java.lang.Object
-
- org.biojava.bio.AnnotationTools
-
public final class AnnotationTools extends Object
AnnotationToolsis a set of static utility methods for manipulatingAnnotations andAnnotationTypes.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.- Since:
- 1.3
- Author:
- Matthew Pocock, Keith James (docs), Thomas Down
-
-
Constructor Summary
Constructors Constructor Description AnnotationTools()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static AnnotationallIn(Annotation annotation, AnnotationType annType)Destructive down-cast an annotation to a type.static AnnotationallOut(Annotation annotation, AnnotationType annType)allOutreturns a newAnnotationcontaining only those values in theAnnotationargument which are not of a type specified by theAnnotationType.static AnnotationTypeintersection(AnnotationType ann1, AnnotationType ann2)Calculate an AnnotationType that matches all Annotation instances matched by both types.static CollectionConstraintintersection(CollectionConstraint cc1, CollectionConstraint cc2)Return the CollectionConstraint which accept only collections accepted by both of those specified.static PropertyConstraintintersection(PropertyConstraint pc1, PropertyConstraint pc2)Calculate the intersection of two PropertyConstraint instances.static SetsearchAnnotation(Annotation ann, AnnotationType query)Scans an Annotation with an AnnotationType and returns all Annotation instances matching a Type.static AnnotationTypeunion(AnnotationType ann1, AnnotationType ann2)Create an AnnotationType that matches all Anntotations that are accepted by two others.static CollectionConstraintunion(CollectionConstraint cc1, CollectionConstraint cc2)Calculate a CollectionConstaint that will accept all items accepted by either constraint.static PropertyConstraintunion(PropertyConstraint pc1, PropertyConstraint pc2)Create a PropertyConstraint that matches all Objects that are accepted by two others.
-
-
-
Constructor Detail
-
AnnotationTools
public AnnotationTools()
-
-
Method Detail
-
allIn
public static Annotation allIn(Annotation annotation, AnnotationType annType)
Destructive down-cast an annotation to a type.
allInreturns a newAnnotationcontaining only those values in theAnnotationargument which are of a type specified by theAnnotationType.- Parameters:
annotation- anAnnotationto scan.annType- anAnnotationType.- Returns:
- an
Annotation.
-
allOut
public static Annotation allOut(Annotation annotation, AnnotationType annType)
allOutreturns a newAnnotationcontaining only those values in theAnnotationargument which are not of a type specified by theAnnotationType.- Parameters:
annotation- anAnnotation.annType- anAnnotationType.- Returns:
- an
Annotationvalue.
-
searchAnnotation
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.
- Parameters:
ann- the Annotation to scanquery- the AnnotationType to match against all nodes in the tree- Returns:
- the set of all annotations matching the query
-
intersection
public static AnnotationType intersection(AnnotationType ann1, AnnotationType ann2)
Calculate an AnnotationType that matches all Annotation instances matched by both types. Usually you will either use this value blind or compare it to AnnotationType.NONE.- Parameters:
ann1- the first AnnotationTypeann2- the seccond AnnotationType- Returns:
- the intersection AnnotationType
-
intersection
public static PropertyConstraint intersection(PropertyConstraint pc1, PropertyConstraint pc2)
Calculate the intersection of two PropertyConstraint instances. This method is realy only interesting when comparing each property in an AnnotationType in turn. Usually the return value is either compared to PropertyConstraint.NONE or is used blindly.- Parameters:
pc1- the first PropertyConstraintpc2- the seccond PropertyConstraint- Returns:
- the intersection PropertyConstraint
-
union
public static AnnotationType union(AnnotationType ann1, AnnotationType ann2)
Create an AnnotationType that matches all Anntotations that are accepted by two others. This method is realy not very usefull in most cases. You may wish to compare the result of this to AnnotationType.ANY, or use it blindly.- Parameters:
ann1- the first AnnotationTypeann2- the seccond AnnotationType- Returns:
- an AnnotationType that represents their unions
-
union
public static PropertyConstraint union(PropertyConstraint pc1, PropertyConstraint pc2)
Create a PropertyConstraint that matches all Objects that are accepted by two others. In the general case, there is no clean way to represent the union of two PropertyConstraint instances. You may get back a PropertyConstraint.Or instance, or perhaps PropertyConstraint.ANY. Alternatively, there may be some comparrison possible. It is a thankless task introspecting this in code. You have been warned.- Parameters:
pc1- the first PropertyConstraintpc2- the second PropertyConstraint- Returns:
- the union PropertyConstraint
-
intersection
public static CollectionConstraint intersection(CollectionConstraint cc1, CollectionConstraint cc2)
Return the CollectionConstraint which accept only collections accepted by both of those specified.- Parameters:
cc1- the first CollectionConstraintcc2- the seccond CollectionConstrant- Returns:
- a CollectionConstraint representing the intersection of the other two
-
union
public static CollectionConstraint union(CollectionConstraint cc1, CollectionConstraint cc2)
Calculate a CollectionConstaint that will accept all items accepted by either constraint.- Parameters:
cc1- the first CollectionConstraintcc2- the seccond collectionConstraint- Returns:
- a CollectionConstraint representing the union of the other two
-
-