public static ContinuousRealInterval interval(final Double l, final Double u, final boolean il, final boolean iu) { return new ContinuousRealInterval(l == null ? null : BigDecimal.valueOf(l), u == null ? null : BigDecimal.valueOf(u), il, iu); }
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(); } }
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(); } }
before = new ContinuousRealInterval(getLower(), other.getLower(), inclusiveLower(), !other.inclusiveLower()); after = new ContinuousRealInterval(other.getUpper(), getUpper(), !other.inclusiveUpper(), inclusiveUpper()); break; before = new ContinuousRealInterval(getLower(), getUpper(), inclusiveLower(), false); after = null; break; after = new ContinuousRealInterval(getLower(), getUpper(), false, inclusiveUpper()); break; case STARTED_BY: before = null; after = new ContinuousRealInterval(other.getUpper(), getUpper(), !other.inclusiveUpper(), inclusiveUpper()); break; before = new ContinuousRealInterval(getLower(), other.getLower(), inclusiveLower(), !other.inclusiveLower()); after = null; break;
before = new ContinuousRealInterval(getLower(), other.getLower(), inclusiveLower(), !other.inclusiveLower()); after = new ContinuousRealInterval(other.getUpper(), getUpper(), !other.inclusiveUpper(), inclusiveUpper()); break; before = new ContinuousRealInterval(getLower(), getUpper(), inclusiveLower(), false); after = null; break; after = new ContinuousRealInterval(getLower(), getUpper(), false, inclusiveUpper()); break; case STARTED_BY: before = null; after = new ContinuousRealInterval(other.getUpper(), getUpper(), !other.inclusiveUpper(), inclusiveUpper()); break; before = new ContinuousRealInterval(getLower(), other.getLower(), inclusiveLower(), !other.inclusiveLower()); after = null; break;
throw new IllegalStateException(); final ContinuousRealInterval continuousRestriction = new ContinuousRealInterval(lower, upper, inclusiveLower, inclusiveUpper); final IntegerInterval integerRestriction = asIntegerInterval(continuousRestriction);
throw new IllegalStateException(); final ContinuousRealInterval continuousRestriction = new ContinuousRealInterval(lower, upper, inclusiveLower, inclusiveUpper); final IntegerInterval integerRestriction = asIntegerInterval(continuousRestriction);
private static ContinuousRealInterval zoneShrink(final ContinuousRealInterval i) { final Number lower = i.boundLower() ? OWLRealUtils.sum(i.getLower(), TZ_SHIFT) : null; final Number upper = i.boundUpper() ? OWLRealUtils.sum(i.getUpper(), -TZ_SHIFT) : null; if (lower != null && upper != null) { final int cmp = OWLRealUtils.compare(lower, upper); if (cmp > 0) return null; else if (cmp == 0) if (!i.inclusiveLower() && !i.inclusiveUpper()) return null; else return new ContinuousRealInterval(lower); } return new ContinuousRealInterval(lower, upper, i.inclusiveLower(), i.inclusiveUpper()); }
private static ContinuousRealInterval zoneShrink(final ContinuousRealInterval i) { final Number lower = i.boundLower() ? OWLRealUtils.sum(i.getLower(), TZ_SHIFT) : null; final Number upper = i.boundUpper() ? OWLRealUtils.sum(i.getUpper(), -TZ_SHIFT) : null; if (lower != null && upper != null) { final int cmp = OWLRealUtils.compare(lower, upper); if (cmp > 0) return null; else if (cmp == 0) if (!i.inclusiveLower() && !i.inclusiveUpper()) return null; else return new ContinuousRealInterval(lower); } return new ContinuousRealInterval(lower, upper, i.inclusiveLower(), i.inclusiveUpper()); }
final ContinuousRealInterval restriction = new ContinuousRealInterval(lower, upper, inclusiveLower, inclusiveUpper); if (c.getTimezone() == DatatypeConstants.FIELD_UNDEFINED)
/** * 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(final 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()); }
/** * 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(final 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()); }
/** * 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); }
/** * 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); }
/** * 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); }
@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)))); }
@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 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)); }
return new ContinuousRealInterval(lower, upper, inclusiveLower, inclusiveUpper);
return new ContinuousRealInterval(lower, upper, inclusiveLower, inclusiveUpper);