Пример #1
0
  public static void main(String[] args) {
    Unit<Mass> atomicMassUnit = UNIFIED_ATOMIC_MASS;
    System.out.println(
        atomicMassUnit + " (" + atomicMassUnit.getName() + "; " + atomicMassUnit.getSymbol() + ")");

    AbstractQuantity<Mass> mass = NumberQuantity.of(10, atomicMassUnit);
    System.out.println(mass);

    Quantity<Mass> massInKg = mass.to(KILOGRAM);
    System.out.println(massInKg);

    System.out.println(WATT_PER_STERADIAN);
    System.out.println(WATT_PER_STERADIAN_PER_SQUARE_METRE);

    Quantity<Angle> angle = Quantities.getQuantity(Math.PI, SI.RADIAN);
    System.out.println(angle.to(NonSI.DEGREE_ANGLE));
  }
Пример #2
0
  /** @param args */
  @SuppressWarnings({"unchecked", "rawtypes"})
  public static void main(String[] args) {
    Quantity<Length> length = Quantities.getQuantity(10, SI.METRE);
    // LengthAmount length = new LengthAmount(10, SI.KILOGRAM);
    // this won't work ;-)

    System.out.println(length);
    Unit<Length> lenUnit = length.getUnit();
    System.out.println(lenUnit);

    System.out.println(((AbstractQuantity) length).doubleValue(USCustomary.FOOT));
    // System.out.println(length.doubleValue(USCustomary.POUND));
    // this won't work either.
    // UnitConverter footConv = lenUnit.getConverterTo(USCustomary.INCH);
    System.out.print(((AbstractQuantity<Length>) length).doubleValue(USCustomary.INCH));
    System.out.println(" " + USCustomary.FOOT);

    Quantity<Mass> mass = Quantities.getQuantity(1000, SI.GRAM);
    Quantity<Mass> mass2 = NumberQuantity.of(1, SI.KILOGRAM);
    System.out.println(mass.equals(mass2));
  }
Пример #3
0
 @Test
 public void testOf() {
   AbstractQuantity<Pressure> pressure = NumberQuantity.of((double) 1, PASCAL);
   assertEquals(PASCAL, pressure.getUnit()); // TODO: Problem with kg...
 }