- Common ways to obtain Unit
private void myMethod () {Unit u =
Quantity quantity;quantity.getUnit()
ParameterDescriptor descriptor;descriptor.getUnit()
CharSequence charSequence;SimpleUnitFormat.getInstance().parse(charSequence)
- Smart code suggestions by Codota
}
@Override public Map<? extends Unit<?>, Integer> getBaseUnits() { return parentUnit.getBaseUnits(); }
@Override public Map<? extends Unit<?>, Integer> getBaseUnits() { return lower.getBaseUnits(); }
@Override public Map<? extends Unit<?>, Integer> getBaseUnits() { return parentUnit.getBaseUnits(); }
@Override public Map<? extends Unit<?>, Integer> getBaseUnits() { return actualUnit.getBaseUnits(); }
/** * Returns the fundamental (base) dimensions and their exponent whose product is this dimension or <code>null</code> if this dimension is a * fundamental dimension. * * @return the mapping between the base dimensions and their exponent. * @since 1.0 */ @SuppressWarnings("rawtypes") public Map<? extends Dimension, Integer> getBaseDimensions() { Map<? extends Unit, Integer> pseudoUnits = pseudoUnit.getBaseUnits(); if (pseudoUnits == null) return null; final Map<QuantityDimension, Integer> baseDimensions = new HashMap<>(); for (Map.Entry<? extends Unit, Integer> entry : pseudoUnits.entrySet()) { baseDimensions.put(new QuantityDimension(entry.getKey()), entry.getValue()); } return baseDimensions; }
/** * Returns the fundamental (base) dimensions and their exponent whose product is this dimension or <code>null</code> if this dimension is a * fundamental dimension. * * @return the mapping between the base dimensions and their exponent. * @since 1.0 */ @SuppressWarnings("rawtypes") public Map<? extends Dimension, Integer> getBaseDimensions() { Map<? extends Unit, Integer> pseudoUnits = pseudoUnit.getBaseUnits(); if (pseudoUnits == null) return null; final Map<QuantityDimension, Integer> baseDimensions = new HashMap<QuantityDimension, Integer>(); for (Map.Entry<? extends Unit, Integer> entry : pseudoUnits.entrySet()) { baseDimensions.put(new QuantityDimension(entry.getKey()), entry.getValue()); } return baseDimensions; }
/** * Returns the fundamental (base) dimensions and their exponent whose product is this dimension or <code>null</code> if this dimension is a * fundamental dimension. * * @return the mapping between the base dimensions and their exponent. * @since 1.0 */ @SuppressWarnings("rawtypes") public Map<? extends Dimension, Integer> getBaseDimensions() { Map<? extends Unit, Integer> pseudoUnits = pseudoUnit.getBaseUnits(); if (pseudoUnits == null) return null; final Map<QuantityDimension, Integer> baseDimensions = new HashMap<>(); for (Map.Entry<? extends Unit, Integer> entry : pseudoUnits.entrySet()) { baseDimensions.put(new QuantityDimension(entry.getKey()), entry.getValue()); } return baseDimensions; }
@SuppressWarnings("unchecked") private static int productPrecedenceInternal(Unit<?> unit, Appendable buffer, SymbolMap symbolMap) throws IOException { Map<Unit<?>, Integer> productUnits = (Map<Unit<?>, Integer>) unit.getBaseUnits(); int negativeExponentCount = 0;
@SuppressWarnings("unchecked") private static int productPrecedenceInternal(Unit<?> unit, Appendable buffer, SymbolMap symbolMap) throws IOException { Map<Unit<?>, Integer> productUnits = (Map<Unit<?>, Integer>) unit.getBaseUnits(); int negativeExponentCount = 0;
/** * Tests {@link SystemUnit#getBaseUnits()}. This method indirectly tests the results of * {@link SystemUnit#multiply(Unit)}, {@link SystemUnit#divide(Unit)} and {@link SystemUnit#pow(int)} * since this test uses constants that were created with above operations. */ @Test public void testGetBaseDimensions() { assertNull("METRE", Units.METRE .getBaseUnits()); // Null value as per JSR-363 specification. assertNull("SECOND", Units.SECOND.getBaseUnits()); assertTrue("UNITY", Units.UNITY .getBaseUnits().isEmpty()); assertMapEquals(Collections.singletonMap(Units.METRE, 3), Units.CUBIC_METRE.getBaseUnits()); final Map<Unit<?>,Integer> expected = new HashMap<>(4); assertNull(expected.put(Units.KILOGRAM, 1)); assertNull(expected.put(Units.METRE, 1)); assertNull(expected.put(Units.SECOND, -2)); assertMapEquals(expected, Units.NEWTON.getBaseUnits()); }
Map<? extends Unit<?>, Integer> c = unscaled.getBaseUnits(); if (c == null) c = Collections.singletonMap(unit, 1); components = c;
buffer.append(symbol); return NOOP_PRECEDENCE; } else if (unit.getBaseUnits() != null) { Map<Unit<?>, Integer> productUnits = (Map<Unit<?>, Integer>) unit.getBaseUnits(); int negativeExponentCount = 0;
} else { components = unit.getBaseUnits(); if (components == null) { components = Collections.singletonMap(unit, 1);
buffer.append(symbol); return NOOP_PRECEDENCE; } else if (unit.getBaseUnits() != null) { Map<Unit<?>, Integer> productUnits = (Map<Unit<?>, Integer>) unit.getBaseUnits(); int negativeExponentCount = 0;
if (symbol != null) { return noopPrecedenceInternal(buffer, symbol); } else if (unit.getBaseUnits() != null) { return productPrecedenceInternal(unit, buffer, symbolMap); } else if (unit instanceof BaseUnit<?>) {
if (symbol != null) { return noopPrecedenceInternal(buffer, symbol); } else if (unit.getBaseUnits() != null) { return productPrecedenceInternal(unit, buffer, symbolMap); } else if (unit instanceof BaseUnit<?>) {
/** * Tests {@link SystemUnit#multiply(Unit)}. */ @Test @DependsOnMethod("testEqualsAndHashCode") public void testMultiply() { assertSame(Units.METRE, Units.METRE.multiply(Units.UNITY)); assertSame(Units.SQUARE_METRE, Units.METRE.multiply(Units.METRE)); assertSame(Units.CUBIC_METRE, Units.METRE.multiply(Units.SQUARE_METRE)); assertSame(Units.CUBIC_METRE, Units.SQUARE_METRE.multiply(Units.METRE)); final Map<Unit<?>,Integer> expected = new HashMap<>(4); assertNull(expected.put(Units.METRE, 1)); assertNull(expected.put(Units.SECOND, 1)); assertMapEquals(expected, Units.METRE.multiply(Units.SECOND).getBaseUnits()); }