/** * Returns the quotient of this dimension with the one specified. * * @param that the dimension divisor. * @return <code>this / that</code> */ public final Dimension divide(Dimension that) { return new Dimension(this._pseudoUnit.divide(that._pseudoUnit)); }
/** * Returns the quotient of this dimension with the one specified. * * @param that the dimension divisor. * @return <code>this / that</code> */ public final Dimension divide(Dimension that) { return new Dimension(this._pseudoUnit.divide(that._pseudoUnit)); }
/** * Returns the quotient of this dimension with the one specified. * * @param that the dimension divisor. * @return <code>this / that</code> */ public final Dimension divide(Dimension that) { return new Dimension(this._pseudoUnit.divide(that._pseudoUnit)); }
@Override public Unit<Velocity> getSpeedUnit() { return SI.KILOMETRE.divide(NonSI.MINUTE).asType(Velocity.class); }
<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 a unit equals to the given root of this unit. * * @param n the root's order. * @return the result of taking the given root of this unit. * @throws ArithmeticException if <code>n == 0</code>. */ public final Unit<? extends Quantity> root(int n) { if (n > 0) { return ProductUnit.getRootInstance(this, n); } else if (n == 0) { throw new ArithmeticException("Root's order of zero"); } else { // n < 0 return ONE.divide(this.root(-n)); } }
/** * Returns a unit equals to the given root of this unit. * * @param n the root's order. * @return the result of taking the given root of this unit. * @throws ArithmeticException if <code>n == 0</code>. */ public final Unit<? extends Quantity> root(int n) { if (n > 0) { return ProductUnit.getRootInstance(this, n); } else if (n == 0) { throw new ArithmeticException("Root's order of zero"); } else { // n < 0 return ONE.divide(this.root(-n)); } }
/** * Returns a unit equals to the given root of this unit. * * @param n the root's order. * @return the result of taking the given root of this unit. * @throws ArithmeticException if <code>n == 0</code>. */ public final Unit<? extends Quantity> root(int n) { if (n > 0) { return ProductUnit.getRootInstance(this, n); } else if (n == 0) { throw new ArithmeticException("Root's order of zero"); } else { // n < 0 return ONE.divide(this.root(-n)); } }
public static void main(String[] args) { System.out.println(UnitMapping.findUnitMapping(NonSI.BYTE)); System.out.println(UnitMapping.findUnitMapping(NonSI.BYTE.divide(SI.SECOND))); System.out.println(UnitMapping.findUnitMapping(NonSI.BYTE.times(1024).divide(SI.SECOND))); System.out.println(UnitMapping.findUnitMapping(NonSI.BYTE.times(1024).divide( SI.SECOND.divide(1000)))); System.out.println(UnitMapping.findUnitMapping(Unit.ONE.times(1000).divide(SI.SECOND))); System.out.println(UnitMapping.findUnitMapping(Unit.ONE.times(1000).divide( SI.SECOND.divide(1000)))); System.out.println(UnitMapping.findUnitMapping(Unit.ONE.times(500).divide( SI.SECOND.divide(2)))); System.out.println(UnitMapping.findUnitMapping(Unit.ONE.times(50).divide(SI.BIT))); } }
/** * Returns a unit equals to this unit raised to an exponent. * * @param n the exponent. * @return the result of raising this unit to the exponent. */ public final Unit<? extends Quantity> pow(int n) { if (n > 0) { return this.times(this.pow(n - 1)); } else if (n == 0) { return ONE; } else { // n < 0 return ONE.divide(this.pow(-n)); } }
/** * Returns a unit equals to this unit raised to an exponent. * * @param n the exponent. * @return the result of raising this unit to the exponent. */ public final Unit<? extends Quantity> pow(int n) { if (n > 0) { return this.times(this.pow(n - 1)); } else if (n == 0) { return ONE; } else { // n < 0 return ONE.divide(this.pow(-n)); } }
/** * Returns a unit equals to this unit raised to an exponent. * * @param n the exponent. * @return the result of raising this unit to the exponent. */ public final Unit<? extends Quantity> pow(int n) { if (n > 0) { return this.times(this.pow(n - 1)); } else if (n == 0) { return ONE; } else { // n < 0 return ONE.divide(this.pow(-n)); } }
@Override public ImmutableSet<ModelBuilder<?, ?>> getModelBuilders() { return ImmutableSet.<ModelBuilder<?, ?>>builder() .add( TimeModel.builder() .withTickLength(1L) .withTimeUnit(NonSI.MINUTE)) .add( RoadModelBuilders.plane() .withMinPoint(getMin()) .withMaxPoint(getMax()) .withDistanceUnit(SI.KILOMETER) .withMaxSpeed(MAX_SPEED) .withSpeedUnit( SI.KILOMETRE.divide(NonSI.MINUTE).asType(Velocity.class))) .add( DefaultPDPModel.builder() .withTimeWindowPolicy(TimeWindowPolicies.TARDY_ALLOWED)) .add( StatsTracker.builder()) .build(); }
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); }
/** * 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); } }
addLabel(THERM, "thm"); addLabel(PSI, "psi"); addLabel(NonSI.FOOT.pow(3).divide(NonSI.MINUTE), "cfm"); addAlias(NonSI.REVOLUTION.divide(NonSI.MINUTE), "rpm"); addAlias(Unit.ONE.divide(1000000), "ppm"); addAlias(Unit.ONE.divide(1000000000), "ppb"); addAlias(NonSI.GALLON_LIQUID_US.divide(NonSI.MINUTE), "gpm");
.divide(SI.SECOND), new Date()); bridge.addMetric(MetricName.parse("cow.bytes.total"), Semantics.COUNTER, NonSI.BYTE, 10000001); bridge.addMetric(MetricName.parse("cow.bytes.rate"), Semantics.INSTANT, NonSI.BYTE.times( 1024).divide(SI.SECOND), new Date()); bridge.addMetric(MetricName.parse("cow.bytes.chewtime"), Semantics.INSTANT, NonSI.HOUR .divide(NonSI.BYTE), 7); bridge.addMetric(MetricName.parse("cow.bytes.jawmotion"), Semantics.INSTANT, SI .KILO(SI.HERTZ), 0.5);
unit = f.unit.divide(g.unit);
return converted; case Acre: Unit<Area> acre = (Unit<Area>) NonSI.MILE.divide(8.0).times(NonSI.FOOT).times(66.0); converted = measure.doubleValue(acre); break;
@Test public void travelTimeMatrix() { final Point p0 = new Point(0, 0); final Point p1 = new Point(10, 0); final Point p2 = new Point(10, 10); final Point p3 = new Point(0, 10); // input in kilometers, output in minutes (rounded up), speed 40 km/h final Measure<Double, Velocity> speed1 = Measure.valueOf(40d, KILOMETERS_PER_HOUR); final int[][] matrix1 = ArraysSolvers .toTravelTimeMatrix(asList(p0, p1, p2, p3), KILOMETER, speed1, MINUTE, RoundingMode.CEILING); assertArrayEquals(new int[] {0, 15, 22, 15}, matrix1[0]); assertArrayEquals(new int[] {15, 0, 15, 22}, matrix1[1]); assertArrayEquals(new int[] {22, 15, 0, 15}, matrix1[2]); assertArrayEquals(new int[] {15, 22, 15, 0}, matrix1[3]); final Point p4 = new Point(11, 3); // input in meters, output in milliseconds (round down), speed .0699 // m/ms final Measure<Double, Velocity> speed2 = Measure.valueOf(.0699, new ProductUnit<Velocity>(METER.divide(MILLI(SECOND)))); final int[][] matrix2 = ArraysSolvers.toTravelTimeMatrix( asList(p0, p1, p2, p3, p4), METER, speed2, MILLI(SECOND), RoundingMode.FLOOR); assertArrayEquals(new int[] {0, 143, 202, 143, 163}, matrix2[0]); assertArrayEquals(new int[] {143, 0, 143, 202, 45}, matrix2[1]); assertArrayEquals(new int[] {202, 143, 0, 143, 101}, matrix2[2]); assertArrayEquals(new int[] {143, 202, 143, 0, 186}, matrix2[3]); assertArrayEquals(new int[] {163, 45, 101, 186, 0}, matrix2[4]); }