unitsofmeasurement / indriya

JSR 385 - Reference Implementation
Other
122 stars 42 forks source link

Improvement: Provide a mechanism to get list of all Dimension for given quantity #224

Open cdwivedi opened 5 years ago

cdwivedi commented 5 years ago

There should be mechanism to get a list of all valid Dimension for a Quantity LENGTH and other quantity too.

keilw commented 5 years ago

It could potentially be something on the SPI, we'll check it but probably for a new version.

keilw commented 4 years ago

I think this one asks the wrong question, or do you have a code example (at least a snippet) how this would be required?

We have a SystemOfUnits method getUnits() that takes a Dimension, e.g. sou.getUnits(UnitDimension.TIME) returning 7 units in the RI unit system. On the other hand there's a getUnit() method that takes the class of a Quantity type like Length returning the system-wide base unit for that quantity type: sou.getUnit(Length.class).

These could be combined:

        Unit<?> result = sou.getUnit(Length.class);
        Dimension dim = result.getDimension();
        Set<? extends Unit<?>> units = sou.getUnits(dim);        

So you can have multiple units for a given dimension, a convenience method returning the set of units would be no big deal, but there is just one dimension for a given quantity type like Volume: "[L]³". There are no multiple dimensions. You can decompose the dimension via getBaseDimensions().

Does this help you @cdwivedi, or could you show, why you think there would be multiple dimensions for a single quantity type? The mentioned convenience method is easy to apply, I am not sure, if we should add it to the API at this point, because the MR1 is planned in less than a month, but adding it to Indriya would not be a problem.