/** * Returns an instance of this class. * * @return An instance of this class. */ public static synchronized StandardUnitFormat instance() { if (_instance == null) _instance = new StandardUnitFormat(); return _instance; }
/** * Reinitialise. */ public void ReInit(java.io.InputStream stream) { ReInit(stream, null); }
final public Unit powerExpr(UnitDB unitDB) throws ParseException, OperationException, UnitSystemException, PrefixDBException, UnitDBException { Unit unit; int exponent; unit = basicExpr(unitDB); switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case PLUS: case MINUS: case UINT: case RAISE: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case RAISE: jj_consume_token(RAISE); break; default: jj_la1[7] = jj_gen; ; } exponent = integer(); unit = unit.raiseTo(exponent); break; default: jj_la1[8] = jj_gen; ; } { if (true) return unit; } throw new Error("Missing return statement in function"); }
final public Date timeOriginExpr() throws ParseException { Calendar calendar; calendar = dateExpr(); if (jj_2_6(2)) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case T: jj_consume_token(T); break; case SP: jj_consume_token(SP); break; default: jj_la1[23] = jj_gen; jj_consume_token(-1); throw new ParseException(); clockExpr(calendar); if (jj_2_5(2)) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case SP: jj_consume_token(SP); break; default: zoneExpr(calendar); } else {
final public Unit unitIdentifier(UnitDB unitDB) throws ParseException, UnitDBException, UnitSystemException, PrefixDBException, OperationException { Token token; Unit unit; switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case T: token = jj_consume_token(T); break; case NAME: token = jj_consume_token(NAME); break; case SYMBOL: token = jj_consume_token(SYMBOL); break; default: jj_la1[22] = jj_gen; jj_consume_token(-1); throw new ParseException(); double scale = 1; for (unit = getUnit(unitDB, string); unit == null; unit = getUnit(unitDB, string)) { Prefix prefix = getPrefix(string); if (prefix == null) { try {
throws Exception { StandardUnitFormat parser = StandardUnitFormat.instance(); final Unit m = parser.parse("m"); final Unit s = parser.parse("s"); final Unit epoch = parser.parse("s @ 1970-01-01 00:00:00 UTC"); myAssert(parser, "m m", m.multiplyBy(m)); myAssert(parser, "m.m", m.multiplyBy(m)); myAssert(parser, "(m)(m)", m.multiplyBy(m)); myAssert(parser, "m/s/s", m.divideBy(s).divideBy(s)); myAssert(parser, "m2", m.raiseTo(2)); myAssert(parser, "m2.s", m.raiseTo(2).multiplyBy(s)); myAssert(parser, "m2/s", m.raiseTo(2).divideBy(s)); myAssert(parser, "m^2/s", m.raiseTo(2).divideBy(s)); myAssert(parser, "m s @ 5", m.multiplyBy(s).shiftTo(5.0)); myAssert(parser, "m2 s @ 5", m.raiseTo(2).multiplyBy(s).shiftTo(5)); myAssert(parser, "m2 s-1 @ 5", m.raiseTo(2).multiplyBy(s.raiseTo(-1)) .shiftTo(5)); myAssert(parser, "m s from 5", m.multiplyBy(s).shiftTo(5)); myAssert(parser, "s@19700101", epoch); myAssert(parser, "s@19700101T000000", epoch); myAssert(parser, "s@19700101T000000.00", epoch); myAssert(parser, "s @ 1970-01-01T00:00:00.00", epoch); myAssert(parser, "s @ 1970-01-01 00:00:00.00", epoch); myAssert(parser, "s @ 1970-01-01 00:00:00.00 +0", epoch); myAssert(parser, "s @ 1970-01-01T00:00:00.00 -12", epoch .shiftTo(new Date(12 * 60 * 60 * 1000))); if (!parser.parse("days since 2009-06-14 04:00:00").equals( parser.parse("days since 2009-06-14 04:00:00 +00:00"))) {
private static void myAssert(StandardUnitFormat parser, final String spec, final Unit unit) throws NoSuchUnitException, UnitParseException, SpecificationException, UnitDBException, PrefixDBException, UnitSystemException { if (!parser.parse(spec).equals(unit)) { throw new AssertionError(spec + " != " + unit); } System.out.println(spec + " -> " + unit); }
/** * Formats a unit in the underlying system of units. * * @param unit The unit to be formatted. * @param buf The buffer to append to. * @return The appended-to buffer. * @throws UnitClassException The class of the unit is unknown. */ public StringBuffer longFormat(Unit unit, StringBuffer buf) throws UnitClassException { return format(unit, buf, false); }
private StringBuffer format(OffsetUnit unit, StringBuffer buf, boolean normalize) throws UnitClassException { double offset = unit.getOffset(); if (offset == 0.0) { format(unit.getUnit(), buf, normalize); } else { int start = buf.length(); format(unit.getUnit(), buf, normalize); return (isBlackSpace(buf, start) ? buf : buf.insert(start, '(').append(')')). append(" @ ").append(offset); } return buf; }
private Token jj_consume_token(int kind) throws ParseException { Token oldToken; if ((oldToken = token).next != null) token = token.next; else token = token.next = token_source.getNextToken(); jj_ntk = -1; if (token.kind == kind) { jj_gen++; if (++jj_gc > 100) { jj_gc = 0; for (int i = 0; i < jj_2_rtns.length; i++) { JJCalls c = jj_2_rtns[i]; while (c != null) { if (c.gen < jj_gen) c.first = null; c = c.next; } } } return token; } token = oldToken; jj_kind = kind; throw generateParseException(); }
final public Date timeOriginExpr() throws ParseException { Calendar calendar; calendar = dateExpr(); if (jj_2_6(2)) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case T: jj_consume_token(T); break; case SP: jj_consume_token(SP); break; default: jj_la1[23] = jj_gen; jj_consume_token(-1); throw new ParseException(); clockExpr(calendar); if (jj_2_5(2)) { switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case SP: jj_consume_token(SP); break; default: zoneExpr(calendar); } else {
final public Unit unitIdentifier(UnitDB unitDB) throws ParseException, UnitDBException, UnitSystemException, PrefixDBException, OperationException { Token token; Unit unit; switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case T: token = jj_consume_token(T); break; case NAME: token = jj_consume_token(NAME); break; case SYMBOL: token = jj_consume_token(SYMBOL); break; default: jj_la1[22] = jj_gen; jj_consume_token(-1); throw new ParseException(); double scale = 1; for (unit = getUnit(unitDB, string); unit == null; unit = getUnit(unitDB, string)) { Prefix prefix = getPrefix(string); if (prefix == null) { try {
throws Exception { StandardUnitFormat parser = StandardUnitFormat.instance(); final Unit m = parser.parse("m"); final Unit s = parser.parse("s"); final Unit epoch = parser.parse("s @ 1970-01-01 00:00:00 UTC"); myAssert(parser, "m m", m.multiplyBy(m)); myAssert(parser, "m.m", m.multiplyBy(m)); myAssert(parser, "(m)(m)", m.multiplyBy(m)); myAssert(parser, "m/s/s", m.divideBy(s).divideBy(s)); myAssert(parser, "m2", m.raiseTo(2)); myAssert(parser, "m2.s", m.raiseTo(2).multiplyBy(s)); myAssert(parser, "m2/s", m.raiseTo(2).divideBy(s)); myAssert(parser, "m^2/s", m.raiseTo(2).divideBy(s)); myAssert(parser, "m s @ 5", m.multiplyBy(s).shiftTo(5.0)); myAssert(parser, "m2 s @ 5", m.raiseTo(2).multiplyBy(s).shiftTo(5)); myAssert(parser, "m2 s-1 @ 5", m.raiseTo(2).multiplyBy(s.raiseTo(-1)) .shiftTo(5)); myAssert(parser, "m s from 5", m.multiplyBy(s).shiftTo(5)); myAssert(parser, "s@19700101", epoch); myAssert(parser, "s@19700101T000000", epoch); myAssert(parser, "s@19700101T000000.00", epoch); myAssert(parser, "s @ 1970-01-01T00:00:00.00", epoch); myAssert(parser, "s @ 1970-01-01 00:00:00.00", epoch); myAssert(parser, "s @ 1970-01-01 00:00:00.00 +0", epoch); myAssert(parser, "s @ 1970-01-01T00:00:00.00 -12", epoch .shiftTo(new Date(12 * 60 * 60 * 1000))); if (!parser.parse("days since 2009-06-14 04:00:00").equals( parser.parse("days since 2009-06-14 04:00:00 +00:00"))) {
private static void myAssert(StandardUnitFormat parser, final String spec, final Unit unit) throws NoSuchUnitException, UnitParseException, SpecificationException, UnitDBException, PrefixDBException, UnitSystemException { if (!parser.parse(spec).equals(unit)) { throw new AssertionError(spec + " != " + unit); } System.out.println(spec + " -> " + unit); }
/** * Formats a unit in the underlying system of units. * * @param unit The unit to be formatted. * @param buf The buffer to append to. * @return The appended-to buffer. * @throws UnitClassException The class of the unit is unknown. */ public StringBuffer longFormat(Unit unit, StringBuffer buf) throws UnitClassException { return format(unit, buf, false); }
private StringBuffer format(OffsetUnit unit, StringBuffer buf, boolean normalize) throws UnitClassException { double offset = unit.getOffset(); if (offset == 0.0) { format(unit.getUnit(), buf, normalize); } else { int start = buf.length(); format(unit.getUnit(), buf, normalize); return (isBlackSpace(buf, start) ? buf : buf.insert(start, '(').append(')')). append(" @ ").append(offset); } return buf; }
private Token jj_consume_token(int kind) throws ParseException { Token oldToken; if ((oldToken = token).next != null) token = token.next; else token = token.next = token_source.getNextToken(); jj_ntk = -1; if (token.kind == kind) { jj_gen++; if (++jj_gc > 100) { jj_gc = 0; for (int i = 0; i < jj_2_rtns.length; i++) { JJCalls c = jj_2_rtns[i]; while (c != null) { if (c.gen < jj_gen) c.first = null; c = c.next; } } } return token; } token = oldToken; jj_kind = kind; throw generateParseException(); }
final public Unit powerExpr(UnitDB unitDB) throws ParseException, OperationException, UnitSystemException, PrefixDBException, UnitDBException { Unit unit; int exponent; unit = basicExpr(unitDB); switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case PLUS: case MINUS: case UINT: case RAISE: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case RAISE: jj_consume_token(RAISE); break; default: jj_la1[7] = jj_gen; ; } exponent = integer(); unit = unit.raiseTo(exponent); break; default: jj_la1[8] = jj_gen; ; } { if (true) return unit; } throw new Error("Missing return statement in function"); }