/** * 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(final 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); }
public RestrictedTimelineDatatype(final Datatype<? extends XMLGregorianCalendar> datatype, final QName schemaType, final boolean requireTz) { _datatype = datatype; _schemaType = schemaType; _empty = new EmptyRestrictedDatatype<>(datatype); _wzIntervals = Collections.singletonList(ContinuousRealInterval.allReals()); _nzIntervals = requireTz ? Collections.<ContinuousRealInterval> emptyList() : Collections.singletonList(ContinuousRealInterval.allReals()); _finite = false; _enumerable = false; }
public List<ContinuousRealInterval> union(final ContinuousRealInterval other) { switch (compare(other)) { case CONTAINS: case EQUALS: case FINISHED_BY: case STARTED_BY: return Collections.singletonList(this); case DURING: case FINISHES: case STARTS: return Collections.singletonList(other); case MEETS: return Collections.singletonList(new ContinuousRealInterval(getLower(), other.getUpper(), inclusiveLower(), other.inclusiveUpper())); case MET_BY: return Collections.singletonList(new ContinuousRealInterval(other.getLower(), getUpper(), other.inclusiveLower(), inclusiveUpper())); case OVERLAPPED_BY: return Collections.singletonList(new ContinuousRealInterval(other.getLower(), getUpper(), other.inclusiveLower(), inclusiveUpper())); case OVERLAPS: return Collections.singletonList(new ContinuousRealInterval(getLower(), other.getUpper(), inclusiveLower(), other.inclusiveUpper())); case PRECEDED_BY: case PRECEDES: return Arrays.asList(this, other); default: throw new IllegalStateException(); } }
@Override public String toString() { return format("%s%s,%s%s", inclusiveLower() ? "[" : "(", boundLower() ? getLower() : "-Inf", boundUpper() ? getUpper() : "+Inf", inclusiveUpper() ? "]" : ")"); }
private static int compareUpperLower(final ContinuousRealInterval a, final 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; }
@Test public void unboundContainsAll() { final ContinuousRealInterval interval = new ContinuousRealInterval(null, null, false, false); 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 two intervals overlapping just on an inclusive bound intersect to a point. */ @Test public void intersectionPoint() { final ContinuousRealInterval a = interval(null, 2.1, false, true); final ContinuousRealInterval b = interval(2.1, null, true, false); final ContinuousRealInterval expected = new ContinuousRealInterval(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)); }
if (negated) intersectWithWz = new ArrayList<>(Arrays.asList(ContinuousRealInterval.allReals())); for (final ContinuousRealInterval i : otherRRD._wzIntervals) tmp.addAll(j.remove(i)); intersectWithWz = tmp; for (final ContinuousRealInterval j : intersectWithWz) final ContinuousRealInterval k = i.intersection(j); if (k != null) revisedWz.add(k); if (negated) intersectWithNz = new ArrayList<>(Arrays.asList(ContinuousRealInterval.allReals())); for (final ContinuousRealInterval i : otherRRD._nzIntervals) tmp.addAll(j.remove(i)); intersectWithNz = tmp; for (final ContinuousRealInterval j : intersectWithNz) final ContinuousRealInterval k = i.intersection(j); if (k != null) revisedNz.add(k);
/** * Verify that if no overlap exists between the bounds an empty intersection is identified */ @Test public void intersectionEmpty() { final ContinuousRealInterval a = interval(null, 0d, false, true); final ContinuousRealInterval b = interval(1d, null, true, false); assertNull(a.intersection(b)); assertNull(b.intersection(a)); assertEquals(IntervalRelations.PRECEDES, a.compare(b)); assertEquals(IntervalRelations.PRECEDED_BY, b.compare(a)); }
/** * Verify that the overlap of two intervals with inclusive bounds intersect correctly. */ @Test public void intersectionOverlap2() { final ContinuousRealInterval a = interval(null, 0.51, false, true); final ContinuousRealInterval b = interval(0.49, null, true, false); final ContinuousRealInterval expected = interval(0.49, 0.51, true, true); 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))); assertTrue(a.intersection(b).contains(BigDecimal.valueOf(0.49))); assertTrue(b.intersection(a).contains(BigDecimal.valueOf(0.49))); assertTrue(a.intersection(b).contains(BigDecimal.valueOf(0.51))); assertTrue(b.intersection(a).contains(BigDecimal.valueOf(0.51))); assertEquals(IntervalRelations.OVERLAPS, a.compare(b)); assertEquals(IntervalRelations.OVERLAPPED_BY, b.compare(a)); }
throw new IllegalStateException(); final ContinuousRealInterval continuousRestriction = new ContinuousRealInterval(lower, upper, inclusiveLower, inclusiveUpper); final IntegerInterval integerRestriction = asIntegerInterval(continuousRestriction); for (final ContinuousRealInterval i : _decimalIntervals) final ContinuousRealInterval j = i.intersection(continuousRestriction); if (j != null) if (!i.equals(j)) changes = true; for (final ContinuousRealInterval i : _rationalIntervals) final ContinuousRealInterval j = i.intersection(continuousRestriction); if (j != null) if (!i.equals(j)) changes = true;
private static int compareLowerLower(final ContinuousRealInterval a, final 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; }
private static int compareUpperUpper(final ContinuousRealInterval a, final 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; }
final ContinuousRealInterval restriction = new ContinuousRealInterval(lower, upper, inclusiveLower, inclusiveUpper); if (c.getTimezone() == DatatypeConstants.FIELD_UNDEFINED) for (final ContinuousRealInterval i : _wzIntervals) final ContinuousRealInterval j = i.intersection(wzRestriction); if (j != null) for (final ContinuousRealInterval i : _nzIntervals) final ContinuousRealInterval j = i.intersection(nzRestriction); if (j != null)
if (i.canUnionWith(j)) tmp.addAll(i.union(j)); revisedWz.addAll(tmp); if (i.canUnionWith(j)) tmp.addAll(i.union(j)); revisedNz.addAll(tmp);
public RestrictedRealDatatype(final Datatype<? extends Number> datatype, final IntegerInterval ints, final ContinuousRealInterval decimals, final ContinuousRealInterval rationals) { _datatype = datatype; _empty = new EmptyRestrictedDatatype<>(datatype); _intIntervals = ints == null ? Collections.<IntegerInterval> emptyList() : Collections.singletonList(ints); _decimalIntervals = decimals == null ? Collections.<ContinuousRealInterval> emptyList() : Collections.singletonList(decimals); _rationalIntervals = rationals == null ? Collections.<ContinuousRealInterval> emptyList() : Collections.singletonList(rationals); _finite = (ints == null ? true : ints.isFinite()) && (decimals == null ? true : decimals.isPoint()) && (rationals == null ? true : rationals.isPoint()); _enumerable = _finite || decimals == null && rationals == null; }
@Test public void unboundEquals() { final ContinuousRealInterval lowerUnbound = new ContinuousRealInterval(null, 1000, false, false); final ContinuousRealInterval upperUnbound = new ContinuousRealInterval(100, null, false, false); final ContinuousRealInterval allBound = new ContinuousRealInterval(100, 1000, false, false); assertFalse(lowerUnbound.equals(upperUnbound)); assertFalse(lowerUnbound.equals(allBound)); assertTrue(lowerUnbound.equals(lowerUnbound)); assertTrue(upperUnbound.equals(upperUnbound)); assertFalse(upperUnbound.equals(allBound)); assertFalse(upperUnbound.equals(lowerUnbound)); assertFalse(allBound.equals(upperUnbound)); assertTrue(allBound.equals(allBound)); assertFalse(allBound.equals(lowerUnbound)); } }
/** * Verify that a interval with equal bounds is a point. */ @Test public void isPointTrue() { final ContinuousRealInterval a = new ContinuousRealInterval(BigDecimal.valueOf(0.1d)); assertTrue(a.isPoint()); final ContinuousRealInterval b = interval(0.1, 0.1, true, true); assertTrue(b.isPoint()); assertEquals(a, b); }