public AndImpl and(ConstraintImpl constraint1, ConstraintImpl constraint2) { return new AndImpl(constraint1, constraint2); }
public AndImpl and(ConstraintImpl constraint1, ConstraintImpl constraint2) { return new AndImpl(constraint1, constraint2); }
public AndImpl and(ConstraintImpl constraint1, ConstraintImpl constraint2) { return new AndImpl(constraint1, constraint2); }
@Override public AstElement copyOf() { List<ConstraintImpl> clone = new ArrayList<ConstraintImpl>(constraints.size()); for (ConstraintImpl c : constraints) { clone.add((ConstraintImpl) copyElementAndCheckReference(c)); } return new AndImpl(clone); }
@Override public AstElement copyOf() { List<ConstraintImpl> clone = new ArrayList<ConstraintImpl>(constraints.size()); for (ConstraintImpl c : constraints) { clone.add((ConstraintImpl) copyElementAndCheckReference(c)); } return new AndImpl(clone); }
@Override public AstElement copyOf() { List<ConstraintImpl> clone = new ArrayList<ConstraintImpl>(constraints.size()); for (ConstraintImpl c : constraints) { clone.add((ConstraintImpl) copyElementAndCheckReference(c)); } return new AndImpl(clone); }
public AndImpl pullOrRight() { if (getLastConstraint() instanceof OrImpl) { return this; } ArrayList<ConstraintImpl> andList = getAllAndConditions(); for (int i = 0; i < andList.size() - 1; i++) { ConstraintImpl c = andList.get(i); if (c instanceof OrImpl) { ArrayList<ConstraintImpl> list = new ArrayList<ConstraintImpl>(); list.addAll(andList); list.remove(i); list.add(c); return new AndImpl(list); } } return this; }
@Override public ConstraintImpl simplify() { // Use LinkedHashSet to eliminate duplicate constraints while keeping // the ordering for test cases (and clients?) that depend on it LinkedHashSet<ConstraintImpl> simplified = newLinkedHashSet(); boolean changed = false; // keep track of changes in simplification for (ConstraintImpl constraint : constraints) { ConstraintImpl simple = constraint.simplify(); if (simple instanceof AndImpl) { // unwind nested AND constraints simplified.addAll(((AndImpl) simple).constraints); changed = true; } else if (simplified.add(simple)) { // check if this constraint got simplified changed = changed || simple != constraint; } else { // this constraint was a duplicate of a previous one changed = true; } } if (simplified.size() == 1) { return simplified.iterator().next(); } else if (changed) { return new AndImpl(newArrayList(simplified)); } else { return this; } }
public AndImpl pullOrRight() { if (getLastConstraint() instanceof OrImpl) { return this; } ArrayList<ConstraintImpl> andList = getAllAndConditions(); for (int i = 0; i < andList.size() - 1; i++) { ConstraintImpl c = andList.get(i); if (c instanceof OrImpl) { ArrayList<ConstraintImpl> list = new ArrayList<ConstraintImpl>(); list.addAll(andList); list.remove(i); list.add(c); return new AndImpl(list); } } return this; }
public AndImpl pullOrRight() { if (getLastConstraint() instanceof OrImpl) { return this; } ArrayList<ConstraintImpl> andList = getAllAndConditions(); for (int i = 0; i < andList.size() - 1; i++) { ConstraintImpl c = andList.get(i); if (c instanceof OrImpl) { ArrayList<ConstraintImpl> list = new ArrayList<ConstraintImpl>(); list.addAll(andList); list.remove(i); list.add(c); return new AndImpl(list); } } return this; }
@Override ConstraintImpl not() { // not (X or Y) == (not X) and (not Y) List<ConstraintImpl> list = newArrayList(); for (ConstraintImpl constraint : getConstraints()) { list.add(new NotImpl(constraint)); } return new AndImpl(list).simplify(); }
@Override ConstraintImpl not() { // not (X or Y) == (not X) and (not Y) List<ConstraintImpl> list = newArrayList(); for (ConstraintImpl constraint : getConstraints()) { list.add(new NotImpl(constraint)); } return new AndImpl(list).simplify(); }
@Override ConstraintImpl not() { // not (X or Y) == (not X) and (not Y) List<ConstraintImpl> list = newArrayList(); for (ConstraintImpl constraint : getConstraints()) { list.add(new NotImpl(constraint)); } return new AndImpl(list).simplify(); }
@Override public String getPlan(NodeState rootState) { StringBuilder buff = new StringBuilder(); buff.append(toString()); buff.append(" /* "); QueryIndex index = getIndex(); if (index != null) { if (index instanceof AdvancedQueryIndex) { AdvancedQueryIndex adv = (AdvancedQueryIndex) index; IndexPlan p = plan.getIndexPlan(); buff.append(adv.getPlanDescription(p, rootState)); } else { buff.append(index.getPlan(createFilter(true), rootState)); } } else { buff.append("no-index"); } if (!selectorConstraints.isEmpty()) { buff.append(" where ").append(new AndImpl(selectorConstraints).toString()); } buff.append(" */"); return buff.toString(); }
@Override public String getPlan(NodeState rootState) { StringBuilder buff = new StringBuilder(); buff.append(toString()); buff.append(" /* "); QueryIndex index = getIndex(); if (index != null) { if (index instanceof AdvancedQueryIndex) { AdvancedQueryIndex adv = (AdvancedQueryIndex) index; IndexPlan p = plan.getIndexPlan(); buff.append(adv.getPlanDescription(p, rootState)); } else { buff.append(index.getPlan(createFilter(true), rootState)); } } else { buff.append("no-index"); } if (!selectorConstraints.isEmpty()) { buff.append(" where ").append(new AndImpl(selectorConstraints).toString()); } buff.append(" */"); return buff.toString(); }
@Override public String getPlan(NodeState rootState) { StringBuilder buff = new StringBuilder(); buff.append(toString()); buff.append(" /* "); QueryIndex index = getIndex(); if (index != null) { if (index instanceof AdvancedQueryIndex) { AdvancedQueryIndex adv = (AdvancedQueryIndex) index; IndexPlan p = plan.getIndexPlan(); buff.append(adv.getPlanDescription(p, rootState)); } else { buff.append(index.getPlan(createFilter(true), rootState)); } } else { buff.append("no-index"); } if (!selectorConstraints.isEmpty()) { buff.append(" where ").append(new AndImpl(selectorConstraints).toString()); } buff.append(" */"); return buff.toString(); }
public void addToUnionList(Set<ConstraintImpl> target) { // conditions of type // @a = 1 and (@x = 1 or @y = 2) // are automatically converted to // (@a = 1 and @x = 1) union (@a = 1 and @y = 2) AndImpl and = pullOrRight(); ConstraintImpl last = and.getLastConstraint(); if (last instanceof OrImpl) { OrImpl or = (OrImpl) last; // same as above, but with the added "and" for(ConstraintImpl c : or.getConstraints()) { ArrayList<ConstraintImpl> list = and.getFirstConstraints(); list.add(c); new AndImpl(list).addToUnionList(target); } return; } target.add(this); }
public void addToUnionList(Set<ConstraintImpl> target) { // conditions of type // @a = 1 and (@x = 1 or @y = 2) // are automatically converted to // (@a = 1 and @x = 1) union (@a = 1 and @y = 2) AndImpl and = pullOrRight(); ConstraintImpl last = and.getLastConstraint(); if (last instanceof OrImpl) { OrImpl or = (OrImpl) last; // same as above, but with the added "and" for(ConstraintImpl c : or.getConstraints()) { ArrayList<ConstraintImpl> list = and.getFirstConstraints(); list.add(c); new AndImpl(list).addToUnionList(target); } return; } target.add(this); }
public void addToUnionList(Set<ConstraintImpl> target) { // conditions of type // @a = 1 and (@x = 1 or @y = 2) // are automatically converted to // (@a = 1 and @x = 1) union (@a = 1 and @y = 2) AndImpl and = pullOrRight(); ConstraintImpl last = and.getLastConstraint(); if (last instanceof OrImpl) { OrImpl or = (OrImpl) last; // same as above, but with the added "and" for(ConstraintImpl c : or.getConstraints()) { ArrayList<ConstraintImpl> list = and.getFirstConstraints(); list.add(c); new AndImpl(list).addToUnionList(target); } return; } target.add(this); }
and = new AndImpl(op1, op2); expected = emptySet(); assertThat(and.convertToUnion(), is(expected)); op2 = mockConstraint("op2", ComparisonImpl.class); op3 = mockConstraint("op3", ComparisonImpl.class); and = new AndImpl(new OrImpl(op1, op2), op3); expected = of( (ConstraintImpl) new AndImpl(op1, op3) , (ConstraintImpl) new AndImpl(op2, op3) ); assertThat(and.convertToUnion(), is(expected)); op3 = mockConstraint("op3", ComparisonImpl.class); op4 = mockConstraint("op4", ComparisonImpl.class); and = new AndImpl(new OrImpl(new OrImpl(op1, op4), op2), op3); expected = of( (ConstraintImpl) new AndImpl(op1, op3) , (ConstraintImpl) new AndImpl(op2, op3) , (ConstraintImpl) new AndImpl(op4, op3) ); assertThat(and.convertToUnion(), is(expected));