Search in sources :

Example 11 with Unit

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);
}
Also used : Unit(javax.measure.Unit) Test(org.junit.Test)

Example 12 with Unit

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());
}
Also used : Unit(javax.measure.Unit) AbstractUnit(tec.uom.se.AbstractUnit) TransformedUnit(tec.uom.se.unit.TransformedUnit) Test(org.junit.Test)

Example 13 with Unit

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);
}
Also used : Unit(javax.measure.Unit) AbstractUnit(tech.units.indriya.AbstractUnit)

Example 14 with 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);
}
Also used : Unit(javax.measure.Unit) AbstractUnit(tech.units.indriya.AbstractUnit)

Example 15 with 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;
    }
}
Also used : Unit(javax.measure.Unit) AbstractUnit(tech.units.indriya.AbstractUnit)

Aggregations

Unit (javax.measure.Unit)52 AbstractUnit (tech.units.indriya.AbstractUnit)12 AbstractUnit (tec.uom.se.AbstractUnit)11 UnitConverter (javax.measure.UnitConverter)5 Test (org.junit.Test)5 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)4 BigDecimal (java.math.BigDecimal)4 Length (javax.measure.quantity.Length)4 CoordinateSystemAxis (org.opengis.referencing.cs.CoordinateSystemAxis)4 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)3 Format (java.text.Format)3 NumberFormat (java.text.NumberFormat)3 IncommensurableException (javax.measure.IncommensurableException)3 Angle (javax.measure.quantity.Angle)3 TestUnit (javax.measure.test.TestUnit)3 Test (org.junit.jupiter.api.Test)3 IdentifiedObject (org.opengis.referencing.IdentifiedObject)3 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)3 ChainedCoordinatesOperation (com.revolsys.geometry.cs.projection.ChainedCoordinatesOperation)2