1 9 package javax.measure.units; 10 11 import javax.measure.converters.UnitConverter; 12 import javax.measure.quantities.Quantity; 13 14 36 public class BaseUnit<Q extends Quantity> extends Unit<Q> { 37 38 41 private final String _symbol; 42 43 50 public BaseUnit(String symbol) { 51 _symbol = symbol; 52 synchronized (Unit.SYMBOL_TO_UNIT) { 54 Unit unit = Unit.SYMBOL_TO_UNIT.get(symbol); 55 if (unit == null) { 56 Unit.SYMBOL_TO_UNIT.put(symbol, this); 57 return; 58 } 59 if (!(unit instanceof BaseUnit)) 60 throw new IllegalArgumentException ("Symbol " + symbol 61 + " is associated to a different unit"); 62 } 63 } 64 65 70 public final String getSymbol() { 71 return _symbol; 72 } 73 74 83 public boolean equals(Object that) { 84 if (this == that) 85 return true; 86 if (!(that instanceof BaseUnit)) 87 return false; 88 BaseUnit thatUnit = (BaseUnit) that; 89 return this._symbol.equals(thatUnit._symbol); 90 } 91 92 @Override 93 public int hashCode() { 94 return _symbol.hashCode(); 95 } 96 97 @Override 98 public Unit<? super Q> getSystemUnit() { 99 return this; 100 } 101 102 @Override 103 public UnitConverter toSystemUnit() { 104 return UnitConverter.IDENTITY; 105 } 106 107 private static final long serialVersionUID = 1L; 108 } | Popular Tags |