/** * {@inheritDoc} */ @Override public String toString() { return left.toString() + " " + op.toString() + " " + right.toString(); }
/** * Negate this constraint. i.e equals becomes not equals. */ public void negate() { op = op.negate(); }
/** * Get ConstraintOp for given operation code. * @param operationCode operation as string * @return ConstraintOp if operation code is valid else null */ public static ConstraintOp getConstraintOp(String operationCode) { if (operationCode == null) { return null; } String opCode = operationCode.trim().toUpperCase(); for (ConstraintOp op : values) { if (op.getName().equalsIgnoreCase(opCode)) { return op; } } return null; }
public void testIndexValid() { assertEquals(ConstraintOp.EQUALS, ConstraintOp.getOpForIndex(ConstraintOp.EQUALS.getIndex())); }
if (constraintObj.has("op")) { String op = constraintObj.getString("op"); ConstraintOp constraintOp = ConstraintOp.getConstraintOp( constraintObj.getString("op")); String code = constraintObj.getString("code");
if (constraintObj.has("op")) { String op = constraintObj.getString("op"); ConstraintOp constraintOp = ConstraintOp.getConstraintOp( constraintObj.getString("op")); String code = constraintObj.getString("code");
/** * {@inheritDoc} */ @Override public String toString() { return left.toString() + " " + op.toString() + " " + right.toString(); }
/** * Negate this constraint. i.e equals becomes not equals. */ public void negate() { op = op.negate(); }
ConstraintOp constraintOp = ConstraintOp.getConstraintOp(attrs .get("op")); if (constraintOp == null) {
/** * Get ConstraintOp for given operation code. * @param operationCode operation as string * @return ConstraintOp if operation code is valid else null */ public static ConstraintOp getConstraintOp(String operationCode) { if (operationCode == null) { return null; } String opCode = operationCode.trim().toUpperCase(); for (ConstraintOp op : values) { if (op.getName().equalsIgnoreCase(opCode)) { return op; } } return null; }
/** * Get the JSON prefix common to all constraints. * @param constraint the constraint to format. * @param code The constraint code. * @return The prefix */ protected String getCommonJsonConstraintPrefix(String code, PathConstraint constraint) { String path = constraint.getPath(); String op = constraint.getOp().toString(); return "{\"path\":\"" + path + "\",\"op\":\"" + op + "\",\"code\":\"" + code + "\""; }
/** * Return a new constraint set with each ConstraintOp negated. * @return A negated version of this constraint set. */ public ConstraintOptions negate() { ConstraintOp newMain = (mainSetOp == AND) ? OR : AND; ConstraintOp newRange = (rangeSetOp == AND) ? OR : AND; ConstraintOp newLeft = leftOp.negate(); ConstraintOp newRight = rightOp.negate(); return new ConstraintOptions( newMain, newRange, newLeft, newRight, leftField, rightField ); }
ConstraintOp constraintOp = ConstraintOp.getConstraintOp(attrs .get("op")); if (constraintOp == null) {
/** * Get the JSON prefix common to all constraints. * @param constraint the constraint to format. * @param code The constraint code. * @return The prefix */ protected String getCommonJsonConstraintPrefix(String code, PathConstraint constraint) { String path = constraint.getPath(); String op = constraint.getOp().toString(); return "{\"path\":\"" + path + "\",\"op\":\"" + op + "\",\"code\":\"" + code + "\""; }
/** * Return a new constraint set with each ConstraintOp negated. * @return A negated version of this constraint set. */ public ConstraintOptions negate() { ConstraintOp newMain = (mainSetOp == AND) ? OR : AND; ConstraintOp newRange = (rangeSetOp == AND) ? OR : AND; ConstraintOp newLeft = leftOp.negate(); ConstraintOp newRight = rightOp.negate(); return new ConstraintOptions( newMain, newRange, newLeft, newRight, leftField, rightField ); }
sb.append("\"" + type + "\""); } else if ("PathConstraintNull".equals(className)) { sb.append("\"" + op.toString() + "\""); } else if ("PathConstraintAttribute".equals(className)) { String value = ((PathConstraintAttribute) pc).getValue(); sb.append("\"" + op.toString() + "\""); sb.append(", \"" + value + "\""); } else if ("PathConstraintLookup".equals(className)) { String value = ((PathConstraintLookup) pc).getValue(); String extraValue = ((PathConstraintLookup) pc).getExtraValue(); sb.append('"').append(op.toString()).append('"'); sb.append(", \"").append(value).append('"'); if (extraValue != null) { sb.append("\"" + op.toString() + "\""); sb.append(", \"" + list + "\""); } else if ("PathConstraintMultiValue".equals(className)) { sb.append("\"" + op.toString() + "\""); sb.append(", ["); Collection<String> values = ((PathConstraintMultiValue) pc).getValues();
/** * By default the CONTAINS options are same as the WITHIN options with the left and * right operators swapped. * @return The options that define what it means for the constrained object to CONTAIN * a given set of ranges. */ protected ConstraintOptions getContainsOptions() { ConstraintOptions withinOpts = getWithinOptions(); // by default the same as within, with right and left operations swapped. return new ConstraintOptions( withinOpts.getMainSetOp(), withinOpts.getRangeSetOp(), withinOpts.getLeftOp().negate(), withinOpts.getRightOp().negate(), withinOpts.getLeftField(), withinOpts.getRightField() ); }
sb.append("\"" + type + "\""); } else if ("PathConstraintNull".equals(className)) { sb.append("\"" + op.toString() + "\""); } else if ("PathConstraintAttribute".equals(className)) { String value = ((PathConstraintAttribute) pc).getValue(); sb.append("\"" + op.toString() + "\""); sb.append(", \"" + value + "\""); } else if ("PathConstraintLookup".equals(className)) { String value = ((PathConstraintLookup) pc).getValue(); String extraValue = ((PathConstraintLookup) pc).getExtraValue(); sb.append('"').append(op.toString()).append('"'); sb.append(", \"").append(value).append('"'); if (extraValue != null) { sb.append("\"" + op.toString() + "\""); sb.append(", \"" + list + "\""); } else if ("PathConstraintMultiValue".equals(className)) { sb.append("\"" + op.toString() + "\""); sb.append(", ["); Collection<String> values = ((PathConstraintMultiValue) pc).getValues();
/** * By default the CONTAINS options are same as the WITHIN options with the left and * right operators swapped. * @return The options that define what it means for the constrained object to CONTAIN * a given set of ranges. */ protected ConstraintOptions getContainsOptions() { ConstraintOptions withinOpts = getWithinOptions(); // by default the same as within, with right and left operations swapped. return new ConstraintOptions( withinOpts.getMainSetOp(), withinOpts.getRangeSetOp(), withinOpts.getLeftOp().negate(), withinOpts.getRightOp().negate(), withinOpts.getLeftField(), withinOpts.getRightField() ); }
public void testToString() { assertEquals("=", ConstraintOp.EQUALS.toString()); } }