/** * Recursively add constraints and their parents. * @param sortedConst the array to fill. * @param fieldConst the constraint to investigate. */ private void insertSingleFieldConstraint(SingleFieldConstraint fieldConst, List<FieldConstraint> sortedConst) { if (fieldConst.getParent() instanceof SingleFieldConstraint) { insertSingleFieldConstraint((SingleFieldConstraint) fieldConst.getParent(), sortedConst); } sortedConst.add(fieldConst); }
/** * Recursively add constraints and their parents. * @param sortedConst the array to fill. * @param fieldConst the constraint to investigate. */ private void insertSingleFieldConstraint(SingleFieldConstraint fieldConst, List<FieldConstraint> sortedConst) { if (fieldConst.getParent() instanceof SingleFieldConstraint) { insertSingleFieldConstraint((SingleFieldConstraint) fieldConst.getParent(), sortedConst); } sortedConst.add(fieldConst); }
public void removeConstraint( final int idx ) { //If the constraint being is a parent of another correct the other constraint's parent accordingly FieldConstraint constraintToRemove = this.constraints[ idx ]; if ( constraintToRemove instanceof SingleFieldConstraint ) { final SingleFieldConstraint sfc = (SingleFieldConstraint) constraintToRemove; FieldConstraint parent = sfc.getParent(); for ( FieldConstraint child : this.constraints ) { if ( child instanceof SingleFieldConstraint ) { SingleFieldConstraint sfcChild = (SingleFieldConstraint) child; if ( sfcChild.getParent() == constraintToRemove ) { sfcChild.setParent( parent ); break; } } } } final FieldConstraint[] newList = new FieldConstraint[ this.constraints.length - 1 ]; int newIdx = 0; for ( int i = 0; i < this.constraints.length; i++ ) { if ( i != idx ) { newList[ newIdx ] = this.constraints[ i ]; newIdx++; } } this.constraints = newList; }
/** * Sort the rule constraints such that parent rules are inserted directly * before their child rules. * @param constraints the list of inheriting constraints to sort. * @return a sorted list of constraints ready for display. */ private List<FieldConstraint> sortConstraints(FieldConstraint[] constraints) { List<FieldConstraint> sortedConst = new ArrayList<FieldConstraint>(constraints.length); for (int i = 0; i < constraints.length; i++) { FieldConstraint current = constraints[i]; if (current instanceof SingleFieldConstraint) { SingleFieldConstraint single = (SingleFieldConstraint) current; int index = sortedConst.indexOf(single.getParent()); if (single.getParent() == null) { sortedConst.add(single); } else if (index >= 0) { sortedConst.add(index + 1, single); } else { insertSingleFieldConstraint(single, sortedConst); } } else { sortedConst.add(current); } } return sortedConst; }
/** * Sort the rule constraints such that parent rules are inserted directly * before their child rules. * @param constraints the list of inheriting constraints to sort. * @return a sorted list of constraints ready for display. */ private List<FieldConstraint> sortConstraints(FieldConstraint[] constraints) { List<FieldConstraint> sortedConst = new ArrayList<FieldConstraint>(constraints.length); for (int i = 0; i < constraints.length; i++) { FieldConstraint current = constraints[i]; if (current instanceof SingleFieldConstraint) { SingleFieldConstraint single = (SingleFieldConstraint) current; int index = sortedConst.indexOf(single.getParent()); if (single.getParent() == null) { sortedConst.add(single); } else if (index >= 0) { sortedConst.add(index + 1, single); } else { insertSingleFieldConstraint(single, sortedConst); } } else { sortedConst.add(current); } } return sortedConst; }
if (current instanceof SingleFieldConstraint) { SingleFieldConstraint single = (SingleFieldConstraint) current; FieldConstraint parent = single.getParent();
if (current instanceof SingleFieldConstraint) { SingleFieldConstraint single = (SingleFieldConstraint) current; FieldConstraint parent = single.getParent();
buf.append(sfcexp.getExpressionLeftSide().getText(visitor)); } else { SingleFieldConstraint parent = (SingleFieldConstraint) constr.getParent(); StringBuilder parentBuf = new StringBuilder(); while (parent != null) { parentBuf.insert(0, fieldName + "."); parent = (SingleFieldConstraint) parent.getParent();
if (con.getParent() == null) { con.setParent(createParentFor(m, factPattern,
private void fixConstraints(FactPattern fp, SingleFieldConstraint sfc) { final FieldConstraint parent = sfc.getParent(); if (parent == null) { sfc.setFactType(fp.getFactType()); } else if (parent instanceof SingleFieldConstraint) { sfc.setFactType(((SingleFieldConstraint) parent).getFieldType()); } sfc.setFieldName(fixFieldName(sfc.getFieldName())); if (sfc.getConnectives() == null) { return; } for (ConnectiveConstraint cc : sfc.getConnectives()) { cc.setFactType(fp.getFactType()); cc.setFieldName(fixFieldName(cc.getFieldName())); } }
private SingleFieldConstraint visitSingleFieldConstraint(SingleFieldConstraint sfc) { SingleFieldConstraint clone = new SingleFieldConstraint(); clone.setConstraintValueType(sfc.getConstraintValueType()); clone.setExpressionValue((ExpressionFormLine) visit(sfc.getExpressionValue())); clone.setFieldBinding(sfc.getFieldBinding()); clone.setFactType(sfc.getFactType()); clone.setFieldName(sfc.getFieldName()); clone.setFieldType(sfc.getFieldType()); clone.setId(sfc.getId()); clone.setOperator(sfc.getOperator()); clone.setParent((FieldConstraint) visit(sfc.getParent())); for (Map.Entry<String, String> entry : sfc.getParameters().entrySet()) { clone.setParameter(entry.getKey(), entry.getValue()); } clone.setValue(sfc.getValue()); if (sfc.getConnectives() != null) { clone.setConnectives(new ConnectiveConstraint[sfc.getConnectives().length]); for (int i = 0; i < sfc.getConnectives().length; i++) { clone.getConnectives()[i] = (ConnectiveConstraint) visit(sfc.getConnectives()[i]); } } return clone; }
private SingleFieldConstraint visitSingleFieldConstraint(SingleFieldConstraint sfc) { SingleFieldConstraint clone = new SingleFieldConstraint(); clone.setConstraintValueType(sfc.getConstraintValueType()); clone.setExpressionValue((ExpressionFormLine) visit(sfc.getExpressionValue())); clone.setFieldBinding(sfc.getFieldBinding()); clone.setFactType(sfc.getFactType()); clone.setFieldName(sfc.getFieldName()); clone.setFieldType(sfc.getFieldType()); clone.setId(sfc.getId()); clone.setOperator(sfc.getOperator()); clone.setParent((FieldConstraint) visit(sfc.getParent())); for (Map.Entry<String, String> entry : sfc.getParameters().entrySet()) { clone.setParameter(entry.getKey(), entry.getValue()); } clone.setValue(sfc.getValue()); if (sfc.getConnectives() != null) { clone.setConnectives(new ConnectiveConstraint[sfc.getConnectives().length]); for (int i = 0; i < sfc.getConnectives().length; i++) { clone.getConnectives()[i] = (ConnectiveConstraint) visit(sfc.getConnectives()[i]); } } return clone; }