If you look for something simple, you can check out my project.
I have created an opensource Unitility for working with physical quantities and units of measurements including easy conversion between them. Example of usage:
// Creating temperature instance of specified units
Temperature temperature = Temperature.ofCelsius(20.5); // {20.50 °C}
// Getting converted value for calculations
double valueInCelsius = temperature.getInCelsius(); // 20.50 °C
double valueInFahrenheits = temperature.getInFahrenheits(); // 68.90 °F
// Checking property current unit, value, and value in base unit
TemperatureUnit unit = temperature.getUnit(); // CELSIUS
TemperatureUnit baseUnit = unit.getBaseUnit(); // KELVIN
// Changing property unit and converting back to base unit
Temperature tempInFahrenheits = temperature.toUnit(TemperatureUnits.FAHRENHEIT);
Temperature tempInKelvins = temperature.toBaseUnit();
Additionally, logical and basic math operations are supported within quantities of the same type:
// Logic operation example:
Temperature smallerTemp = Temperature.ofCelsius(-20.0);
Temperature greaterTemp = Temperature.ofCelsius(0.0);
smallerTemp.isLowerThan(greaterTemp); // true
greaterTemp.isGreaterThan(smallerTemp); // true
// Math operation example:
Temperature sourceTemperature = Temperature.ofCelsius(20);
Temperature temperatureToAdd = Temperature.ofKelvins(293.15);
Temperature actualTemperature = sourceTemperature.add(temperatureToAdd); // {40°C}
Maybe this will be helpful if you are looking for something simple. It supports a selection of most typical physical quantities and its units for SI and IMPERIAL units.
- If you need any specific unit or quantity to be added - just let me know.
- I have provided modules for Spring and Quarkus support to preconfigure object mappers for easier use in web applications,
Maven repository: https://mvnrepository.com/artifact/com.synerset/unitility-core
I hope this helps.