@Override public ATermAppl getLiteral(final Object value) { if (value instanceof Rational) { final Rational r = (Rational) value; final String lexicalForm = r.toString(); return ATermUtils.makeTypedLiteral(lexicalForm, getName()); } else throw new IllegalArgumentException(); }
@Override public ATermAppl getLiteral(final Object value) { if (value instanceof Rational) { final Rational r = (Rational) value; final String lexicalForm = r.toString(); return ATermUtils.makeTypedLiteral(lexicalForm, getName()); } else throw new IllegalArgumentException(); }
public static String print(final Number n) { final Type t = Type.get(n.getClass()); if (t == null) { final String msg = format("Unexpected number type %s passed to print method.", n.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } switch (t) { case BYTE: return DatatypeConverter.printByte(n.byteValue()); case SHORT: return DatatypeConverter.printShort(n.shortValue()); case INTEGER: return DatatypeConverter.printInt(n.intValue()); case LONG: return DatatypeConverter.printLong(n.longValue()); case BIG_INTEGER: return DatatypeConverter.printInteger((BigInteger) n); case BIG_DECIMAL: return DatatypeConverter.printDecimal((BigDecimal) n); case RATIONAL: return ((Rational) n).toString(); default: throw new IllegalStateException(); } }
public static String print(final Number n) { final Type t = Type.get(n.getClass()); if (t == null) { final String msg = format("Unexpected number type %s passed to print method.", n.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } switch (t) { case BYTE: return DatatypeConverter.printByte(n.byteValue()); case SHORT: return DatatypeConverter.printShort(n.shortValue()); case INTEGER: return DatatypeConverter.printInt(n.intValue()); case LONG: return DatatypeConverter.printLong(n.longValue()); case BIG_INTEGER: return DatatypeConverter.printInteger((BigInteger) n); case BIG_DECIMAL: return DatatypeConverter.printDecimal((BigDecimal) n); case RATIONAL: return ((Rational) n).toString(); default: throw new IllegalStateException(); } }
/** * Test that toString matches the canonical lexical form */ @Test public void lexicalForm() { assertEquals("1 / 3", rational("1/3").toString()); assertEquals("10 / 5", rational("10/5").toString()); assertEquals("-1 / 3", rational("-1/3").toString()); assertEquals("-10 / 5", rational("-10/5").toString()); }
@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)); }