Warning
|
This is not a proper documentation |
This library provides objects to manipulate value with unit. Instead of encoding the type of data and its unit in the variable name you can simply use the corresponding class.
For instance :
final Mass mass = Mass.TONNE.create(1);
final Length length = Length.METER.create(10_000);
final Time time = Time.parse("1 s");
final Speed speed = length.divide(time);
final Acceleration acceleration = speed.divide(time);
final Force force = acceleration.multiply(mass);
final Energy energy = length.multiply(force);
c
System.out.println("Energy value in J: "+energy.getValueInJoule());
final Volume volume = length.cubic();
final Density density = mass.divide(volume);
System.out.println("Density : "+density);
System.out.println("Density : "+density.inAdaptedUnit());
will output:
Energy value in J: 1.0E11 Density : 1.0E-9 kg.m^-3 Density : 0.001 mg.m^-3
Temperature are also available:
final Temperature vapor = Temperature.FAHRENHEIT_212;
final Temperature ice = Temperature.FAHRENHEIT_32;
final DeltaTemperature deltaVaporIce = vapor.subtract(ice);
final Temperature lowerThanIce = ice.subtract(DeltaTemperature.DELTA_CELSIUS.create(5));
System.out.printf("Ice in celsius: %s%n",ice.toCelsius().toPrettyString("%5.1f"));
System.out.printf("Vapor in celsius: %s%n",vapor.toCelsius().toPrettyString("%5.1f"));
System.out.printf("Delta Vapor Ice : %s%n",deltaVaporIce);
System.out.printf("Delta Vapor Ice : %s%n",deltaVaporIce.toDeltaFahrenheit());
System.out.printf("Ice minus 5°dC : %s%n",lowerThanIce.toFahrenheit().toPrettyString("%5.1f"));
System.out.printf("Ice minus 5°dC : %s%n",lowerThanIce.toCelsius().toPrettyString("%5.1f"));
will print:
Ice in celsius: 0.0 °C Vapor in celsius: 100.0 °C Delta Vapor Ice : 100.0 dK Delta Vapor Ice : 180.0 d°F Ice minus 5°dC : 23.0 °F Ice minus 5°dC : -5.0 °C
All classes specific to a quantity, unit or measurement are generated. The source of the generation is the xml file units.xml.
If you want to add a unit, you just need to modify this file and recompile the project.
You can use the XML schema units.xsd to ensure a correct edition of the units.xml file.