final LineType t1 = getType(); final LineType t2 = other.getType(); switch (compare(other)) before = new OWLRealInterval(getLower(), other.getLower(), inclusiveLower(), !other.inclusiveLower(), t1); if (LineType.CONTINUOUS.equals(t2)) during = other; else during = new OWLRealInterval(other.getLower(), other.getUpper(), other.inclusiveLower(), other.inclusiveUpper(), LineType.CONTINUOUS); after = new OWLRealInterval(other.getUpper(), getUpper(), !other.inclusiveUpper(), inclusiveUpper(), t1); break; before = new OWLRealInterval(other.getLower(), getLower(), other.inclusiveLower(), !inclusiveLower(), t2); if (LineType.CONTINUOUS.equals(t1)) during = this; else during = new OWLRealInterval(getLower(), getUpper(), inclusiveLower(), inclusiveUpper(), LineType.CONTINUOUS); after = new OWLRealInterval(getUpper(), other.getUpper(), !inclusiveUpper(), other.inclusiveUpper(), t2); break; during = new OWLRealInterval(getLower(), getUpper(), inclusiveLower(), inclusiveUpper(), LineType.CONTINUOUS); after = null; break; before = new OWLRealInterval(getLower(), other.getLower(), inclusiveLower(), !other.inclusiveLower(), t1); if (LineType.CONTINUOUS.equals(t2)) during = other; else
@Override public String toString() { return format("%s%s,%s%s%s", inclusiveLower() ? "[" : "(", boundLower() ? getLower() : "-Inf", boundUpper() ? getUpper() : "+Inf", inclusiveUpper() ? "]" : ")", _type.equals(LineType.CONTINUOUS) ? "" : _type.equals(LineType.INTEGER_ONLY) ? "{int}" : "{noint}"); }
private static int compareUpperLower(final OWLRealInterval a, final OWLRealInterval b) { int ul; if (!a.boundUpper()) ul = 1; else if (!b.boundLower()) ul = 1; else ul = OWLRealUtils.compare(a.getUpper(), b.getLower()); return ul; }
/** * 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 OWLRealInterval less(final Number n) { if (boundUpper() && OWLRealUtils.compare(n, getUpper()) > 0) return this; else if (boundLower() && OWLRealUtils.compare(n, getLower()) <= 0) return null; return new OWLRealInterval(getLower(), n, inclusiveLower(), false, getType()); }
/** * 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 OWLRealInterval greater(final Number n) { if (boundLower() && OWLRealUtils.compare(n, getLower()) < 0) return this; else if (boundUpper() && OWLRealUtils.compare(n, getUpper()) >= 0) return null; return new OWLRealInterval(n, getUpper(), false, inclusiveUpper(), getType()); }
/** * Verify that two continuous intervals overlapping just on an inclusive bound intersect to a point. */ @Test public void intersectionPointCon() { final OWLRealInterval a = interval(null, 2.1, false, true, LineType.CONTINUOUS); final OWLRealInterval b = interval(2.1, null, true, false, LineType.CONTINUOUS); final OWLRealInterval expected = new OWLRealInterval(BigDecimal.valueOf(2.1d)); assertEquals(expected, a.intersection(b)); assertEquals(expected, b.intersection(a)); assertTrue(a.intersection(b).isPoint()); assertTrue(b.intersection(a).isPoint()); assertTrue(a.intersection(b).contains(BigDecimal.valueOf(2.1d))); assertTrue(b.intersection(a).contains(BigDecimal.valueOf(2.1d))); assertEquals(IntervalRelations.OVERLAPS, a.compare(b)); assertEquals(IntervalRelations.OVERLAPPED_BY, b.compare(a)); }
public Iterator<Number> valueIterator() if (isPoint()) return Collections.singletonList(getUpper()).iterator(); else if (LineType.INTEGER_ONLY.equals(getType())) if (boundLower()) start = getLower(); increment = true; finish = boundUpper() ? getUpper() : null; if (boundUpper()) start = getUpper(); increment = false; finish = null;
@Test public void unboundContainsAll() { final OWLRealInterval interval = new OWLRealInterval(null, null, false, false, LineType.CONTINUOUS); assertFalse(interval.boundLower()); assertFalse(interval.boundUpper()); assertFalse(interval.isPoint()); assertTrue(interval.contains(-1)); assertTrue(interval.contains(0)); assertTrue(interval.contains(1)); assertTrue(interval.contains(BigDecimal.valueOf(-0.31d))); assertTrue(interval.contains(BigDecimal.valueOf(0.13d))); assertTrue(interval.contains(BigDecimal.valueOf(Long.MAX_VALUE).add(BigDecimal.valueOf(Long.MAX_VALUE)).add(BigDecimal.valueOf(0.123d)))); }
/** * Verify that the intersection of a continuous interval with a continuous interval which it starts and which share an inclusive endpoint is correct. */ @Test public void intersectionStartsConCon1() { final OWLRealInterval a = interval(2.1, 3.1, true, true, LineType.CONTINUOUS); final OWLRealInterval b = interval(2.1, null, true, false, LineType.CONTINUOUS); assertEquals(a, a.intersection(b)); assertEquals(a, b.intersection(a)); assertEquals(IntervalRelations.STARTS, a.compare(b)); assertEquals(IntervalRelations.STARTED_BY, b.compare(a)); }
public RestrictedRealDatatype(final Datatype<? extends Number> datatype, final OWLRealInterval interval) { _datatype = datatype; _empty = new EmptyRestrictedDatatype<>(datatype); _intervals = Collections.singletonList(interval); _finite = interval.isFinite(); _enumerable = interval.isPoint() || interval.getType().equals(OWLRealInterval.LineType.INTEGER_ONLY); }
/** * Verify that the overlap of two continuous intervals with exclusive bounds intersect correctly. */ @Test public void intersectionOverlapConCon1() { final OWLRealInterval a = interval(null, 0.51, false, false, LineType.CONTINUOUS); final OWLRealInterval b = interval(0.49, null, false, false, LineType.CONTINUOUS); final OWLRealInterval expected = interval(0.49, 0.51, false, false, LineType.CONTINUOUS); assertEquals(expected, a.intersection(b)); assertEquals(expected, b.intersection(a)); assertTrue(a.intersection(b).contains(BigDecimal.valueOf(0.50))); assertTrue(b.intersection(a).contains(BigDecimal.valueOf(0.50))); assertFalse(a.intersection(b).contains(BigDecimal.valueOf(0.49))); assertFalse(b.intersection(a).contains(BigDecimal.valueOf(0.49))); assertFalse(a.intersection(b).contains(BigDecimal.valueOf(0.51))); assertFalse(b.intersection(a).contains(BigDecimal.valueOf(0.51))); assertEquals(IntervalRelations.OVERLAPS, a.compare(b)); assertEquals(IntervalRelations.OVERLAPPED_BY, b.compare(a)); }
private static int compareLowerLower(final OWLRealInterval a, final OWLRealInterval 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; }
private static int compareUpperUpper(final OWLRealInterval a, final OWLRealInterval 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; }
if (negated) intersectWith = new ArrayList<>(Arrays.asList(OWLRealInterval.allReals())); for (final OWLRealInterval i : otherRRD._intervals) tmp.addAll(j.remove(i)); intersectWith = tmp; for (final OWLRealInterval j : intersectWith) final OWLRealInterval k = i.intersection(j); if (k != null) revisedIntervals.add(k);
@Override public boolean contains(final Object value) { if (value instanceof Number) { final Number n = (Number) value; if (OWLRealUtils.acceptable(n.getClass())) { /* * TODO: This could be made more efficient by looking at how * each contained check fails (e.g., if _intervals is sorted by * boundaries and n is not contained, but less than upper, there * is no need to look further). */ for (final OWLRealInterval i : _intervals) if (i.contains(n)) return true; return false; } else return false; } else return false; }
throw new IllegalStateException(); final OWLRealInterval restriction = new OWLRealInterval(lower, upper, inclusiveLower, inclusiveUpper, OWLRealInterval.LineType.CONTINUOUS); final OWLRealInterval j = i.intersection(restriction); if (j != null)
/** * Verify that a continuous interval with equal bounds is a point. */ @Test public void isPointTrueCon() { final OWLRealInterval a = new OWLRealInterval(BigDecimal.valueOf(0.1d)); assertTrue(a.isPoint()); final OWLRealInterval b = interval(0.1, 0.1, true, true, LineType.CONTINUOUS); assertTrue(b.isPoint()); assertEquals(a, b); }
public static OWLRealInterval interval(final Integer l, final Integer u, final boolean il, final boolean iu, final OWLRealInterval.LineType t) { return new OWLRealInterval(l, u, il, iu, t); }