Java Code Examples for javax.measure.UnitConverter#concatenate()

The following examples show how to use javax.measure.UnitConverter#concatenate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultTemporalCRS.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the fields required for {@link #toInstant(double)} and {@link #toValue(Instant)} operations.
 */
private void initializeConverter() {
    toSeconds = getUnit().getConverterTo(Units.SECOND);
    long t = datum.getOrigin().getTime();
    origin = t / MILLIS_PER_SECOND;
    t %= MILLIS_PER_SECOND;
    if (t != 0) {
        /*
         * The origin is usually an integer amount of days or hours. It rarely has a fractional amount of seconds.
         * If it happens anyway, put the fractional amount of seconds in the converter instead than adding another
         * field in this class for such very rare situation. Accuracy should be okay since the offset is small.
         */
        UnitConverter c = Units.converter(null, new Fraction((int) t, MILLIS_PER_SECOND).simplify());
        toSeconds = c.concatenate(toSeconds);
    }
}
 
Example 2
Source File: SystemUnit.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the unit derived from this unit using the specified converter.
 *
 * @param  operation  the converter from the transformed unit to this unit.
 * @return the unit after the specified transformation.
 */
@Override
public Unit<Q> transform(UnitConverter operation) {
    ArgumentChecks.ensureNonNull("operation", operation);
    AbstractUnit<Q> base = this;
    final ConventionalUnit<Q> pseudo = Prefixes.pseudoSystemUnit(this);
    if (pseudo != null) {
        /*
         * Special case for Units.KILOGRAM, to be replaced by Units.GRAM so a prefix can be computed.
         * The kilogram may appear in an expression like "kg/m", which we want to replace by "g/m".
         *
         * Note: we could argue that this block should be UnitFormat's work rather than SystemUnit.
         * We perform this work here because this unit symbol may be different than what UnitFormat
         * would infer, for example because of symbols recorded by sequence of Unit.multiply(Unit)
         * and Unit.divide(Unit) operations.
         */
        operation = operation.concatenate(pseudo.toTarget.inverse());
        base = pseudo;
    }
    return ConventionalUnit.create(base, operation);
}