1 9 package javax.measure.units; 10 11 import javax.measure.converters.UnitConverter; 12 import javax.measure.quantities.Quantity; 13 14 27 public final class CompoundUnit<Q extends Quantity> extends DerivedUnit<Q> { 28 29 32 private final Unit<Q> _first; 33 34 37 private final Unit<Q> _next; 38 39 47 CompoundUnit(Unit<Q> first, Unit<Q> next) { 48 if (!first.getSystemUnit().equals(next.getSystemUnit())) 49 throw new IllegalArgumentException ( 50 "Both units do not have the same system unit"); 51 if (first instanceof CompoundUnit) { 52 CompoundUnit<Q> firstUnit = (CompoundUnit<Q>) first; 53 _first = firstUnit._first; 54 _next = new CompoundUnit<Q>(firstUnit._next, next); 55 } else { 56 _first = first; 57 _next = next; 58 } 59 } 60 61 66 public Unit<Q> getFirst() { 67 return _first; 68 } 69 70 75 public Unit<Q> getNext() { 76 return _next; 77 } 78 79 88 public boolean equals(Object that) { 89 if (this == that) 90 return true; 91 if (!(that instanceof CompoundUnit)) 92 return false; 93 CompoundUnit thatUnit = (CompoundUnit) that; 94 return this._first.equals(thatUnit._first) 95 && this._next.equals(thatUnit._next); 96 } 97 98 @Override 99 public int hashCode() { 100 return _first.hashCode() ^ _next.hashCode(); 101 } 102 103 @Override 104 public Unit<? super Q> getSystemUnit() { 105 return _first.getSystemUnit(); } 107 108 @Override 109 public UnitConverter toSystemUnit() { 110 return _first.toSystemUnit(); 111 } 112 113 private static final long serialVersionUID = 1L; 114 } | Popular Tags |