コード例 #1
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   ContinuousRealInterval other = (ContinuousRealInterval) obj;
   if (inclusiveLower != other.inclusiveLower) return false;
   if (inclusiveUpper != other.inclusiveUpper) return false;
   if (lower == null) {
     if (other.lower != null) return false;
   } else if (OWLRealUtils.compare(lower, other.lower) != 0) return false;
   if (upper == null) {
     if (other.upper != null) return false;
   } else if (OWLRealUtils.compare(upper, other.upper) != 0) return false;
   return true;
 }
コード例 #2
0
  /**
   * Create an interval. <code>null</code> should be used to indicate unbound (i.e., infinite
   * intervals).
   *
   * @param lower Interval lower bound
   * @param upper Interval upper bound
   * @param inclusiveLower <code>true</code> if lower bound is inclusive, <code>false</code> for
   *     exclusive. Ignored if <code>lower == null</code>.
   * @param inclusiveUpper <code>true</code> if upper bound is inclusive, <code>false</code> for
   *     exclusive. Ignored if <code>upper == null</code>.
   */
  public ContinuousRealInterval(
      Number lower, Number upper, boolean inclusiveLower, boolean inclusiveUpper) {
    if (lower != null && upper != null) {
      final int cmp = OWLRealUtils.compare(lower, upper);
      if (cmp > 0) {
        final String msg =
            format(
                "Lower bound of interval (%s) should not be greater than upper bound of interval (%s)",
                lower, upper);
        log.severe(msg);
        throw new IllegalArgumentException(msg);
      } else if (cmp == 0) {
        if ((!inclusiveLower || !inclusiveUpper)) {
          final String msg = "Point intervals must be inclusive";
          log.severe(msg);
          throw new IllegalArgumentException(msg);
        }
      }
    }

    this.lower = lower;
    this.upper = upper;
    this.inclusiveLower = (lower == null) ? false : inclusiveLower;
    this.inclusiveUpper = (upper == null) ? false : inclusiveUpper;

    this.point = (lower != null && upper != null && lower.equals(upper));
  }
コード例 #3
0
 private static int compareUpperLower(ContinuousRealInterval a, ContinuousRealInterval b) {
   int ul;
   if (!a.boundUpper()) ul = 1;
   else if (!b.boundLower()) ul = 1;
   else ul = OWLRealUtils.compare(a.getUpper(), b.getLower());
   return ul;
 }
コード例 #4
0
  public boolean contains(Number n) {

    int comp;
    if (boundLower()) {
      comp = OWLRealUtils.compare(getLower(), n);
      if (comp > 0) return false;
      if ((comp == 0) && !inclusiveLower()) return false;
    }

    if (boundUpper()) {
      comp = OWLRealUtils.compare(getUpper(), n);
      if (comp < 0) return false;
      if ((comp == 0) && !inclusiveUpper()) return false;
    }

    return true;
  }
コード例 #5
0
 private static int compareUpperUpper(ContinuousRealInterval a, ContinuousRealInterval b) {
   int uu;
   if (!a.boundUpper()) {
     if (!b.boundUpper()) uu = 0;
     else uu = 1;
   } else if (!b.boundUpper()) uu = -1;
   else {
     uu = OWLRealUtils.compare(a.getUpper(), b.getUpper());
     if (uu == 0) {
       if (a.inclusiveUpper()) {
         if (!b.inclusiveUpper()) uu = 1;
       } else if (b.inclusiveUpper()) uu = -1;
     }
   }
   return uu;
 }
コード例 #6
0
 private static int compareLowerLower(ContinuousRealInterval a, ContinuousRealInterval other) {
   int ll;
   if (!a.boundLower()) {
     if (!other.boundLower()) ll = 0;
     else ll = -1;
   } else {
     if (!other.boundLower()) ll = 1;
     else {
       ll = OWLRealUtils.compare(a.getLower(), other.getLower());
       if (ll == 0) {
         if (a.inclusiveLower()) {
           if (!other.inclusiveLower()) ll = -1;
         } else if (other.inclusiveLower()) ll = 1;
       }
     }
   }
   return ll;
 }
コード例 #7
0
 /**
  * Get the subinterval less than n
  *
  * @param n
  * @return a new interval, formed by intersecting this interval with (-inf,n) or <code>null</code>
  *     if that intersection is empty
  */
 public ContinuousRealInterval less(Number n) {
   if (boundUpper() && OWLRealUtils.compare(n, getUpper()) > 0) return this;
   else if (boundLower() && OWLRealUtils.compare(n, getLower()) <= 0) return null;
   return new ContinuousRealInterval(getLower(), n, inclusiveLower(), false);
 }
コード例 #8
0
 /**
  * Get the subinterval greater than n
  *
  * @param n
  * @return a new interval, formed by intersecting this interval with (n,+inf) or <code>null</code>
  *     if that intersection is empty
  */
 public ContinuousRealInterval greater(Number n) {
   if (boundLower() && OWLRealUtils.compare(n, getLower()) < 0) return this;
   else if (boundUpper() && OWLRealUtils.compare(n, getUpper()) >= 0) return null;
   return new ContinuousRealInterval(n, getUpper(), false, inclusiveUpper());
 }