1 9 package javax.measure.units; 10 11 import javax.measure.converters.UnitConverter; 12 import javax.measure.quantities.Quantity; 13 14 40 public final class TransformedUnit<Q extends Quantity> extends DerivedUnit<Q> { 41 42 45 private final Unit<Q> _parentUnit; 46 47 50 private final UnitConverter _toParentUnit; 51 52 61 TransformedUnit(Unit<Q> parentUnit, UnitConverter toParentUnit) { 62 if (toParentUnit == UnitConverter.IDENTITY) 63 throw new IllegalArgumentException ("Identity not allowed"); 64 _parentUnit = parentUnit; 65 _toParentUnit = toParentUnit; 66 } 67 68 74 public Unit<Q> getParentUnit() { 75 return _parentUnit; 76 } 77 78 83 public UnitConverter toParentUnit() { 84 return _toParentUnit; 85 } 86 87 96 public boolean equals(Object that) { 97 if (this == that) return true; 98 if (!(that instanceof TransformedUnit)) return false; 99 TransformedUnit thatUnit = (TransformedUnit) that; 100 return this._parentUnit.equals(thatUnit._parentUnit) && 101 this._toParentUnit.equals(thatUnit._toParentUnit); 102 } 103 104 public int hashCode() { 106 return _parentUnit.hashCode() + _toParentUnit.hashCode(); 107 } 108 109 public Unit<? super Q> getSystemUnit() { 111 return _parentUnit.getSystemUnit(); 112 } 113 114 public UnitConverter toSystemUnit() { 116 return _parentUnit.toSystemUnit().concatenate(_toParentUnit); 117 } 118 119 private static final long serialVersionUID = 1L; 120 121 } | Popular Tags |