예제 #1
0
  public Bound max(Bound aBound) {

    if (equals(MAX)) {
      return this;
    }

    if (aBound.equals(MAX)) {
      return aBound;
    }

    if (this.value.max(aBound.getValue()).equals(this.value)) {
      return this;
    } else {
      return aBound;
    }
  }
예제 #2
0
  @Override
  public int compareTo(Bound bound) {

    if (bound == null) {
      throw new InternalException("bound may not be null");
    }

    if (getClass() != bound.getClass()) {
      throw new InternalException("bound must have the same class");
    }

    if (this.value == null || bound.value == null) {
      if (this == MIN) {
        return bound == MIN ? 0 : -1;
      }

      if (this == MAX) {
        return bound == MAX ? 0 : 1;
      }

      if (bound == MIN) {
        return 1;
      }

      return -1;
    }

    return this.value.compareTo(bound.value);
  }
예제 #3
0
  public Bound subtract(Bound bound) {

    if (bound == null) {
      throw new InternalError("value shouldn't be null");
    }

    if (equals(MAX) && bound.equals(MAX) || equals(MIN) && bound.equals(MIN)) {
      throw new InternalError("Canno't subtract + infinite and - infinite");
    }

    if (bound.equals(MAX) || equals(MIN)) {
      return MIN;
    } else if (bound.equals(MIN) || equals(MAX)) {
      return MAX;
    } else {
      return new Bound(this.value.subtract(bound.getValue()));
    }
  }