Package org.biojava.bio
Class CollectionConstraint.Or
- java.lang.Object
-
- org.biojava.bio.CollectionConstraint.Or
-
- All Implemented Interfaces:
CollectionConstraint
- Enclosing interface:
- CollectionConstraint
public static class CollectionConstraint.Or extends Object implements CollectionConstraint
A collection constraint that accepts items iff they are accepted by either child constraints. This effectively matches the union of the items matched by the two constraints. Use this to combine multiple constraints. You can make one or both of the children Or instances if you need a wider union.- Author:
- Matthew Pocock, Thomas Down
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.biojava.bio.CollectionConstraint
CollectionConstraint.AllValuesIn, CollectionConstraint.And, CollectionConstraint.Contains, CollectionConstraint.Or
-
-
Field Summary
-
Fields inherited from interface org.biojava.bio.CollectionConstraint
ANY, EMPTY, NONE
-
-
Constructor Summary
Constructors Constructor Description Or(CollectionConstraint c1, CollectionConstraint c2)Create a newOrfrom two child constraints.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaccept(Object object)acceptreturns true if the value fulfills the constraint.CollectionConstraintgetChild1()Get the first child CollectionConstraint.CollectionConstraintgetChild2()Get the seccond child CollectionConstraint.booleansubConstraintOf(CollectionConstraint pc)subConstraintOfreturns true if the constraint is a sub-constraint.StringtoString()booleanvalidateAddValue(Collection oldcoll, Object newvalue)Returntrueiff the Collection formed by addingnewValuetocurrentwould be accepted by this constraint.booleanvalidateRemoveValue(Collection oldcoll, Object victim)Returntrueiff the Collection formed by removingnewValuefromcurrentwould be accepted by this constraint.
-
-
-
Constructor Detail
-
Or
public Or(CollectionConstraint c1, CollectionConstraint c2)
Create a newOrfrom two child constraints.- Parameters:
c1- the first childc2- the seccond child
-
-
Method Detail
-
getChild1
public CollectionConstraint getChild1()
Get the first child CollectionConstraint.- Returns:
- the first child CollectionConstraint
-
getChild2
public CollectionConstraint getChild2()
Get the seccond child CollectionConstraint.- Returns:
- the seccond child CollectionConstraint
-
accept
public boolean accept(Object object)
Description copied from interface:CollectionConstraintacceptreturns true if the value fulfills the constraint.- Specified by:
acceptin interfaceCollectionConstraint- Parameters:
object- 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
public boolean subConstraintOf(CollectionConstraint pc)
Description copied from interface:CollectionConstraintsubConstraintOfreturns 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.- Specified by:
subConstraintOfin interfaceCollectionConstraint- Parameters:
pc- 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
public boolean validateAddValue(Collection oldcoll, Object newvalue)
Description copied from interface:CollectionConstraintReturntrueiff the Collection formed by addingnewValuetocurrentwould be accepted by this constraint. Implementations may not assume thatcurrentis valid.- Specified by:
validateAddValuein interfaceCollectionConstraint- Parameters:
oldcoll- 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
public boolean validateRemoveValue(Collection oldcoll, Object victim)
Description copied from interface:CollectionConstraintReturntrueiff 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.- Specified by:
validateRemoveValuein interfaceCollectionConstraint- Parameters:
oldcoll- a Collection containing the current valuesvictim- the value to remove- Returns:
- true if removing the victim will result in an acceptable property value set
-
-