use of javax.measure.Unit in project uom-se by unitsofmeasurement.
the class SymbolMapTest method parseWithEBNFUnitFormat.
/**
* Test if parsing 'dag' equals DEKA(GRAM)
*/
@Test
public void parseWithEBNFUnitFormat() {
Unit u2 = EBNFUnitFormat.getInstance().parse("dag");
assertEquals(MetricPrefix.DEKA(Units.GRAM), u2);
}
use of javax.measure.Unit in project uom-se by unitsofmeasurement.
the class UnitsTest method testByClassTime.
@Test
public void testByClassTime() {
Unit result = Units.getInstance().getUnit(Time.class);
assertNotNull(result);
assertEquals("s", result.toString());
}
use of javax.measure.Unit in project indriya by unitsofmeasurement.
the class NumberSpaceQuantityFormat method parse.
@Override
public ComparableQuantity<?> parse(CharSequence csq, ParsePosition cursor) throws IllegalArgumentException, MeasurementParseException {
String str = csq.toString();
Number number = numberFormat.parse(str, cursor);
if (number == null)
throw new IllegalArgumentException("Number cannot be parsed");
Unit unit = unitFormat.parse(csq);
return Quantities.getQuantity(number.longValue(), unit);
}
use of javax.measure.Unit in project indriya by unitsofmeasurement.
the class SimpleQuantityFormat method parse.
@SuppressWarnings("unchecked")
@Override
AbstractQuantity<?> parse(CharSequence csq, int index) throws MeasurementParseException {
// cursor.getIndex();
int startDecimal = index;
while ((startDecimal < csq.length()) && Character.isWhitespace(csq.charAt(startDecimal))) {
startDecimal++;
}
int endDecimal = startDecimal + 1;
while ((endDecimal < csq.length()) && !Character.isWhitespace(csq.charAt(endDecimal))) {
endDecimal++;
}
Double decimal = new Double(csq.subSequence(startDecimal, endDecimal).toString());
Unit unit = SimpleUnitFormat.getInstance().parse(csq, index);
return NumberQuantity.of(decimal, unit);
}
use of javax.measure.Unit in project indriya by unitsofmeasurement.
the class LocalUnitFormatParser method MulExpr.
public final Unit MulExpr() throws TokenException {
Unit result = AbstractUnit.ONE;
Unit temp = AbstractUnit.ONE;
result = ExponentExpr();
label_2: while (true) {
switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
case ASTERISK:
case MIDDLE_DOT:
case SOLIDUS:
break;
default:
laA[2] = genInt;
break label_2;
}
switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
case ASTERISK:
case MIDDLE_DOT:
switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
case ASTERISK:
consumeToken(ASTERISK);
break;
case MIDDLE_DOT:
consumeToken(MIDDLE_DOT);
break;
default:
laA[3] = genInt;
consumeToken(-1);
throw new TokenException();
}
temp = ExponentExpr();
result = result.multiply(temp);
break;
case SOLIDUS:
consumeToken(SOLIDUS);
temp = ExponentExpr();
result = result.divide(temp);
break;
default:
laA[4] = genInt;
consumeToken(-1);
throw new TokenException();
}
}
{
return result;
}
}
Aggregations