/** * Returns the current constraint logic. The logic is returned in groups, according to the outer * join layout of the query. Two codes in separate groups can only be combined with an AND * operation and OR operation. * * @return the current constraint logic */ public synchronized String getConstraintLogic() { return (logic == null ? "" : logic.toString()); }
/** * Returns the current constraint logic. The logic is returned in groups, according to the outer * join layout of the query. Two codes in separate groups can only be combined with an AND * operation and OR operation. * * @return the current constraint logic */ public synchronized String getConstraintLogic() { return (logic == null ? "" : logic.toString()); }
/** * {@inheritDoc} */ @Override public int hashCode() { return toString().hashCode(); }
/** * {@inheritDoc} */ @Override public int hashCode() { return toString().hashCode(); }
/** * {@inheritDoc} */ @Override public boolean equals(Object o) { if (o instanceof LogicExpression) { return toString().equals(o.toString()); } return false; }
/** * {@inheritDoc} */ @Override public boolean equals(Object o) { if (o instanceof LogicExpression) { return toString().equals(o.toString()); } return false; }
/** * Remove a variable from the expression. * @param name variable to remove */ public void removeVariable(String name) { if (root instanceof Operator) { removeVariable(name, (Operator) root); } else if (root instanceof Variable && ((Variable) root).getName().equals(name)) { throw new IllegalArgumentException("Removing root node"); } String logic = toString(); root = parse(logic); }
/** * Remove a variable from the expression. * @param name variable to remove */ public void removeVariable(String name) { if (root instanceof Operator) { removeVariable(name, (Operator) root); } else if (root instanceof Variable && ((Variable) root).getName().equals(name)) { throw new IllegalArgumentException("Removing root node"); } String logic = toString(); root = parse(logic); }
/** * Remove any variables that aren't in the given set. * @param variables Collection of variable names */ public void removeAllVariablesExcept(Collection<String> variables) { if (root instanceof Operator) { removeAllVariablesExcept(variables, (Operator) root); } else if (root instanceof Variable && !variables.contains(((Variable) root).getName())) { throw new IllegalArgumentException("Removing root node"); } String logic = toString(); root = parse(logic); }
/** * Remove any variables that aren't in the given set. * @param variables Collection of variable names */ public void removeAllVariablesExcept(Collection<String> variables) { if (root instanceof Operator) { removeAllVariablesExcept(variables, (Operator) root); } else if (root instanceof Variable && !variables.contains(((Variable) root).getName())) { throw new IllegalArgumentException("Removing root node"); } String logic = toString(); root = parse(logic); }
public void testBrackets2() { LogicExpression l = new LogicExpression("A and (B or C)"); assertEquals("A and (B or C)", l.toString()); }
public void testBrackets1() { LogicExpression l = new LogicExpression("A and B or C"); assertEquals("(A and B) or C", l.toString()); }
public void testBrackets3() { LogicExpression l = new LogicExpression("(A and B) or C"); assertEquals("(A and B) or C", l.toString()); }
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 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()); }
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 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 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 testRemoveFromConstraintLogic() throws Exception { LogicExpression l = new LogicExpression("A and B"); LogicExpression updated = MainHelper.removeFromConstraintLogic(l, "B"); assertEquals("A", updated.toString()); l = new LogicExpression("A and B"); updated = MainHelper.removeFromConstraintLogic(l, "A"); assertEquals("B", updated.toString()); l = new LogicExpression("(A and B) or (C and D)"); updated = MainHelper.removeFromConstraintLogic(l, "C"); assertEquals("(A and B) or D", updated.toString()); l = new LogicExpression("A"); assertNull(MainHelper.removeFromConstraintLogic(l, "A")); }
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")))); }