@Override public int hashCode() { int result = getOp().hashCode(); result = 31 * result + getScope().hashCode(); result = 31 * result + getTargetExpressions().hashCode(); return result; }
Assert.assertEquals(single.toString(), target.toString()); Assert.assertEquals(single.getScope(), target.getScope()); Assert.assertEquals(TargetOperator.IN, target.getOp()); Assert.assertEquals(single.getTargetExpressions(), target.getTargetExpressions()); Assert.assertEquals(target.getScope(), single.getScope()); Assert.assertEquals(1, single.getMinCardinality()); Assert.assertEquals(Integer.MAX_VALUE, single.getMaxCardinality()); Assert.assertEquals(single.getTargetExpressions(), target.getTargetExpressions());
@Override public AbstractConstraint visit(SingleConstraint constraint) { AbstractConstraint transformedConstraint = constraint; // Check if it is a target constraint. if (constraint.getMinCardinality() == 1 && constraint.getMaxCardinality() == Integer.MAX_VALUE) { transformedConstraint = new TargetConstraint(TargetOperator.IN, constraint.getScope(), constraint.getTargetExpressions()); } else if (constraint.getMinCardinality() == 0 && constraint.getMaxCardinality() == 0) { transformedConstraint = new TargetConstraint(TargetOperator.NOT_IN, constraint.getScope(), constraint.getTargetExpressions()); } return transformedConstraint; } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof TargetConstraint)) { return false; } TargetConstraint that = (TargetConstraint) o; if (getOp() != that.getOp()) { return false; } if (!getScope().equals(that.getScope())) { return false; } return getTargetExpressions().equals(that.getTargetExpressions()); }
@Override public AbstractConstraint visit(TargetConstraint constraint) { AbstractConstraint newConstraint; if (constraint.getOp() == TargetOperator.IN) { newConstraint = new SingleConstraint(constraint.getScope(), 1, Integer.MAX_VALUE, constraint.getTargetExpressions()); } else if (constraint.getOp() == TargetOperator.NOT_IN) { newConstraint = new SingleConstraint(constraint.getScope(), 0, 0, constraint.getTargetExpressions()); } else { throw new YarnRuntimeException( "Encountered unexpected type of constraint target operator: " + constraint.getOp()); } return newConstraint; }
@Override public String toString() { List<String> targetExprs = getTargetExpressions().stream().map( targetExpression -> new StringBuilder() .append(op.getOperator()).append(",") .append(scope).append(",") .append(targetExpression.toString()) .toString()).collect(Collectors.toList()); return String.join(":", targetExprs); }