addUnit("(?:mph)", MILE.divide(HOUR), "mph", 1, false);
format.alias(bel.divide(10), "dB");
public static void main(String[] args) { System.out.println(UnitMapping.findUnitMapping(BYTE)); System.out.println(UnitMapping.findUnitMapping(BYTE.divide(SECOND))); System.out.println(UnitMapping.findUnitMapping(BYTE.multiply(1024).divide(SECOND))); System.out.println(UnitMapping.findUnitMapping(BYTE.multiply(1024).divide(SECOND.divide(1000)))); System.out.println(UnitMapping.findUnitMapping(ONE.multiply(1000).divide(SECOND))); System.out.println(UnitMapping.findUnitMapping(ONE.multiply(1000).divide(SECOND.divide(1000)))); System.out.println(UnitMapping.findUnitMapping(ONE.multiply(500).divide(SECOND.divide(2)))); System.out.println(UnitMapping.findUnitMapping(ONE.multiply(50).divide(BIT))); } }
<T extends PcpScale<?>, U extends PcpScale<?>> PcpDimensionSet(Class<T> unitDimension, Class<U> perDimension) { this.unitMappings = new HashSet<UnitMapping>(); for (PcpScale<?> units : unitDimension.getEnumConstants()) { for (PcpScale<?> divisor : perDimension.getEnumConstants()) { unitMappings.add(new UnitMapping(units.getUnit().divide(divisor.getUnit()), PcpDimensionSet.this, units, divisor)); } } }
/** * Returns this quantity divided by the given quantity. */ @Override public final Quantity<?> divide(final Quantity<?> other) { return of(value / other.getValue().doubleValue(), unit.divide(other.getUnit())); }
/** * Returns this quantity divided by the given quantity. */ @Override public final Quantity<?> divide(final Quantity<?> other) { return of(value / other.getValue().doubleValue(), unit.divide(other.getUnit())); }
private static boolean areFunctionallyIdenticalUnits(Unit<?> left, Unit<?> right) { if (!left.isCompatible(right)) { return false; } Unit<?> divided = left.divide(right); if (!divided.getDimension().equals(Dimension.NONE)) { return false; } return divided.asType(Dimensionless.class).getConverterTo(ONE).equals(IDENTITY); }
@Override public Quantity<?> divide(Quantity<?> that) { return NumberQuantity.of((short) value / that.getValue().byteValue(), getUnit().divide(that.getUnit())); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Quantity<?> divide(Quantity<?> that) { return new DoubleQuantity(value / that.getValue().doubleValue(), getUnit().divide(that.getUnit())); }
@Override public ComparableQuantity<?> divide(Quantity<?> that) { return new DoubleQuantity(value / that.getValue().doubleValue(), getUnit().divide(that.getUnit())); }
@Override public ComparableQuantity<?> divide(Quantity<?> that) { return NumberQuantity.of((short) value / that.getValue().shortValue(), getUnit().divide(that.getUnit())); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Quantity<Q> divide(Quantity<?> that) { final Unit<?> unit = getUnit().divide(that.getUnit()); return new NumberQuantity((getValue().doubleValue() / that.getValue().doubleValue()), unit); }
@Override public ComparableQuantity<?> divide(Quantity<?> that) { return NumberQuantity.of((short) value / that.getValue().byteValue(), getUnit().divide(that.getUnit())); }
@Override public ComparableQuantity<?> divide(Quantity<?> that) { return NumberQuantity.of((short) value / that.getValue().shortValue(), getUnit().divide(that.getUnit())); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Quantity<?> divide(Quantity<?> that) { return new FloatQuantity(value / that.getValue().floatValue(), getUnit().divide(that.getUnit())); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public ComparableQuantity<?> divide(ComparableQuantity<?> that) { return new FloatQuantity(value / that.getValue().floatValue(), getUnit().divide(that.getUnit())); }
/** * Tests {@link SystemUnit#divide(Unit)}. */ @Test @DependsOnMethod("testEqualsAndHashCode") public void testDivide() { assertSame(Units.METRE, Units.METRE.divide(Units.UNITY)); assertSame(Units.METRE, Units.SQUARE_METRE.divide(Units.METRE)); assertSame(Units.METRE, Units.CUBIC_METRE.divide(Units.SQUARE_METRE)); assertSame(Units.SQUARE_METRE, Units.CUBIC_METRE.divide(Units.METRE)); assertSame(Units.METRES_PER_SECOND, Units.METRE.divide(Units.SECOND)); }
@Override public ComparableQuantity<?> divide(Quantity<?> that) { return new DecimalQuantity(value.divide(Equalizer.toBigDecimal(that.getValue()), MathContext.DECIMAL128), getUnit().divide(that.getUnit())); }
/** * Tests formatting of units when the numerator is unity. * * @see <a href="https://issues.apache.org/jira/browse/SIS-414">SIS-414</a> */ @Test public void testUnity() { final UnitFormat f = new UnitFormat(Locale.UK); assertEquals( "1∕m²", f.format(Units.UNITY.divide(Units.SQUARE_METRE))); assertEquals("10⁻²∕m²", f.format(Units.UNITY.divide(100).divide(Units.SQUARE_METRE))); assertEquals("10⁻²∕m²", f.format(Units.PERCENT.divide(Units.SQUARE_METRE))); }
/** * Tests formatting of some more unusual units. The units tested by this method are artificial * and somewhat convolved. The intent is to verify that unit formatting is still robust. */ @Test public void testFormatUnusual() { final UnitFormat f = new UnitFormat(Locale.UK); final Unit<?> u1 = Units.SECOND.pow(-1).multiply(3); assertEquals("3∕s", f.format(u1)); assertEquals("3⋅m∕s", f.format(Units.METRE.multiply(u1))); assertEquals("m^⅔", f.format(Units.METRE.pow(2).root(3))); assertEquals("km²∕(s⋅kg)", f.format(Units.SQUARE_METRE.divide(Units.SECOND).divide(Units.KILOGRAM).multiply(1E+6))); }