Package javax.measure.converter

Examples of javax.measure.converter.UnitConverter


  }

  public static double fromMeterToCrs(double value,
      CoordinateReferenceSystem crs) {
    Unit<?> unit = getUnit(crs);
    UnitConverter converter = SI.METER.getConverterTo(unit);
    return converter.convert(value);
  }
View Full Code Here


  }

  public static double fromCrsToMeter(double value,
      CoordinateReferenceSystem crs) {
    Unit<?> unit = getUnit(crs);
    UnitConverter converter = unit.getConverterTo(javax.measure.unit.SI.METER);
    return converter.convert(value);
  }
View Full Code Here

     */
    private static <Q extends Quantity> void checkConversion(
            final double expected, final Unit<Q> unitExpected,
            final double actual,   final Unit<Q> unitActual)
    {
        UnitConverter converter = unitActual.getConverterTo(unitExpected);
        assertEquals(expected, converter.convert(actual), 1E-6);
        converter = converter.inverse();
        assertEquals(actual, converter.convert(expected), 1E-6);
    }
View Full Code Here

            if (elementType == type) {
                return (MeasurementRange<N>) this;
            }
            targetUnit = unit;
        } else if (unit != null) {
            final UnitConverter converter = unit.getConverterToAny(targetUnit);
            if (!converter.equals(UnitConverter.IDENTITY)) {
                boolean minInc = isMinIncluded;
                boolean maxInc = isMaxIncluded;
                double minimum = converter.convert(getMinDouble());
                double maximum = converter.convert(getMaxDouble());
                if (minimum > maximum) {
                    final double  td = minimum; minimum = maximum; maximum = td;
                    final boolean tb = minInc;  minInc  = maxInc;  maxInc  = tb;
                }
                if (Numbers.isInteger(type)) {
View Full Code Here

    /**
     * On deserialization, returns an existing instance.
     */
    protected final Object readResolve() throws ObjectStreamException {
        UnitConverter candidate = INTEGER;
        for (int i=0; i<4; i++) {
            switch (i) {
                case 0break; // Do nothing since candidate is already set to INTEGER.
                case 1// Fallthrough
                case 3:  candidate = candidate.inverse(); break;
                case 2:  candidate = FRACTIONAL; break;
            }
            if (equals(candidate)) {
                return candidate;
            }
View Full Code Here

    @Override
    public Date[] numberToDate(final String symbol, final Number... values) throws IOException {
        final Date[] dates = new Date[values.length];
        final String[] parts = TIME_UNIT_PATTERN.split(symbol);
        if (parts.length == 2) try {
            final UnitConverter converter = Units.valueOf(parts[0]).getConverterToAny(Units.MILLISECOND);
            final long epoch = JDK8.parseDateTime(parts[1], DEFAULT_TIMEZONE_IS_UTC).getTime();
            for (int i=0; i<values.length; i++) {
                final Number value = values[i];
                if (value != null) {
                    dates[i] = new Date(epoch + Math.round(converter.convert(value.doubleValue())));
                }
            }
        } catch (ConversionException e) {
            listeners.warning(null, e);
        } catch (IllegalArgumentException e) {
View Full Code Here

            if (!LENGTH_UNITS.containsKey(unit)) {
              LENGTH_UNITS.put(unit, unit.toString());

              Unit<?> baseUnit = unit.getStandardUnit();

              UnitConverter multiply = unit.toStandardUnit();
              crsSequence.append("|" + unit.toString()); //$NON-NLS-1$
            }
          } catch (Exception e) {
            LOGGER.warning("exception" + e.getMessage()); //$NON-NLS-1$
          }
View Full Code Here

                if (Objects.equals(sourceUnit, targetUnit)) {
                    // There is no units conversion to apply
                    // between source[i] and target[j].
                    continue;
                }
                final UnitConverter converter = sourceUnit.getConverterToAny(targetUnit);
                if (!(converter instanceof LinearConverter)) {
                    throw new ConversionException(Errors.format(
                              Errors.Keys.NonLinearUnitConversion_2, sourceUnit, targetUnit));
                }
                final double offset = converter.convert(0);
                final double scale  = Units.derivative(converter, 0);
                matrix.setElement(j, i, element*scale);
                matrix.setElement(j, sourceDim, matrix.getElement(j, sourceDim) + element*offset);
            }
        }
View Full Code Here

        RangeMeaning rm = property(properties, RANGE_MEANING_KEY, RangeMeaning.class);
        if (minimum == null && maximum == null && rm == null) {
            double min = Double.NEGATIVE_INFINITY;
            double max = Double.POSITIVE_INFINITY;
            if (Units.isAngular(unit)) {
                final UnitConverter fromDegrees = NonSI.DEGREE_ANGLE.getConverterTo(unit.asType(Angle.class));
                final AxisDirection dir = AxisDirections.absolute(direction);
                if (dir.equals(AxisDirection.NORTH)) {
                    min = fromDegrees.convert(Latitude.MIN_VALUE);
                    max = fromDegrees.convert(Latitude.MAX_VALUE);
                    rm  = RangeMeaning.EXACT;
                } else if (dir.equals(AxisDirection.EAST)) {
                    min = fromDegrees.convert(Longitude.MIN_VALUE);
                    max = fromDegrees.convert(Longitude.MAX_VALUE);
                    rm  = RangeMeaning.WRAPAROUND; // 180°E wraps to 180°W
                }
                if (min > max) {
                    final double t = min;
                    min = max;
View Full Code Here

            if (elementType == type) {
                return (MeasurementRange<N>) this;
            }
            targetUnit = unit;
        } else if (unit != null) {
            final UnitConverter converter = unit.getConverterToAny(targetUnit);
            if (!converter.equals(UnitConverter.IDENTITY)) {
                boolean minInc = isMinIncluded;
                boolean maxInc = isMaxIncluded;
                double minimum = converter.convert(getMinDouble());
                double maximum = converter.convert(getMaxDouble());
                if (minimum > maximum) {
                    final double  td = minimum; minimum = maximum; maximum = td;
                    final boolean tb = minInc;  minInc  = maxInc;  maxInc  = tb;
                }
                if (Numbers.isInteger(type)) {
View Full Code Here

TOP

Related Classes of javax.measure.converter.UnitConverter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.