@Override protected boolean valid(final Number n) { if (n == null) return true; return OWLRealUtils.acceptable(n.getClass()) && OWLRealUtils.isInteger(n); }
@Override protected boolean valid(final Number n) { if (n == null) return true; return OWLRealUtils.acceptable(n.getClass()) && OWLRealUtils.isInteger(n); }
public AbstractDerivedIntegerType(final ATermAppl name, final Number lower, final Number upper) { super(name); if (lower != null && !OWLRealUtils.isInteger(lower)) throw new IllegalArgumentException(); if (upper != null && !OWLRealUtils.isInteger(upper)) throw new IllegalArgumentException(); if (lower != null && upper != null && OWLRealUtils.compare(lower, upper) > 0) throw new IllegalArgumentException(); final IntegerInterval i = new IntegerInterval(lower == null ? null : OWLRealUtils.getCanonicalObject(lower), upper == null ? null : OWLRealUtils.getCanonicalObject(upper)); _dataRange = new RestrictedRealDatatype(this, i, null, null); }
public AbstractDerivedIntegerType(final ATermAppl name, final Number lower, final Number upper) { super(name); if (lower != null && !OWLRealUtils.isInteger(lower)) throw new IllegalArgumentException(); if (upper != null && !OWLRealUtils.isInteger(upper)) throw new IllegalArgumentException(); if (lower != null && upper != null && OWLRealUtils.compare(lower, upper) > 0) throw new IllegalArgumentException(); final IntegerInterval i = new IntegerInterval(lower == null ? null : OWLRealUtils.getCanonicalObject(lower), upper == null ? null : OWLRealUtils.getCanonicalObject(upper)); _dataRange = new RestrictedRealDatatype(this, i, null, null); }
public static Number sum(final Number a, final Number b) { if (isInteger(a) && isInteger(b)) return integerSum(a, b); final Type ta = Type.get(a.getClass()); final Type tb = Type.get(b.getClass()); if (ta == null || tb == null) { final String msg = format("Unexpected number type %s,%s passed to integerSum method.", a.getClass().getCanonicalName(), b.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } if (EnumSet.of(ta, tb).contains(Type.RATIONAL)) { final String msg = format("Addition for rational numbers is not supported"); _logger.warning(msg); throw new IllegalArgumentException(msg); } final BigDecimal da = (BigDecimal) convertFromTo(a, ta, Type.BIG_DECIMAL); final BigDecimal db = (BigDecimal) convertFromTo(b, tb, Type.BIG_DECIMAL); return getCanonicalObject(da.add(db)); }
public static Number sum(final Number a, final Number b) { if (isInteger(a) && isInteger(b)) return integerSum(a, b); final Type ta = Type.get(a.getClass()); final Type tb = Type.get(b.getClass()); if (ta == null || tb == null) { final String msg = format("Unexpected number type %s,%s passed to integerSum method.", a.getClass().getCanonicalName(), b.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } if (EnumSet.of(ta, tb).contains(Type.RATIONAL)) { final String msg = format("Addition for rational numbers is not supported"); _logger.warning(msg); throw new IllegalArgumentException(msg); } final BigDecimal da = (BigDecimal) convertFromTo(a, ta, Type.BIG_DECIMAL); final BigDecimal db = (BigDecimal) convertFromTo(b, tb, Type.BIG_DECIMAL); return getCanonicalObject(da.add(db)); }
if (!intOk && OWLRealUtils.isInteger(next)) next = null; if (!decOk && OWLRealUtils.isDecimal(next))
if (!intOk && OWLRealUtils.isInteger(next)) next = null; if (!decOk && OWLRealUtils.isDecimal(next))
@Test public void isDecimalValueInteger() { assertTrue(isInteger(new BigDecimal("0"))); assertTrue(isInteger(new BigDecimal("1"))); assertTrue(isInteger(new BigDecimal("10"))); assertTrue(isInteger(new BigDecimal("11"))); assertTrue(isInteger(new BigDecimal("0.0"))); assertTrue(isInteger(new BigDecimal("1.0"))); assertTrue(isInteger(new BigDecimal("1.00"))); assertTrue(isInteger(new BigDecimal("10.0"))); assertTrue(isInteger(new BigDecimal("11.0"))); assertFalse(isInteger(new BigDecimal("10.01"))); } }
if (isInteger(n)) return shrinkBigInteger(bigInteger(n)); else
@Deprecated @Override public int size() { if (!_finite) throw new IllegalStateException(); Number sum = 0; for (final IntegerInterval i : _intIntervals) { sum = OWLRealUtils.integerSum(sum, i.size()); if (OWLRealUtils.compare(Integer.MAX_VALUE, sum) <= 0) return Integer.MAX_VALUE; } for (final ContinuousRealInterval i : _decimalIntervals) if (!OWLRealUtils.isInteger(i.getLower())) { sum = OWLRealUtils.integerIncrement(sum); if (OWLRealUtils.compare(Integer.MAX_VALUE, sum) <= 0) return Integer.MAX_VALUE; } for (final ContinuousRealInterval i : _rationalIntervals) if (!OWLRealUtils.isInteger(i.getLower()) && !OWLRealUtils.isRational(i.getLower())) { sum = OWLRealUtils.integerIncrement(sum); if (OWLRealUtils.compare(Integer.MAX_VALUE, sum) <= 0) return Integer.MAX_VALUE; } return sum.intValue(); }
@Deprecated @Override public int size() { if (!_finite) throw new IllegalStateException(); Number sum = 0; for (final IntegerInterval i : _intIntervals) { sum = OWLRealUtils.integerSum(sum, i.size()); if (OWLRealUtils.compare(Integer.MAX_VALUE, sum) <= 0) return Integer.MAX_VALUE; } for (final ContinuousRealInterval i : _decimalIntervals) if (!OWLRealUtils.isInteger(i.getLower())) { sum = OWLRealUtils.integerIncrement(sum); if (OWLRealUtils.compare(Integer.MAX_VALUE, sum) <= 0) return Integer.MAX_VALUE; } for (final ContinuousRealInterval i : _rationalIntervals) if (!OWLRealUtils.isInteger(i.getLower()) && !OWLRealUtils.isRational(i.getLower())) { sum = OWLRealUtils.integerIncrement(sum); if (OWLRealUtils.compare(Integer.MAX_VALUE, sum) <= 0) return Integer.MAX_VALUE; } return sum.intValue(); }
if (OWLRealUtils.isInteger(n))
if (OWLRealUtils.isInteger(n))
public boolean contains(final Number n) { if (_type.equals(LineType.INTEGER_ONLY)) { if (!isInteger(n)) return false; } else if (_type.equals(LineType.INTEGER_EXCLUDED)) if (isInteger(n)) return false; 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; }
public boolean contains(final Number n) { if (_type.equals(LineType.INTEGER_ONLY)) { if (!isInteger(n)) return false; } else if (_type.equals(LineType.INTEGER_EXCLUDED)) if (isInteger(n)) return false; 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; }
@Override public boolean containsAtLeast(final int n) { if (!_finite || n <= 0) return true; Number sum = 0; for (final IntegerInterval i : _intIntervals) { sum = OWLRealUtils.integerSum(sum, i.size()); if (OWLRealUtils.compare(n, sum) <= 0) return true; } for (final ContinuousRealInterval i : _decimalIntervals) if (!OWLRealUtils.isInteger(i.getLower())) { sum = OWLRealUtils.integerIncrement(sum); if (OWLRealUtils.compare(n, sum) <= 0) return true; } for (final ContinuousRealInterval i : _rationalIntervals) if (!OWLRealUtils.isInteger(i.getLower()) && !OWLRealUtils.isRational(i.getLower())) { sum = OWLRealUtils.integerIncrement(sum); if (OWLRealUtils.compare(n, sum) <= 0) return true; } return false; }
@Override public boolean containsAtLeast(final int n) { if (!_finite || n <= 0) return true; Number sum = 0; for (final IntegerInterval i : _intIntervals) { sum = OWLRealUtils.integerSum(sum, i.size()); if (OWLRealUtils.compare(n, sum) <= 0) return true; } for (final ContinuousRealInterval i : _decimalIntervals) if (!OWLRealUtils.isInteger(i.getLower())) { sum = OWLRealUtils.integerIncrement(sum); if (OWLRealUtils.compare(n, sum) <= 0) return true; } for (final ContinuousRealInterval i : _rationalIntervals) if (!OWLRealUtils.isInteger(i.getLower()) && !OWLRealUtils.isRational(i.getLower())) { sum = OWLRealUtils.integerIncrement(sum); if (OWLRealUtils.compare(n, sum) <= 0) return true; } return false; }