public static Rational valueOf(final String s) throws NumberFormatException { if (s == null) throw new NullPointerException(); final Matcher m = _lexicalPattern.matcher(s); if (!m.matches()) throw new NumberFormatException(s); final String sLex = m.group(1); final String nLex = m.group(2); final String dLex = m.group(3); final Number n = OWLRealUtils.getCanonicalObject(DatatypeConverter.parseInteger(sLex == null ? nLex : sLex + nLex)); final Number d = OWLRealUtils.getCanonicalObject(DatatypeConverter.parseInteger(dLex)); if (OWLRealUtils.signum(d) != 1) throw new NumberFormatException(s); return new Rational(n, d); }
public static Rational valueOf(final String s) throws NumberFormatException { if (s == null) throw new NullPointerException(); final Matcher m = _lexicalPattern.matcher(s); if (!m.matches()) throw new NumberFormatException(s); final String sLex = m.group(1); final String nLex = m.group(2); final String dLex = m.group(3); final Number n = OWLRealUtils.getCanonicalObject(DatatypeConverter.parseInteger(sLex == null ? nLex : sLex + nLex)); final Number d = OWLRealUtils.getCanonicalObject(DatatypeConverter.parseInteger(dLex)); if (OWLRealUtils.signum(d) != 1) throw new NumberFormatException(s); return new Rational(n, d); }
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); }
@Override public Number getValue(final ATermAppl literal) throws InvalidLiteralException { final String lexicalForm = getLexicalForm(literal); return OWLRealUtils.getCanonicalObject(fromLexicalForm(lexicalForm)); }
@Override public Number getValue(final ATermAppl literal) throws InvalidLiteralException { final String lexicalForm = getLexicalForm(literal); return OWLRealUtils.getCanonicalObject(fromLexicalForm(lexicalForm)); }
@Test public void canonicalBigDecimal() { assertEquals(Byte.valueOf((byte) 1), getCanonicalObject(BigDecimal.valueOf(10, 1))); assertEquals(Byte.valueOf((byte) 1), getCanonicalObject(BigDecimal.valueOf(1, 0))); assertEquals(Byte.valueOf((byte) 0), getCanonicalObject(BigDecimal.valueOf(0, 0))); assertEquals(Byte.valueOf((byte) 0), getCanonicalObject(BigDecimal.valueOf(0, 1))); }
@Override public Number getValue(final ATermAppl literal) throws InvalidLiteralException { final String lexicalForm = getLexicalForm(literal); try { return OWLRealUtils.getCanonicalObject(DatatypeConverter.parseDecimal(lexicalForm)); } catch (final NumberFormatException e) { throw new InvalidLiteralException(getName(), lexicalForm, e); } }
@Override public Number getValue(final ATermAppl literal) throws InvalidLiteralException { final String lexicalForm = getLexicalForm(literal); try { return OWLRealUtils.getCanonicalObject(Rational.valueOf(lexicalForm)); } catch (final NumberFormatException e) { throw new InvalidLiteralException(getName(), lexicalForm, e); } }
@Override public Number getValue(final ATermAppl literal) throws InvalidLiteralException { if (!ATermUtils.isLiteral(literal)) throw new IllegalArgumentException(); if (!literal.getArgument(ATermUtils.LIT_URI_INDEX).equals(name)) throw new IllegalArgumentException(); final String lexicalForm = ATermUtils.getLiteralValue(literal); try { return OWLRealUtils.getCanonicalObject(DatatypeConverter.parseLong(lexicalForm)); } catch (final NumberFormatException e) { throw new InvalidLiteralException(name, lexicalForm, e); } }
@Override public Number getValue(final ATermAppl literal) throws InvalidLiteralException { if (!ATermUtils.isLiteral(literal)) throw new IllegalArgumentException(); if (!literal.getArgument(ATermUtils.LIT_URI_INDEX).equals(name)) throw new IllegalArgumentException(); final String lexicalForm = ATermUtils.getLiteralValue(literal); try { return OWLRealUtils.getCanonicalObject(DatatypeConverter.parseDecimal(lexicalForm)); } catch (final NumberFormatException e) { throw new InvalidLiteralException(name, lexicalForm, e); } }
@Override public Number getValue(final ATermAppl literal) throws InvalidLiteralException { if (!ATermUtils.isLiteral(literal)) throw new IllegalArgumentException(); if (!literal.getArgument(ATermUtils.LIT_URI_INDEX).equals(name)) throw new IllegalArgumentException(); final String lexicalForm = ATermUtils.getLiteralValue(literal); try { return OWLRealUtils.getCanonicalObject(DatatypeConverter.parseLong(lexicalForm)); } catch (final NumberFormatException e) { throw new InvalidLiteralException(name, lexicalForm, e); } }
@Override public Number getValue(final ATermAppl literal) throws InvalidLiteralException { final String lexicalForm = getLexicalForm(literal); try { return OWLRealUtils.getCanonicalObject(DatatypeConverter.parseDecimal(lexicalForm)); } catch (final NumberFormatException e) { throw new InvalidLiteralException(getName(), lexicalForm, e); } }
@Override public Number getValue(final ATermAppl literal) throws InvalidLiteralException { final String lexicalForm = getLexicalForm(literal); try { return OWLRealUtils.getCanonicalObject(Rational.valueOf(lexicalForm)); } catch (final NumberFormatException e) { throw new InvalidLiteralException(getName(), lexicalForm, e); } }
@Override public Number getValue(final ATermAppl literal) throws InvalidLiteralException { if (!ATermUtils.isLiteral(literal)) throw new IllegalArgumentException(); if (!literal.getArgument(ATermUtils.LIT_URI_INDEX).equals(name)) throw new IllegalArgumentException(); final String lexicalForm = ATermUtils.getLiteralValue(literal); try { return OWLRealUtils.getCanonicalObject(DatatypeConverter.parseInteger(lexicalForm)); } catch (final NumberFormatException e) { throw new InvalidLiteralException(name, lexicalForm, e); } }
@Override public Number getValue(final ATermAppl literal) throws InvalidLiteralException { if (!ATermUtils.isLiteral(literal)) throw new IllegalArgumentException(); if (!literal.getArgument(ATermUtils.LIT_URI_INDEX).equals(name)) throw new IllegalArgumentException(); final String lexicalForm = ATermUtils.getLiteralValue(literal); try { return OWLRealUtils.getCanonicalObject(DatatypeConverter.parseDecimal(lexicalForm)); } catch (final NumberFormatException e) { throw new InvalidLiteralException(name, lexicalForm, e); } }
@Override public Number getValue(final ATermAppl literal) throws InvalidLiteralException { if (!ATermUtils.isLiteral(literal)) throw new IllegalArgumentException(); if (!literal.getArgument(ATermUtils.LIT_URI_INDEX).equals(name)) throw new IllegalArgumentException(); final String lexicalForm = ATermUtils.getLiteralValue(literal); try { return OWLRealUtils.getCanonicalObject(DatatypeConverter.parseInteger(lexicalForm)); } catch (final NumberFormatException e) { throw new InvalidLiteralException(name, lexicalForm, e); } }
@Override public ATermAppl getCanonicalRepresentation(final ATermAppl input) throws InvalidLiteralException { final Number n = getValue(input); if (n instanceof Rational) { final String canonicalForm = Rational.simplify((Rational) n).toString(); if (canonicalForm.equals(ATermUtils.getLiteralValue(input))) return input; else return ATermUtils.makeTypedLiteral(canonicalForm, getName()); } else return OWLReal.getInstance().getLiteral(OWLRealUtils.getCanonicalObject(n)); }
@Override public ATermAppl getCanonicalRepresentation(final ATermAppl input) throws InvalidLiteralException { final Number n = getValue(input); if (n instanceof Rational) { final String canonicalForm = Rational.simplify((Rational) n).toString(); if (canonicalForm.equals(ATermUtils.getLiteralValue(input))) return input; else return ATermUtils.makeTypedLiteral(canonicalForm, getName()); } else return OWLReal.getInstance().getLiteral(OWLRealUtils.getCanonicalObject(n)); }
/** * Test parsing of valid values */ @Test public void validParse() { Rational r; r = Rational.valueOf("1 / 3"); assertNotNull(r); assertEquals(new Rational(OWLRealUtils.getCanonicalObject(1), OWLRealUtils.getCanonicalObject(3)), r); r = Rational.valueOf("12 / 36"); assertNotNull(r); assertEquals(new Rational(OWLRealUtils.getCanonicalObject(12), OWLRealUtils.getCanonicalObject(36)), r); r = Rational.valueOf("-1 / 3"); assertNotNull(r); assertEquals(new Rational(OWLRealUtils.getCanonicalObject(-1), OWLRealUtils.getCanonicalObject(3)), r); } }