public double doubleValue(Unit<Q> unit) { if ((unit == _unit) || (unit.equals(_unit))) return _value; return _unit.getConverterTo(unit).convert(_value); }
if (isNotBlank(nextValue.getCode())) { Unit<? extends javax.measure.quantity.Quantity> unit = Unit.valueOf(nextValue.getCode()); javax.measure.converter.UnitConverter dayConverter = unit.getConverterTo(NonSI.DAY); double dayValue = dayConverter.convert(nextValue.getValue().doubleValue()); Duration newValue = new Duration(); newValue.setSystem(SearchParamConstants.UCUM_NS); newValue.setCode(NonSI.DAY.toString()); newValue.setValue(dayValue); nextValue = newValue;
private static boolean areFunctionallyIdenticalUnits(Unit<?> left, Unit<?> right) { if (!left.isCompatible(right)) { return false; } Unit<?> divided = left.divide(right); if (!divided.getDimension().equals(javax.measure.unit.Dimension.NONE)) { return false; } return divided.asType(Dimensionless.class).getConverterTo(Unit.ONE).equals( UnitConverter.IDENTITY); }
public void updatePixelUnit(CoordinateReferenceSystem crs) { final CoordinateSystem coordinateSystem = crs.getCoordinateSystem(); final String unitX = coordinateSystem.getAxis(0).getUnit().toString(); if (!unitX.equals(pixelXUnit.getText())) { pixelXUnit.setText(unitX); pixelSizeXField.setValue(unitMap.get(unitX)); } final String unitY = coordinateSystem.getAxis(1).getUnit().toString(); if (!unitY.equals(pixelYUnit.getText())) { pixelYUnit.setText(unitY); pixelSizeYField.setValue(unitMap.get(unitY)); } }
int dimension = cs.getDimension(); if (cs.getAxis(j).getDirection().equals(targetDirections[i])) { axisIndices[i] = j; converters[i] = cs.getAxis(j).getUnit().getConverterTo(targetUnits[i]); notfound = false; returnable[(i * dimension) + j] = converters[j].convert(positions[i].getOrdinate(axisIndices[j]));
/** * Derives the unit of data for a band in the destination image. * This method compute {@code sample}/{@code axis} where: * * <ul> * <li>{@code sample} is the sample unit in source image.</li> * <li>{@code axis} is the coordinate reference system axis unit.</li> * </ul> */ protected Unit deriveUnit(final Unit[] units, final Parameters parameters) { final CoordinateSystem cs = parameters.crs.getCoordinateSystem(); if (!DEBUG && units.length==1 && units[0]!=null) { final Unit spatialUnit = cs.getAxis(0).getUnit(); for (int i=Math.min(cs.getDimension(), 2); --i>=0;) { if (!spatialUnit.equals(cs.getAxis(i).getUnit())) { return super.deriveUnit(units, parameters); } } try { return units[0].divide(spatialUnit); } catch (RuntimeException exception) { // Can't compute units... We will compute image data // anyway, but the result will have no know unit. // TODO: Catch a more specific exception. } } return super.deriveUnit(units, parameters); } }
public double getOrdinate(int dimension) throws IndexOutOfBoundsException { if (dimension == 0) { Unit<?> u = GeographicCRS.LATITUDE_LONGITUDE_CS.getAxis(0).getUnit(); return DEGREE_ANGLE.getConverterTo(u).convert(_latitude); } else if (dimension == 1) { Unit<?> u = GeographicCRS.LATITUDE_LONGITUDE_CS.getAxis(1).getUnit(); return DEGREE_ANGLE.getConverterTo(u).convert(_longitude); } else { throw new IndexOutOfBoundsException(); } }
@SuppressWarnings("unchecked") public static Unit<Area> getAreaUnit(CoordinateReferenceSystem crs) { CoordinateReferenceSystem horCRS = CRS.getHorizontalCRS(crs); if (horCRS instanceof GeographicCRS) { return SI.SQUARE_METRE; // default } else { Unit<?> distUnit = horCRS.getCoordinateSystem().getAxis(0).getUnit(); return (Unit<Area>) distUnit.times(distUnit); } } }
generator = new GeographicGenerator(center, quadrantSegments, crs); } else { Unit unit = hor.getCoordinateSystem().getAxis(0).getUnit(); UnitConverter converter = SI.METER.getConverterTo(unit); generator = new MetricGenerator(center, quadrantSegments, converter);
if (linearUnit != null && !SI.METER.isCompatible(linearUnit)) { throw new IllegalArgumentException(Errors.format( ErrorKeys.NON_LINEAR_UNIT_$1, linearUnit)); if (SI.METER.isCompatible(linearUnit)) { if (SI.METER.equals(linearUnit)) { metadata.addGeoShortParam( GeoTiffPCSCodes.ProjLinearUnitsGeoKey, if (NonSI.NAUTICAL_MILE.equals(linearUnit)) { metadata.addGeoShortParam( GeoTiffPCSCodes.ProjLinearUnitsGeoKey, metadata.addGeoDoubleParam( GeoTiffPCSCodes.ProjLinearUnitSizeGeoKey, linearUnit .getConverterTo(SI.METER).convert(1)); if (NonSI.FOOT.equals(linearUnit)) { metadata.addGeoShortParam( GeoTiffPCSCodes.ProjLinearUnitsGeoKey, metadata.addGeoDoubleParam( GeoTiffPCSCodes.ProjLinearUnitSizeGeoKey, linearUnit .getConverterTo(SI.METER).convert(1)); if (NonSI.YARD.equals(linearUnit)) { metadata.addGeoShortParam( GeoTiffPCSCodes.ProjLinearUnitsGeoKey,
AmountWrapper getInternalAmount(String description) { Unit<?> unit = CategoryMapperUtil.findDurationUnit(description); if (unit != null && unit.isCompatible(STANDARD_PER_WEEK_UNIT)) { return AmountWrapper.create( Amount.rangeOf((double) 3, NonSI.DAY.inverse().getConverterTo(unit).convert(1) - 1, unit) .to(STANDARD_PER_WEEK_UNIT), false); } return null; } }
StringBuilder conversionScript = new StringBuilder(); for (String standardUnitName : findCompositeUnitNames(standardUnit.toString())) { for (String customeUnitName : findCompositeUnitNames(unit.toString())) { Unit<?> unit1 = Unit.valueOf(standardUnitName); Unit<?> unit2 = Unit.valueOf(customeUnitName); if (unit1 != null && unit2 != null && unit1.isCompatible(unit2) && !unit1.equals(unit2)) { Amount<?> value2 = Amount.valueOf(1, unit2); Amount<?> value1 = value2.to(unit1);
literal = s; UnitConverter duration = Unit.valueOf(origUnit).getConverterTo(MILLI(SECOND)); value = (long) duration.convert(origQuantity); } catch (Exception e) { throw new KlabRuntimeException(e);
public static double parseValueAsUnit(String string, Unit<?> unit) { double parsedValue = parseValue(string); Unit<?> parsedUnit = parseUnit(string); return parsedUnit.getConverterTo(unit).convert(parsedValue); }
/** * Workaround for RFE #4093999 ("Relax constraint on placement of this()/super() * call in constructors"). */ private static UnitConverter getConverter(final Unit<?> source) throws ConversionException { if (source == null) { throw new ConversionException(Errors.format(ErrorKeys.NO_UNIT)); } return source.getConverterTo(MILLISECOND); }
/** * Returns the representation of this dimension. * * @return the representation of this dimension. */ public String toString() { return _pseudoUnit.toString(); }
Unit<?> unit1 = Unit.valueOf(units1); Unit<?> unit2 = Unit.valueOf(units2); try { return (unit1.getConverterToAny(unit2).convert(1) ==1); } catch (UnsupportedOperationException e) { return false;