/** * Get the Set of variable names. * @return set of variable names in this expression */ public Set<String> getVariableNames() { Set<String> variables = new HashSet<String>(); getVariableNames(variables, root); return variables; }
/** * Get the Set of variable names. * @return set of variable names in this expression */ public Set<String> getVariableNames() { Set<String> variables = new HashSet<String>(); getVariableNames(variables, root); return variables; }
private void getVariableNames(Set<String> variables, Node node) { if (node instanceof Operator) { for (Node child : ((Operator) node).getChildren()) { getVariableNames(variables, child); } } else { variables.add(((Variable) node).getName()); } }
private void getVariableNames(Set<String> variables, Node node) { if (node instanceof Operator) { for (Node child : ((Operator) node).getChildren()) { getVariableNames(variables, child); } } else { variables.add(((Variable) node).getName()); } }
/** * Removes a constraint from this query. The PathConstraint should be a constraint that already * exists in this query. The constraint will also be removed from the constraint logic. * * @param constraint the PathConstraint to remove from this query * @throws NullPointerException if the constraint is null * @throws NoSuchElementException if the constraint is not present in the query */ public synchronized void removeConstraint(PathConstraint constraint) { deVerify(); if (constraint == null) { throw new NullPointerException("Cannot remove null constraint from this query"); } if (constraints.containsKey(constraint)) { String code = constraints.remove(constraint); if (code != null) { if (logic.getVariableNames().size() > 1) { logic.removeVariable(code); } else { logic = null; } } } else { throw new NoSuchElementException("Constraint to remove is not present in query"); } }
/** * Removes a constraint from this query. The PathConstraint should be a constraint that already * exists in this query. The constraint will also be removed from the constraint logic. * * @param constraint the PathConstraint to remove from this query * @throws NullPointerException if the constraint is null * @throws NoSuchElementException if the constraint is not present in the query */ public synchronized void removeConstraint(PathConstraint constraint) { deVerify(); if (constraint == null) { throw new NullPointerException("Cannot remove null constraint from this query"); } if (constraints.containsKey(constraint)) { String code = constraints.remove(constraint); if (code != null) { if (logic.getVariableNames().size() > 1) { logic.removeVariable(code); } else { logic = null; } } } else { throw new NoSuchElementException("Constraint to remove is not present in query"); } }
return null; if (!getVariableNames().containsAll(variables)) { throw new IllegalArgumentException("Unrecognised variables in request"); return this; } else if (root instanceof Or) { if (variables.containsAll(getVariableNames())) { return this; } else { for (Node node : and.getChildren()) { Set<String> hasVariables = new HashSet<String>(); getVariableNames(hasVariables, node); boolean containsAll = true; boolean containsNone = true;
if (!presentVariables.equals(getVariableNames())) { throw new IllegalArgumentException("Variables in argument (" + presentVariables + ") do not match variables in expression (" + getVariableNames() + ")"); getVariableNames(hasVariables, node); int bucketNo = -1; for (int i = 0; i < variables.size(); i++) {
if (!presentVariables.equals(getVariableNames())) { throw new IllegalArgumentException("Variables in argument (" + presentVariables + ") do not match variables in expression (" + getVariableNames() + ")");
if (!presentVariables.equals(getVariableNames())) { throw new IllegalArgumentException("Variables in argument (" + presentVariables + ") do not match variables in expression (" + getVariableNames() + ")");
/** * Sets the current constraint logic. * * @param logic the constraint logic */ public synchronized void setConstraintLogic(String logic) { // TODO method does not work properly allowing (A and B) or C on Outer Joins deVerify(); if (constraints.isEmpty()) { this.logic = null; } else { this.logic = new LogicExpression(logic); for (String code : constraints.values()) { if (!this.logic.getVariableNames().contains(code)) { this.logic = new LogicExpression("(" + this.logic.toString() + ") and " + code); } } this.logic.removeAllVariablesExcept(constraints.values()); } }
/** * Sets the current constraint logic. * * @param logic the constraint logic */ public synchronized void setConstraintLogic(String logic) { // TODO method does not work properly allowing (A and B) or C on Outer Joins deVerify(); if (constraints.isEmpty()) { this.logic = null; } else { this.logic = new LogicExpression(logic); for (String code : constraints.values()) { if (!this.logic.getVariableNames().contains(code)) { this.logic = new LogicExpression("(" + this.logic.toString() + ") and " + code); } } this.logic.removeAllVariablesExcept(constraints.values()); } }
public void test4() { LogicExpression l = new LogicExpression("A and (B and C)"); assertEquals(new HashSet<String>(Arrays.asList("A", "B", "C")), l.getVariableNames()); assertEquals("A and B and C", l.toString()); assertEquals(Arrays.asList(new LogicExpression("A and C"), new LogicExpression("B")), l.split(Arrays.asList(Arrays.asList("A", "C"), Arrays.asList("B")))); }
public void test6() { LogicExpression l = new LogicExpression("A and (B or C and D)"); assertEquals(new HashSet<String>(Arrays.asList("A", "B", "C", "D")), l.getVariableNames()); assertEquals("A and (B or (C and D))", l.toString()); assertEquals(Arrays.asList(new LogicExpression("A"), new LogicExpression("B or (C and D)")), l.split(Arrays.asList(Arrays.asList("A"), Arrays.asList("B", "C", "D")))); try { l.split(Arrays.asList(Arrays.asList("A", "B", "C"), Arrays.asList("D"))); fail("Expected exception"); } catch (IllegalArgumentException e) { } }
public void test5() { LogicExpression l = new LogicExpression("A and (B or C)"); assertEquals(new HashSet<String>(Arrays.asList("A", "B", "C")), l.getVariableNames()); assertEquals("A and (B or C)", l.toString()); assertEquals(Arrays.asList(new LogicExpression("A"), new LogicExpression("B or C"), null), l.split(Arrays.asList(Arrays.asList("A"), Arrays.asList("B", "C"), empty))); assertEquals(new LogicExpression("A and (B or C)"), l.getSection(Arrays.asList("A", "B", "C"))); assertEquals(Arrays.asList(new LogicExpression("A and (B or C)")), l.split(Arrays.asList(Arrays.asList("A", "B", "C")))); assertTrue(l == l.validateForGroups(Arrays.asList(Arrays.asList("A", "B", "C")))); assertTrue(l == l.validateForGroups(Arrays.asList(Arrays.asList("A"), Arrays.asList("B", "C")))); assertEquals(new LogicExpression("A and B and C"), l.validateForGroups(Arrays.asList(Arrays.asList("A", "B"), Arrays.asList("C")))); }
public void testRemoveVariables1() { LogicExpression l = new LogicExpression("(A or B) and (C or D)"); assertEquals(new HashSet<String>(Arrays.asList("A", "B", "C", "D")), l.getVariableNames()); assertEquals("(A or B) and (C or D)", l.toString()); l.removeAllVariablesExcept(Arrays.asList("C", "D")); assertEquals("C or D", l.toString()); }
public void test3() { LogicExpression l = new LogicExpression("A or B"); assertEquals(new HashSet<String>(Arrays.asList("A", "B")), l.getVariableNames()); assertEquals("A or B", l.toString()); try { l.split(Arrays.asList(Arrays.asList("A"), Arrays.asList("B"))); fail("Expected exception"); } catch (IllegalArgumentException e) { } assertEquals(Arrays.asList(new LogicExpression("A or B")), l.split(Arrays.asList(Arrays.asList("A", "B")))); assertEquals(new LogicExpression("A or B"), l.getSection(Arrays.asList("A", "B"))); try { l.getSection(Arrays.asList("A")); fail("Expected exception"); } catch (IllegalArgumentException e) { } assertEquals(new LogicExpression("A and B"), l.validateForGroups(Arrays.asList(Arrays.asList("A"), Arrays.asList("B")))); assertTrue(l == l.validateForGroups(Arrays.asList(Arrays.asList("A", "B")))); try { l.validateForGroups(Arrays.asList(Arrays.asList("A"))); fail("Expected exception"); } catch (IllegalArgumentException e) { } }
public void test1() { LogicExpression l = new LogicExpression("A"); assertEquals(Collections.singleton("A"), l.getVariableNames()); assertEquals("A", l.toString()); assertEquals(Collections.singletonList(new LogicExpression("A")), l.split(Collections.singletonList(Collections.singletonList("A")))); assertEquals(new LogicExpression("A"), l.getSection(Arrays.asList("A"))); assertEquals(null, l.getSection(empty)); try { l.getSection(Arrays.asList("B")); fail("Expected exception"); } catch (IllegalArgumentException e) { } assertEquals(new LogicExpression("A"), l.validateForGroups(Arrays.asList(Arrays.asList("A")))); }
@SuppressWarnings({ }) public void test2() { LogicExpression l = new LogicExpression("A and B"); assertEquals(new HashSet<String>(Arrays.asList("A", "B")), l.getVariableNames()); assertEquals("A and B", l.toString()); assertEquals(Arrays.asList(new LogicExpression("A"), new LogicExpression("B")), l.split(Arrays.asList(Arrays.asList("A"), Arrays.asList("B")))); try { l.split(Arrays.asList(Arrays.asList("A"))); fail("Expected exception"); } catch (IllegalArgumentException e) { } try { l.split(Arrays.asList(Arrays.asList("A", "B", "C"))); fail("Expected exception"); } catch (IllegalArgumentException e) { } try { l.split(Arrays.asList(Arrays.asList("A", "B"), Arrays.asList("A"))); fail("Expected exception"); } catch (IllegalArgumentException e) { } assertEquals(new LogicExpression("A"), l.getSection(Arrays.asList("A"))); assertEquals(new LogicExpression("A and B"), l.getSection(Arrays.asList("A", "B"))); assertTrue(l == l.validateForGroups(Arrays.asList(Arrays.asList("A"), Arrays.asList("B")))); assertTrue(l == l.validateForGroups(Arrays.asList(Arrays.asList("A", "B")))); }
public void testRemoveVariables2() { LogicExpression l = new LogicExpression("(A or B) and (C or D)"); assertEquals(new HashSet<String>(Arrays.asList("A", "B", "C", "D")), l.getVariableNames()); assertEquals("(A or B) and (C or D)", l.toString()); l.removeVariable("A"); assertEquals("B and (C or D)", l.toString()); l.removeVariable("B"); assertEquals("C or D", l.toString()); }