public void andWith ( OrCondition other ) { //Because Titan does not natively support Or conditions in Graph Queries, //we need to expand out the condition so it is in the form of a single OrCondition //that contains only AndConditions. We do this by following the rules of boolean //algebra. As an example, suppose the current condition is ((a=1 and b=2) or (c=3 and d=4)). //Suppose "other" is ((e=5 and f=6) or (g=7 or h=8)). The overall condition, after applying the //"and" is: // //((a=1 and b=2) or (c=3 and d=4)) and ((e=5 and f=6) or (g=7 and h=8)) // //This needs to be expanded out to remove the nested or clauses. The result of this expansion is: // //(a=1 and b=2 and e=5 and f=6) or //(a=1 and b=2 and g=7 and h=8) or //(c=3 and d=4 and e=5 and f=6) or //(c=3 and d=4 and g=7 and h=8) //The logic below does this expansion, in a generalized way. It loops through the existing AndConditions //and, in a nested loop, through the AndConditions in "other". For each of those combinations, //it creates a new AndCondition that combines the two AndConditions together. These combined //AndConditions become the new set of AndConditions in this OrCondition. List < AndCondition > expandedExpressionChildren = new ArrayList <> ( ) ; for ( AndCondition otherExprTerm : other . getAndTerms ( ) ) { for ( AndCondition currentExpr : children ) { AndCondition currentAndConditionCopy = currentExpr . copy ( ) ; currentAndConditionCopy . andWith ( otherExprTerm . getTerms ( ) ) ; expandedExpressionChildren . add ( currentAndConditionCopy ) ; } } children = expandedExpressionChildren ; }
Updates this OrCondition in place so that it matches vertices that satisfy the current OrCondition AND that satisfy the provided OrCondition .