Search in sources :

Example 16 with Unit

use of javax.measure.Unit in project indriya by unitsofmeasurement.

the class LocalUnitFormatParser method parseUnit.

public final Unit parseUnit() throws TokenException {
    Unit result = CompoundExpr();
    consumeToken(0);
    {
        return result;
    }
}
Also used : Unit(javax.measure.Unit) AbstractUnit(tech.units.indriya.AbstractUnit)

Example 17 with Unit

use of javax.measure.Unit in project indriya by unitsofmeasurement.

the class LocalUnitFormatParser method AddExpr.

public final Unit AddExpr() throws TokenException {
    Unit result = AbstractUnit.ONE;
    Number n1 = null;
    Token sign1 = null;
    Number n2 = null;
    Token sign2 = null;
    if (jj_2_1(2147483647)) {
        n1 = NumberExpr();
        sign1 = Sign();
    } else {
    }
    result = MulExpr();
    switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
        case PLUS:
        case MINUS:
            sign2 = Sign();
            n2 = NumberExpr();
            break;
        default:
            laA[1] = genInt;
    }
    if (n1 != null) {
        if (sign1.image.equals("-")) {
            result = result.multiply(-1);
        }
        result = result.shift(n1.doubleValue());
    }
    if (n2 != null) {
        double offset = n2.doubleValue();
        if (sign2.image.equals("-")) {
            offset = -offset;
        }
        result = result.shift(offset);
    }
    {
        return result;
    }
}
Also used : Unit(javax.measure.Unit) AbstractUnit(tech.units.indriya.AbstractUnit)

Example 18 with Unit

use of javax.measure.Unit in project indriya by unitsofmeasurement.

the class LocalUnitFormatParser method ExponentExpr.

public final Unit ExponentExpr() throws TokenException {
    Unit result = AbstractUnit.ONE;
    Exponent exponent = null;
    Token token = null;
    if (jj_2_2(2147483647)) {
        switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
            case INTEGER:
                token = consumeToken(INTEGER);
                break;
            case E:
                token = consumeToken(E);
                break;
            default:
                laA[5] = genInt;
                consumeToken(-1);
                throw new TokenException();
        }
        consumeToken(CARET);
        result = AtomicExpr();
        double base;
        if (token.kind == INTEGER) {
            base = Integer.parseInt(token.image);
        } else {
            base = StrictMath.E;
        }
        {
            return result.transform(new LogConverter(base).inverse());
        }
    } else {
        switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
            case OPEN_PAREN:
            case INTEGER:
            case FLOATING_POINT:
            case UNIT_IDENTIFIER:
                result = AtomicExpr();
                switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
                    case CARET:
                    case SUPERSCRIPT_INTEGER:
                        exponent = Exp();
                        break;
                    default:
                        laA[6] = genInt;
                }
                if (exponent != null) {
                    if (exponent.pow != 1) {
                        result = result.pow(exponent.pow);
                    }
                    if (exponent.root != 1) {
                        result = result.root(exponent.root);
                    }
                }
                {
                    return result;
                }
            case LOG:
            case NAT_LOG:
                switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
                    case LOG:
                        consumeToken(LOG);
                        switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
                            case INTEGER:
                                token = consumeToken(INTEGER);
                                break;
                            default:
                                laA[7] = genInt;
                        }
                        break;
                    case NAT_LOG:
                        token = consumeToken(NAT_LOG);
                        break;
                    default:
                        laA[8] = genInt;
                        consumeToken(-1);
                        throw new TokenException();
                }
                consumeToken(OPEN_PAREN);
                result = AddExpr();
                consumeToken(CLOSE_PAREN);
                double base = 10;
                if (token != null) {
                    if (token.kind == INTEGER) {
                        base = Integer.parseInt(token.image);
                    } else if (token.kind == NAT_LOG) {
                        base = StrictMath.E;
                    }
                }
                {
                    return result.transform(new LogConverter(base));
                }
            default:
                laA[9] = genInt;
                consumeToken(-1);
                throw new TokenException();
        }
    }
}
Also used : LogConverter(tech.units.indriya.function.LogConverter) Unit(javax.measure.Unit) AbstractUnit(tech.units.indriya.AbstractUnit)

Example 19 with Unit

use of javax.measure.Unit in project indriya 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.jupiter.api.Test)

Example 20 with Unit

use of javax.measure.Unit in project uom-se 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(tec.uom.se.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