Package org.biojava.bio
Interface CollectionConstraint
- All Known Implementing Classes:
CollectionConstraint.AllValuesIn,CollectionConstraint.And,CollectionConstraint.Contains,CollectionConstraint.Or
public interface CollectionConstraint
Used by
AnnotationType to represent the constraint on
the collection of values in a property-slot.
CollectionConstraints usually use a PropertyConstraint
to validate the individual elements.
Use one or more of the built-in implementations to build new
AnnotationTypes.- Since:
- 1.3
- Author:
- Thomas Down, Matthew Pocock
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classCollectionConstraint which validates all members of a Collection.static classA collection constraint that accpepts collections iff they are accepted by both child constraints.static classCollectionConstraint which validates a portion of a Collection.static classA collection constraint that accepts items iff they are accepted by either child constraints. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CollectionConstraintANYis a constraint which accepts a property for addition under all conditions.static final CollectionConstraintEMPTYis a constraint which only accepts the empty set.static final CollectionConstraintNONEis a constraint which accepts no value for a property under any condition. -
Method Summary
Modifier and TypeMethodDescriptionbooleanacceptreturns true if the value fulfills the constraint.booleansubConstraintOf(CollectionConstraint subConstraint) subConstraintOfreturns true if the constraint is a sub-constraint.booleanvalidateAddValue(Collection current, Object newValue) Returntrueiff the Collection formed by addingnewValuetocurrentwould be accepted by this constraint.booleanvalidateRemoveValue(Collection current, Object victim) Returntrueiff the Collection formed by removingnewValuefromcurrentwould be accepted by this constraint.
-
Field Details
-
ANY
ANYis a constraint which accepts a property for addition under all conditions. Whenever a CollectionConstraint is needed and you want to allow any value there -
EMPTY
EMPTYis a constraint which only accepts the empty set. Use this to indicate that a property must be undefined -
NONE
NONEis a constraint which accepts no value for a property under any condition. This value indicates an impossible condition. It may be returned by methods such asAnnotationTools.intersectionto indicate thatNOvalues of a property (include undefined) are valid.
-
-
Method Details
-
accept
acceptreturns true if the value fulfills the constraint.- Parameters:
values- aCollectionto check.- Returns:
- true if the values are acceptable powerUser Manually compare items with the CollectionConstraint. Node: this will ususaly be done for you in an AnnotationType instance
-
subConstraintOf
subConstraintOfreturns true if the constraint is a sub-constraint.A pair of constraints super and sub are in a superConstraint/subConstraint relationship if every object accepted by sub is also accepted by super. To put it another way, if instanceOf was used as a set-membership indicator function over some set of objects, then the set produced by super would be a superset of that produced by sub.
It is not expected that constraints will neccesarily maintain references to super/sub types. It will be more usual to infer this relationship by introspecting the constraints themselves. For example,
CollectionConstraint.ByClasswill infer subConstraintOf by looking at the possible class of all items matching subConstraint.- Parameters:
subConstraint- aCollectionConstraintto check.- Returns:
- a
boolean. Usefull when attempting to compare two constraints to see if it is necisary to retain both. You may want to check the more general or the more specific constraint only.
-
validateAddValue
Returntrueiff the Collection formed by addingnewValuetocurrentwould be accepted by this constraint. Implementations may not assume thatcurrentis valid.- Parameters:
current- a Collection containing the current valuesnewValue- the new value to add- Returns:
- true if adding the new value will result in an acceptable property
-
validateRemoveValue
Returntrueiff the Collection formed by removingnewValuefromcurrentwould be accepted by this constraint. Implementations may not assume thatcurrentis valid. However,currentwill already have been checked to ensure that it containsvictim.- Parameters:
current- a Collection containing the current valuesvictim- the value to remove- Returns:
- true if removing the victim will result in an acceptable property value set
-