You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to use AlternateUnit for example AlternateUnit.of(MetricPrefix.NANO(Units.METRE), "nm", "Wavelength");
but this throws IllegalArgumentException: The parent unit: nm is not an unscaled SI unit.
Next attempt something like AlternateUnit.of(METRE, "λ", "Wavelength") + NANO(...) produces symbol nλ instead of nm, I think one can workaround this by mapping it to an own symbol.
What somehow worked was new TransformedUnit<>("nm", "Wavelength", Units.METRE, MultiplyConverter.ofRational(1, 1_000_000_000L)); but must manually duplicate the conversion factor that MetricPrefix.NANO(METRE) already defines.
A similar problem arise for example if one want to have a Distance in km to be distinguishable from a Length in km, so my question is what is the "standard way" to archive such kind of "alias" of a unit?
I find it sometimes hard to get how to use the API for such cases, is there some official documentation that describes all the differences between when to use BaseUnit / AlternateUnit / TransformedUnit / ... ?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I tried to use
AlternateUnitfor exampleAlternateUnit.of(MetricPrefix.NANO(Units.METRE), "nm", "Wavelength");but this throws
IllegalArgumentException: The parent unit: nm is not an unscaled SI unit.Next attempt something like
AlternateUnit.of(METRE, "λ", "Wavelength")+NANO(...)produces symbolnλinstead ofnm, I think one can workaround this by mapping it to an own symbol.What somehow worked was
new TransformedUnit<>("nm", "Wavelength", Units.METRE, MultiplyConverter.ofRational(1, 1_000_000_000L));but must manually duplicate the conversion factor thatMetricPrefix.NANO(METRE)already defines.A similar problem arise for example if one want to have a
Distance in kmto be distinguishable from aLength in km, so my question is what is the "standard way" to archive such kind of "alias" of a unit?I find it sometimes hard to get how to use the API for such cases, is there some official documentation that describes all the differences between when to use
BaseUnit/AlternateUnit/TransformedUnit/ ... ?Beta Was this translation helpful? Give feedback.
All reactions