Java Code Examples for javax.measure.unit.Unit#equals()
The following examples show how to use
javax.measure.unit.Unit#equals() .
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: MagmaUnitConverter.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
public String convertUnit(Unit<? extends Quantity> standardUnit, Unit<? extends Quantity> unit) { if (standardUnit != null && unit != 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); double estimatedValue1 = value1.getEstimatedValue(); double estimatedValue2 = value2.getEstimatedValue(); if (estimatedValue1 > estimatedValue2) { conversionScript .append(".times(") .append(value1.divide(value2).getEstimatedValue()) .append(")"); } else { conversionScript .append(".div(") .append(value2.divide(value1).getEstimatedValue()) .append(")"); } } if (conversionScript.length() > 0) { return conversionScript.toString(); } } } } return StringUtils.EMPTY; }
Example 2
Source File: ProjectionFactory.java From gama with GNU General Public License v3.0 | 5 votes |
void computeTargetCRS(final IScope scope, final CoordinateReferenceSystem crs, final double longitude, final double latitude) { // If we already know in which CRS we project the data in GAMA, no need to recompute it. This information is // normally wiped when an experiment is disposed if (targetCRS != null) { return; } try { if (!GamaPreferences.External.LIB_TARGETED.getValue()) { targetCRS = computeDefaultCRS(scope, GamaPreferences.External.LIB_TARGET_CRS.getValue(), true); } else { if (crs != null && crs instanceof DefaultProjectedCRS) { // Temporary fix of issue 766... a better solution final CartesianCS ccs = ((DefaultProjectedCRS) crs).getCoordinateSystem(); final Unit<?> unitX = ccs.getAxis(0).getUnit(); if (unitX != null && !unitX.equals(SI.METER)) { unitConverter = unitX.getConverterTo(SI.METER); } targetCRS = crs; } else { final int index = (int) (0.5 + (longitude + 186.0) / 6); final boolean north = latitude > 0; final String newCode = EPSGPrefix + (32600 + index + (north ? 0 : 100)); targetCRS = getCRS(scope, newCode); } } } catch (final GamaRuntimeException e) { e.addContext( "The cause could be that you try to re-project already projected data (see Gama > Preferences... > External for turning the option to true)"); throw e; } }
Example 3
Source File: VectorMeasure.java From microMathematics with GNU General Public License v3.0 | 5 votes |
@Override public MultiDimensional<Q> to(Unit<Q> unit) { if ((unit == _unit) || (unit.equals(_unit))) return this; UnitConverter cvtr = _unit.getConverterTo(unit); double[] newValues = new double[_components.length]; for (int i=0; i < _components.length; i++) { newValues[i] = cvtr.convert(_components[i]); } return new MultiDimensional<>(newValues, unit); }
Example 4
Source File: VectorMeasure.java From microMathematics with GNU General Public License v3.0 | 5 votes |
@Override public double doubleValue(Unit<Q> unit) { double normSquare = _components[0] * _components[0]; for (int i=1, n=_components.length; i < n;) { double d = _components[i++]; normSquare += d * d; } if ((unit == _unit) || (unit.equals(_unit))) return Math.sqrt(normSquare); return _unit.getConverterTo(unit).convert(Math.sqrt(normSquare)); }
Example 5
Source File: VectorMeasure.java From microMathematics with GNU General Public License v3.0 | 5 votes |
@Override public ThreeDimensional<Q> to(Unit<Q> unit) { if ((unit == _unit) || (unit.equals(_unit))) return this; UnitConverter cvtr = _unit.getConverterTo(unit); return new ThreeDimensional<>(cvtr.convert(_x), cvtr.convert(_y), cvtr.convert(_z), unit); }
Example 6
Source File: VectorMeasure.java From microMathematics with GNU General Public License v3.0 | 5 votes |
@Override public double doubleValue(Unit<Q> unit) { double norm = Math.sqrt(_x * _x + _y * _y + _z * _z); if ((unit == _unit) || (unit.equals(_unit))) return norm; return _unit.getConverterTo(unit).convert(norm); }
Example 7
Source File: VectorMeasure.java From microMathematics with GNU General Public License v3.0 | 5 votes |
@Override public TwoDimensional<Q> to(Unit<Q> unit) { if ((unit == _unit) || (unit.equals(_unit))) return this; UnitConverter cvtr = _unit.getConverterTo(unit); return new TwoDimensional<>(cvtr.convert(_x), cvtr.convert(_y), unit); }
Example 8
Source File: VectorMeasure.java From microMathematics with GNU General Public License v3.0 | 5 votes |
@Override public double doubleValue(Unit<Q> unit) { double norm = Math.sqrt(_x * _x + _y * _y); if ((unit == _unit) || (unit.equals(_unit))) return norm; return _unit.getConverterTo(unit).convert(norm); }
Example 9
Source File: DecimalMeasure.java From microMathematics with GNU General Public License v3.0 | 4 votes |
public double doubleValue(Unit<Q> unit) { if ((unit == _unit) || (unit.equals(_unit))) return _value.doubleValue(); return _unit.getConverterTo(unit).convert(_value.doubleValue()); }
Example 10
Source File: NumericAlgorithmGenerator.java From molgenis with GNU Lesser General Public License v3.0 | 4 votes |
String generateUnitConversionAlgorithm(Attribute targetAttribute, Attribute sourceAttribute) { String algorithm = null; Unit<? extends Quantity> targetUnit = unitResolver.resolveUnit(targetAttribute); Unit<? extends Quantity> sourceUnit = unitResolver.resolveUnit(sourceAttribute); if (sourceUnit != null) { if (targetUnit != null && !sourceUnit.equals(targetUnit)) { // if units are convertible, create convert algorithm UnitConverter unitConverter; try { unitConverter = sourceUnit.getConverterTo(targetUnit); } catch (ConversionException e) { unitConverter = null; // algorithm sets source unit and assigns source value to target algorithm = String.format( "$('%s').unit('%s').value();", sourceAttribute.getName(), sourceUnit.toString()); } if (unitConverter != null) { // algorithm sets source unit and assigns value converted to target unit to target algorithm = String.format( "$('%s').unit('%s').toUnit('%s').value();", sourceAttribute.getName(), sourceUnit.toString(), targetUnit.toString()); } } else { // algorithm sets source unit and assigns source value to target algorithm = String.format( "$('%s').unit('%s').value();", sourceAttribute.getName(), sourceUnit.toString()); } } if (algorithm == null) { // algorithm assigns source value to target algorithm = String.format("$('%s').value();", sourceAttribute.getName()); } return algorithm; }
Example 11
Source File: Measure.java From microMathematics with GNU General Public License v3.0 | 4 votes |
@Override public Measure<java.lang.Double, Q> to(Unit<Q> unit) { if ((unit == _unit) || (unit.equals(_unit))) return this; return new Double<>(doubleValue(unit), unit); }
Example 12
Source File: Measure.java From microMathematics with GNU General Public License v3.0 | 4 votes |
public long longValue(Unit<Q> unit) throws ArithmeticException { if ((unit == _unit) || (unit.equals(_unit))) return _value; // No conversion, returns value directly. return super.longValue(unit); }
Example 13
Source File: Measure.java From microMathematics with GNU General Public License v3.0 | 4 votes |
public double doubleValue(Unit<Q> unit) { if ((unit == _unit) || (unit.equals(_unit))) return _value; return _unit.getConverterTo(unit).convert(_value); }
Example 14
Source File: Measure.java From microMathematics with GNU General Public License v3.0 | 4 votes |
@Override public Measure<java.lang.Integer, Q> to(Unit<Q> unit) { if ((unit == _unit) || (unit.equals(_unit))) return this; return new Integer<>(intValue(unit), unit); }
Example 15
Source File: Measure.java From microMathematics with GNU General Public License v3.0 | 4 votes |
public double doubleValue(Unit<Q> unit) { if ((unit == _unit) || (unit.equals(_unit))) return _value; return _unit.getConverterTo(unit).convert(_value); }
Example 16
Source File: Measure.java From microMathematics with GNU General Public License v3.0 | 4 votes |
@Override public Measure<java.lang.Float, Q> to(Unit<Q> unit) { if ((unit == _unit) || (unit.equals(_unit))) return this; return new Float<>(floatValue(unit), unit); }
Example 17
Source File: Measure.java From microMathematics with GNU General Public License v3.0 | 4 votes |
public long longValue(Unit<Q> unit) throws ArithmeticException { if ((unit == _unit) || (unit.equals(_unit))) return _value; // No conversion, returns value directly. return super.longValue(unit); }
Example 18
Source File: Measure.java From microMathematics with GNU General Public License v3.0 | 4 votes |
public double doubleValue(Unit<Q> unit) { if ((unit == _unit) || (unit.equals(_unit))) return _value; return _unit.getConverterTo(unit).convert(_value); }
Example 19
Source File: Measure.java From microMathematics with GNU General Public License v3.0 | 4 votes |
@Override public Measure<java.lang.Long, Q> to(Unit<Q> unit) { if ((unit == _unit) || (unit.equals(_unit))) return this; return new Long<>(longValue(unit), unit); }
Example 20
Source File: Measure.java From microMathematics with GNU General Public License v3.0 | 4 votes |
public double doubleValue(Unit<Q> unit) { if ((unit == _unit) || (unit.equals(_unit))) return _value; return _unit.getConverterTo(unit).convert(_value); }