Esempio n. 1
0
 @Override
 public void validate() throws ValidationException {
   if (iD.equals(Amount.ZERO)) throw new ValidationException(this, "Invalid iD");
   if (oD.equals(Amount.ZERO)) throw new ValidationException(this, "Invalid oD");
   if (getLength().equals(Amount.ZERO)) throw new ValidationException(this, "Invalid Length");
   if (iD.isGreaterThan(oD)) throw new ValidationException(this, "iD > oD");
 }
Esempio n. 2
0
  /**
   * Returns a short description of the type of constraint.
   *
   * @param constraint
   * @param includeThat
   * @return null if the constraint is invalid
   */
  public static String getDescription(BinaryTemporalConstraint constraint, boolean includeThat) {
    Amount<Duration> minimum = constraint.getMinimumBminusA();
    Amount<Duration> maximum = constraint.getMaximumBminusA();
    // construct the string
    if (minimum == null && maximum == null) {
      return null;
    }

    String minimumStr =
        minimum == null ? null : EnsembleAmountFormat.INSTANCE.formatAmount(minimum.abs());
    String maximumStr =
        maximum == null ? null : EnsembleAmountFormat.INSTANCE.formatAmount(maximum.abs());
    String string = "";
    if (minimum == null && maximum != null) {
      // any time after
      if (maximum.approximates(ZERO)) {
        string += "anytime after";
      }
      // at least after
      else if (maximum.isLessThan(ZERO)) {
        string += "at least " + maximumStr + " after";
      }
      // at most before
      else { // max > 0
        string += "at most " + maximumStr + " before";
      }
    } else if (maximum == null && minimum != null) {
      // anytime before
      if (minimum.approximates(ZERO)) {
        string += "anytime before";
      }
      // at most after
      else if (minimum.isLessThan(ZERO)) {
        string += "at most " + minimumStr + " after";
      }
      // at least before
      else { // min > 0
        string += "at least " + minimumStr + " before";
      }
    }
    // at the same time
    else if (minimum != null
        && minimum.approximates(ZERO)
        && maximum != null
        && maximum.approximates(ZERO)) {
      string += "at the same time";
      if (includeThat) {
        if (constraint.getPointB().hasEndpoint()) {
          string += " that";
        } else {
          string += " as";
        }
      }
    }
    // exactly
    else if (minimum != null && minimum.approximates(maximum)) {
      string += "exactly ";
      string += minimumStr;
      if (minimum.isLessThan(ZERO)) {
        string += " after";
      } else { // min > 0
        string += " before";
      }
    }
    // between
    else {
      string += "between ";
      String minAndMaxStr;
      if (maximum != null && minimum != null && minimum.abs().isLessThan(maximum.abs())) {
        minAndMaxStr = minimumStr + " and " + maximumStr;
      } else {
        minAndMaxStr = maximumStr + " and " + minimumStr;
      }
      // after
      if (minimum != null
          && maximum != null
          && !minimum.isGreaterThan(ZERO)
          && !maximum.isGreaterThan(ZERO)) { // min <= 0 && max <= 0
        string += minAndMaxStr;
        string += " after";
      }
      // before
      else if (minimum != null
          && maximum != null
          && !minimum.isLessThan(ZERO)
          && !maximum.isLessThan(ZERO)) { // min >= 0 && max >= 0
        string += minAndMaxStr;
        string += " before";
      }
      // before and after
      else if (minimum != null
          && minimum.isLessThan(ZERO)
          && maximum != null
          && maximum.isGreaterThan(ZERO)) {
        string += maximumStr + " before and " + minimumStr + " after";
      } else {
        return null;
      }
    }
    return string;
  }