Class AnnotationTools
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.- Since:
- 1.3
- Author:
- Matthew Pocock, Keith James (docs), Thomas Down
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Annotation
allIn
(Annotation annotation, AnnotationType annType) Destructive down-cast an annotation to a type.static Annotation
allOut
(Annotation annotation, AnnotationType annType) allOut
returns a newAnnotation
containing only those values in theAnnotation
argument which are not of a type specified by theAnnotationType
.static AnnotationType
intersection
(AnnotationType ann1, AnnotationType ann2) Calculate an AnnotationType that matches all Annotation instances matched by both types.static CollectionConstraint
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.
-
Constructor Details
-
AnnotationTools
public AnnotationTools()
-
-
Method Details
-
allIn
Destructive down-cast an annotation to a type.
allIn
returns a newAnnotation
containing only those values in theAnnotation
argument which are of a type specified by theAnnotationType
.- Parameters:
annotation
- anAnnotation
to scan.annType
- anAnnotationType
.- Returns:
- an
Annotation
.
-
allOut
allOut
returns a newAnnotation
containing only those values in theAnnotation
argument which are not of a type specified by theAnnotationType
.- Parameters:
annotation
- anAnnotation
.annType
- anAnnotationType
.- Returns:
- an
Annotation
value.
-
searchAnnotation
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
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
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
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
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
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
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
-