we are using the great unit-of-measurement framework to manage units dynamically. I have the requirement to filter a list of units by quantity. E.g. display all mass (tonne, kg ....). The list results in an generic capture list (which is not ideal - i know). The generic information does not exist at runtime (only at compile time). However for the unit interface an implementation exists to check the compatibility exists:
boolean isCompatible(Unit that);
@Test public void testCompatible_ByUnit(){ Unit<Mass> kilogram = Units.KILOGRAM; Unit<Mass> tonne = NonSI.TONNE; assertTrue(kilogram.isCompatible(tonne)); }
Is there any interface to check the compatiblity by quantity?
Non working example with quantity Mass.
@Test
public void testCompatible_FilterByQuantityAndCapture(){
Unit<?> kilogram = Units.KILOGRAM;
// wish: interface does not exist
assertTrue(kilogram.isCompatible(Mass.class));
}