Esempio n. 1
0
 // //////////////
 // Formatting //
 // //////////////
 public Appendable format(final Unit<?> unit, final Appendable appendable) throws IOException {
   CharSequence symbol;
   //      CharSequence annotation = null;
   //      if (unit instanceof AnnotatedUnit<?>) {
   //          AnnotatedUnit<?> annotatedUnit = (AnnotatedUnit<?>) unit;
   //          unit = annotatedUnit.getActualUnit();
   //          annotation = annotatedUnit.getAnnotation();
   //      }
   String mapSymbol = symbolMap.get(unit);
   if (mapSymbol != null) {
     symbol = mapSymbol;
   } else {
     throw new IllegalArgumentException(
         "Symbol mapping for unit of type "
             + //$NON-NLS-1$
             unit.getClass().getName()
             + " has not been set "
             + //$NON-NLS-1$
             "(see UnitFormat.SymbolMap)"); //$NON-NLS-1$
   }
   appendable.append(symbol);
   //      if (annotation != null && annotation.length() > 0) {
   //          appendAnnotation(unit, symbol, annotation, appendable);
   //      }
   return appendable;
 }
Esempio n. 2
0
 @Override
 public UnitConverter getSystemConverter() {
   if (actualUnit instanceof AbstractUnit) {
     return ((AbstractUnit<?>) actualUnit).getSystemConverter();
   } else {
     throw new ClassCastException("Unknown type " + actualUnit.getClass());
   }
 }
Esempio n. 3
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));
  }
Esempio n. 4
0
 @Override
 public Map<? extends Unit<?>, Integer> getProductUnits() {
   return actualUnit.getProductUnits();
 }
Esempio n. 5
0
 @Override
 public String getSymbol() {
   return actualUnit.getSymbol();
 }
Esempio n. 6
0
 @Override
 public int hashCode() {
   return actualUnit.hashCode() + annotation.hashCode();
 }
Esempio n. 7
0
 @Override
 public Dimension getDimension() {
   return actualUnit.getDimension();
 }
Esempio n. 8
0
 @Override
 public AbstractUnit<Q> toSystemUnit() {
   return (AbstractUnit<Q>) actualUnit.getSystemUnit();
 }