Convert value from unit to this unit (if conpatible) @param value value to convert @param unit unit of value @return value converted to this unit
(final double value, final Unit unit)
| 151 | * @return value converted to this unit |
| 152 | */ |
| 153 | public double convert(final double value, final Unit unit) { |
| 154 | if (unit == this) { |
| 155 | return value; |
| 156 | } |
| 157 | if (!isCompatible(unit)) { |
| 158 | throw new IllegalArgumentException("unit " + name + " is incompatible with unit " + unit.name); |
| 159 | } |
| 160 | return value * unit.getScale() / scale; |
| 161 | } |
| 162 | |
| 163 | public boolean isPrimary() { |
| 164 | return primary == this; |
no test coverage detected