Package org.intermine.objectstore.query
Class ConstraintHelper
- java.lang.Object
- 
- org.intermine.objectstore.query.ConstraintHelper
 
- 
 public final class ConstraintHelper extends java.lang.ObjectStatic methods to create Lists of Constraint objects in a query and Constraints in a query relating to a given QueryClass, plus helper methods for dealing with Constraints.
 'left' and 'right' arguments for each constraint type are defined as follows: SimpleConstraint: left = arg1, right = arg2 (both QueryEvaluables) ClassConstraint: left = QueryClass arg1, right = a QueryClass or example object arg2 ContainsConstraint: left = the QueryReference - i.e. field of containing class right = the QueryClass this reference is constrained to SubQueryConstraint: left = the QueryClass or QueryEvaluable constrained to be in the subquery right = the query ConstraintSet: N/A- Author:
- Matthew Wakeling, Richard Smith
 
- 
- 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddToList(java.util.List<Constraint> list, Constraint constraint)Adds all the constraints present in the argument into the given List.static java.util.List<Constraint>createList(Query query)Converts a constraint from a query into a List of Constraint objects.static java.util.List<Constraint>createList(Query query, FromElement fromElement)Return a List of Constraint objects that relate to the given FromElement.static java.util.List<Constraint>filter(java.util.List<Constraint> list, FromElement fromElement, boolean related)Return a subset of the given List that contains only Constraints that relate to the given FromElement or constraints associated with nothing if fromElement is null.static java.lang.ObjectgetLeftArgument(Constraint constraint)Get the left argument of the given constraint, will return null if passed a ConstraintSet or a MultipleInBagConstraint.protected static java.util.Set<QueryField>getQueryFields(QueryEvaluable qe)Descends into QueryExpression and QueryFunction objects to find all instances of QueryField.static java.lang.ObjectgetRightArgument(Constraint constraint)Get the right argument of the given constraint, will return null if passed a ConstraintSet or a MultipleInBagConstraint.static booleanisAssociatedWith(Constraint constraint, FromElement fromElement)Returns true if the constraint is associated with the given FromElement.static booleanisAssociatedWithNothing(Constraint c)Returns true if the given constraint is associated with no particular FromElement.static booleanisCrossReference(Constraint constraint)Returns true if the Constraint is a cross-reference between two QueryClasses.static booleanisRelatedTo(Constraint constraint, FromElement fromElement)Returns true if the constraint is associated with the given FromElement.static booleanisRelatedToNothing(Constraint c)Returns true if the given constraint is related to no FromElement.static java.util.List<Constraint>listRelatedConstraints(Query query, FromElement fromElement)Return a List of Constraint objects that relate to the given FromElement.static voidtraverseConstraints(Constraint c, ConstraintTraverseAction ca)Traverse the given Constraint tree (ie.
 
- 
- 
- 
Method Detail- 
createListpublic static java.util.List<Constraint> createList(Query query) Converts a constraint from a query into a List of Constraint objects.- Parameters:
- query- a Query object to list Constraints for
- Returns:
- a List of Constraint objects
 
 - 
createListpublic static java.util.List<Constraint> createList(Query query, FromElement fromElement) Return a List of Constraint objects that relate to the given FromElement.- Parameters:
- query- a Query object to to list contraints for
- fromElement- a FromElement that returned constraints relate to
- Returns:
- a List of Constraint objects
 
 - 
traverseConstraintspublic static void traverseConstraints(Constraint c, ConstraintTraverseAction ca) Traverse the given Constraint tree (ie. recursively look for nested constraints if the argument is a ConstraintSet) and call ConstraintTraverseAction for each Constraint.- Parameters:
- c- the Constraint to traverse - could be a ConstraintSet (possibly with nested ConstraintSets)
- ca- ConstraintTraverseAction.apply() is called for each Constraint found
 
 - 
listRelatedConstraintspublic static java.util.List<Constraint> listRelatedConstraints(Query query, FromElement fromElement) Return a List of Constraint objects that relate to the given FromElement.- Parameters:
- query- a Query object to to list contraints for
- fromElement- a FromElement that returned constraints relate to
- Returns:
- a List of Constraint objects
 
 - 
filterpublic static java.util.List<Constraint> filter(java.util.List<Constraint> list, FromElement fromElement, boolean related) Return a subset of the given List that contains only Constraints that relate to the given FromElement or constraints associated with nothing if fromElement is null.- Parameters:
- list- a list of Constraints to filter
- fromElement- a fromElement that returned constraints relate to
- related- if tru list all releted constraints, otherwise just associated
- Returns:
- a List of Constraint objects
 
 - 
addToListpublic static void addToList(java.util.List<Constraint> list, Constraint constraint) Adds all the constraints present in the argument into the given List.- Parameters:
- list- a List of Constraints, to which to add more entries
- constraint- a Constraint to pick apart
 
 - 
isAssociatedWithpublic static boolean isAssociatedWith(Constraint constraint, FromElement fromElement) Returns true if the constraint is associated with the given FromElement. Associated with means relating directly to a field of the QueryClass but NOT a cross-reference contraint (which compares two arbitrary fields of different QueryClasses.- Parameters:
- constraint- the constraint in question
- fromElement- the FromElement to check
- Returns:
- true if associated
 
 - 
isAssociatedWithNothingpublic static boolean isAssociatedWithNothing(Constraint c) Returns true if the given constraint is associated with no particular FromElement.- Parameters:
- c- the constraint to examine
- Returns:
- true if constraint is not associated with a FromElement
 
 - 
isRelatedTopublic static boolean isRelatedTo(Constraint constraint, FromElement fromElement) Returns true if the constraint is associated with the given FromElement.- Parameters:
- constraint- the constraint in question
- fromElement- the FromElement to check
- Returns:
- true if associated
 
 - 
isRelatedToNothingpublic static boolean isRelatedToNothing(Constraint c) Returns true if the given constraint is related to no FromElement. This should only return true if c is a SimpleConstraint that only references constants.- Parameters:
- c- the constraint to examine
- Returns:
- true if constraint is not associated with a FromElement
 
 - 
isCrossReferencepublic static boolean isCrossReference(Constraint constraint) Returns true if the Constraint is a cross-reference between two QueryClasses. A constraint is deemed to be a cross-reference if it compares fields of two different QueryClasses, either directly or via QueryExpressions.- Parameters:
- constraint- the contraint to test
- Returns:
- true if the contraint is a cross-reference
 
 - 
getQueryFieldsprotected static java.util.Set<QueryField> getQueryFields(QueryEvaluable qe) Descends into QueryExpression and QueryFunction objects to find all instances of QueryField. Will return a single element set for QueryField and an empty set for QueryValue.- Parameters:
- qe- a QueryEvalubale to find QueryFields for
- Returns:
- a set of QueryFields
 
 - 
getLeftArgumentpublic static java.lang.Object getLeftArgument(Constraint constraint) Get the left argument of the given constraint, will return null if passed a ConstraintSet or a MultipleInBagConstraint.- Parameters:
- constraint- a constraint
- Returns:
- the left argument of given constraint
 
 - 
getRightArgumentpublic static java.lang.Object getRightArgument(Constraint constraint) Get the right argument of the given constraint, will return null if passed a ConstraintSet or a MultipleInBagConstraint.- Parameters:
- constraint- a constraint
- Returns:
- the right argument of given constraint
 
 
- 
 
-