From 0f65f56f3d0d0f45212e9ab525ba351434ecf8e1 Mon Sep 17 00:00:00 2001 From: Piotr Jazdzyk Date: Sat, 26 Aug 2023 12:03:13 +0200 Subject: [PATCH 1/2] feat(SNSUN-22): replaced 'to' methods by getIn methods, for easier double values extraction during calculations. --- pom.xml | 3 +- readme.md | 26 +++++-- .../unitsystem/PhysicalQuantity.java | 43 ++++++++++-- .../synerset/unitility/unitsystem/Unit.java | 6 +- .../unitility/unitsystem/common/Angle.java | 32 ++++----- .../unitsystem/common/AngleUnits.java | 4 +- .../unitility/unitsystem/common/Area.java | 69 +++++++++---------- .../unitsystem/common/AreaUnits.java | 4 +- .../unitility/unitsystem/common/Distance.java | 52 +++++++------- .../unitsystem/common/DistanceUnits.java | 4 +- .../unitility/unitsystem/common/Mass.java | 50 +++++++------- .../unitsystem/common/MassUnits.java | 4 +- .../unitility/unitsystem/common/Velocity.java | 56 +++++++-------- .../unitsystem/common/VelocityUnits.java | 4 +- .../unitility/unitsystem/common/Volume.java | 56 +++++++-------- .../unitsystem/common/VolumeUnits.java | 4 +- .../dimensionless/BypassFactor.java | 8 +++ .../dimensionless/BypassFactorUnits.java | 4 +- .../dimensionless/GrashofNumber.java | 8 +++ .../dimensionless/GrashofNumberUnits.java | 4 +- .../dimensionless/PrandtlNumber.java | 8 +++ .../dimensionless/PrandtlNumberUnits.java | 4 +- .../dimensionless/ReynoldsNumber.java | 8 +++ .../dimensionless/ReynoldsNumberUnits.java | 4 +- .../UnitSystemArgumentException.java | 9 +-- .../unitility/unitsystem/flows/MassFlow.java | 40 +++++------ .../unitsystem/flows/MassFlowUnits.java | 4 +- .../unitsystem/flows/VolumetricFlow.java | 67 ++++++++---------- .../unitsystem/flows/VolumetricFlowUnits.java | 4 +- .../unitsystem/humidity/HumidityRatio.java | 32 ++++----- .../humidity/HumidityRatioUnits.java | 6 +- .../unitsystem/humidity/RelativeHumidity.java | 32 ++++----- .../humidity/RelativeHumidityUnits.java | 6 +- .../unitsystem/mechanical/Force.java | 48 ++++++------- .../unitsystem/mechanical/ForceUnits.java | 4 +- .../unitsystem/mechanical/Momentum.java | 36 +++++----- .../unitsystem/mechanical/MomentumUnits.java | 4 +- .../unitsystem/mechanical/Torque.java | 44 ++++++------ .../unitsystem/mechanical/TorqueUnits.java | 4 +- .../unitsystem/thermodynamic/Density.java | 32 +++++---- .../thermodynamic/DensityUnits.java | 6 +- .../thermodynamic/DynamicViscosity.java | 36 +++++----- .../thermodynamic/DynamicViscosityUnits.java | 4 +- .../unitsystem/thermodynamic/Energy.java | 67 ++++++++---------- .../unitsystem/thermodynamic/EnergyUnits.java | 4 +- .../thermodynamic/KinematicViscosity.java | 32 ++++----- .../KinematicViscosityUnits.java | 4 +- .../unitsystem/thermodynamic/Power.java | 51 ++++++-------- .../unitsystem/thermodynamic/PowerUnits.java | 4 +- .../unitsystem/thermodynamic/Pressure.java | 53 +++++++------- .../thermodynamic/PressureUnits.java | 4 +- .../thermodynamic/SpecificEnthalpy.java | 36 +++++----- .../thermodynamic/SpecificEnthalpyUnits.java | 4 +- .../thermodynamic/SpecificHeat.java | 36 +++++----- .../thermodynamic/SpecificHeatUnits.java | 4 +- .../unitsystem/thermodynamic/Temperature.java | 43 +++++------- .../thermodynamic/TemperatureUnits.java | 6 +- .../thermodynamic/ThermalConductivity.java | 36 +++++----- .../ThermalConductivityUnits.java | 4 +- .../thermodynamic/ThermalDiffusivity.java | 32 ++++----- .../ThermalDiffusivityUnits.java | 4 +- .../unitsystem/PhysicalQuantityTest.java | 60 +++++++++++++++- .../unitsystem/common/AngleTest.java | 10 ++- .../unitility/unitsystem/common/AreaTest.java | 44 +++++++++--- .../unitsystem/common/DistanceTest.java | 16 ++++- .../unitility/unitsystem/common/MassTest.java | 14 +++- .../unitsystem/common/VelocityTest.java | 30 ++++++-- .../unitsystem/common/VolumeTest.java | 38 +++++++--- .../dimensionless/BypassFactorTest.java | 27 ++++++++ .../dimensionless/GrashofNumberTest.java | 2 + .../dimensionless/PrandtlNumberTest.java | 2 + .../dimensionless/ReynoldsNumberTest.java | 2 + .../unitsystem/flows/MassFlowTest.java | 24 ++++--- .../unitsystem/flows/VolumetricFlowTest.java | 34 ++++++--- .../humidity/HumidityRatioTest.java | 5 ++ .../humidity/RelativeHumidityTest.java | 8 ++- .../unitsystem/mechanical/ForceTest.java | 29 +++++--- .../unitsystem/mechanical/MomentumTest.java | 10 ++- .../unitsystem/mechanical/TorqueTest.java | 18 +++-- .../unitsystem/thermodynamic/DensityTest.java | 14 ++-- .../thermodynamic/DynamicViscosityTest.java | 14 ++-- .../unitsystem/thermodynamic/EnergyTest.java | 47 +++++++++---- .../thermodynamic/KinematicViscosityTest.java | 8 ++- .../unitsystem/thermodynamic/PowerTest.java | 22 ++++-- .../thermodynamic/PressureTest.java | 38 ++++++---- .../thermodynamic/SpecificEnthalpyTest.java | 14 ++-- .../thermodynamic/SpecificHeatTest.java | 14 ++-- .../thermodynamic/TemperatureTest.java | 8 ++- .../ThermalConductivityTest.java | 14 ++-- .../thermodynamic/ThermalDiffusivityTest.java | 4 ++ 90 files changed, 1123 insertions(+), 754 deletions(-) create mode 100644 src/test/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactorTest.java diff --git a/pom.xml b/pom.xml index 921dbc6..32e6066 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.synerset unitility - 1.0.2 + 1.1.0 jar Unitility @@ -14,7 +14,6 @@ Unitility provides value objects that combine numerical values with their corresponding units, allowing developers to easily perform accurate and efficient conversions between different units. With a wide range of value objects that represent commonly used physical quantities, this solution is built using plain Java for optimal speed and lightweight functionality. - This solution offers quick and easy usage in any project, without heavy frameworks or external libraries. https://github.com/pjazdzyk/unitility diff --git a/readme.md b/readme.md index 95590f2..9112db4 100644 --- a/readme.md +++ b/readme.md @@ -19,13 +19,13 @@ or external libraries.
### INSTALLATION Just copy Maven dependency provided below to your pom.xml file, and you are ready to go. For other package managers, check maven central repository: -[UNITILITY](https://search.maven.org/artifact/com.synerset/unitility/1.0.2/jar?eh=). +[UNITILITY](https://search.maven.org/artifact/com.synerset/unitility/1.1.0/jar?eh=). ```xml com.synerset unitility - 1.0.2 + 1.1.0 ``` ## Tech @@ -45,14 +45,25 @@ CI/CD:
## Examples **Creating quantities:**
-Below is a simple example how to work with units and convert to another type of unit: +Below is a simple example how to work with units and convert property from one unit to another or to convert as doubles for further calculations: ```java -Temperature tempInCelsius = Temperature.ofCelsius(20.5); // 20.5 °C -Temperature tempInKelvin = tempInCelsius.toKelvin(); // 293.65 K -Temperature temInFahrenheit = tempInKelvin.toFahrenheit(); // 68.9 °F +// 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 valueInKelvins = temperature.getInKelvins(); // 293.65 K +double valueInFahrenheits = temperature.getInFahrenheits(); // 68.90 °F +// Checking property current unit, value, and value in base unit +Unit unit = temperature.getUnit(); // CELSIUS +Unit baseUnit = unit.getBaseUnit(); // KELVIN +double valueInUnit = temperature.getValue(); // 20.50 °C +double valueInBaseUnits = temperature.getBaseValue(); // 293.65 K +// Changing property unit and converting back to base unit +Temperature tempInFahrenheits = temperature.toUnit(TemperatureUnits.FAHRENHEIT); // {68.90 °F} +Temperature tempInKelvins = temperature.toBaseUnit(); // {293.65 K} ``` All quantities have smart toStringWithRelevantDigits() method, which will always adjust values decimal precision to capture by default specified relevant digits depending on your unit type and its value. -This way you have guaranteed an elegant output without any additional effort of reformatting. Values will be rounded up using HALF_UP approach. +This way you have guaranteed an elegant output without any additional effort of reformatting. Values will be rounded up using HALF_EVEN approach. ```java Distance bigDistance = Distance.ofMeters(10); @@ -67,6 +78,7 @@ This project has been implemented in a functional manner using io.vavr library: Since version **1.0.2** [Unitility](https://github.com/pjazdzyk/unitility) supports basic transformation and logic operations. **Transformations:**
+The choice of the developer determines whether calculations are performed using double values or with physical quantity objects through the available transformation methods: * adding or subtracting quantities of the same type: ```java Temperature sourceTemperature = Temperature.ofCelsius(20); diff --git a/src/main/java/com/synerset/unitility/unitsystem/PhysicalQuantity.java b/src/main/java/com/synerset/unitility/unitsystem/PhysicalQuantity.java index e4d22f5..2b512ef 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/PhysicalQuantity.java +++ b/src/main/java/com/synerset/unitility/unitsystem/PhysicalQuantity.java @@ -10,7 +10,7 @@ * * @param The type of quantity, used to maintain type safety. */ -public interface PhysicalQuantity { +public interface PhysicalQuantity extends Comparable> { /** * Get the value of the physical quantity. @@ -19,6 +19,13 @@ public interface PhysicalQuantity { */ double getValue(); + /** + * Get the value of the physical quantity in its base unit. + * + * @return The base value of the physical quantity. + */ + double getBaseValue(); + /** * Get the unit associated with the physical quantity. * @@ -68,7 +75,17 @@ default String toStringWithRelevantDigits(int relevantDigits) { return ValueFormatter.formatDoubleToRelevantDigits(getValue(), relevantDigits) + " " + getUnit().getSymbol(); } - // Comparing methods + /** + * Returns a converted value to target unit of the same type. + * + * @param targetUnit TThe target unit for conversion. + * @return A value converted to target unit. + */ + default double getIn(Unit targetUnit) { + return targetUnit.fromValueInBaseUnit(getBaseValue()); + } + + // Logical operations /** * Check if the physical quantity is greater than another quantity @@ -194,7 +211,7 @@ default boolean isZero() { return getValue() == 0; } - // Transformation methods + // Transformations /** * Add a constant value to the physical quantity. @@ -286,7 +303,7 @@ default double multiply(PhysicalQuantity inputQuantity) { */ default PhysicalQuantity divide(double value) { if (value == 0) { - throw new UnitSystemArgumentException("Divider value cannot be zero."); + throw new UnitSystemArgumentException("Division by zero is not allowed. Please provide a non-zero divider value."); } double newValue = getValue() / value; return createNewWithValue(newValue); @@ -306,4 +323,20 @@ default double divide(PhysicalQuantity inputQuantity) { } return thisValue / inputQuantity.getValue(); } -} + + @Override + default int compareTo(PhysicalQuantity other) { + if (this == other) { + return 0; + } + // Convert both quantities to the same unit for comparison + PhysicalQuantity thisInOtherUnit = this.toUnit(other.getUnit()); + + // Compare the values of the two quantities + double thisValue = thisInOtherUnit.getValue(); + double otherValue = other.getValue(); + + return Double.compare(thisValue, otherValue); + } + +} \ No newline at end of file diff --git a/src/main/java/com/synerset/unitility/unitsystem/Unit.java b/src/main/java/com/synerset/unitility/unitsystem/Unit.java index cab3378..5ec927c 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/Unit.java +++ b/src/main/java/com/synerset/unitility/unitsystem/Unit.java @@ -1,7 +1,7 @@ /** * An interface representing a unit of measurement in a unit system. * - * @param The quantity type associated with the unit (e.g., Length, Mass, Time). + * @param The quantity type associated with the unit (e.g., Length, Mass, Time). It is used to ensure proper unit type usage in physical quantities. */ package com.synerset.unitility.unitsystem; @@ -26,7 +26,7 @@ public interface Unit { * @param valueInThisUnit The value to be converted, in this unit. * @return The equivalent value in the base unit. */ - double toBaseUnit(double valueInThisUnit); + double toValueInBaseUnit(double valueInThisUnit); /** * Convert a value from the base unit to the equivalent value in this unit. @@ -34,5 +34,5 @@ public interface Unit { * @param valueInBaseUnit The value to be converted, in the base unit. * @return The equivalent value in this unit. */ - double fromBaseToThisUnit(double valueInBaseUnit); + double fromValueInBaseUnit(double valueInBaseUnit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/Angle.java b/src/main/java/com/synerset/unitility/unitsystem/common/Angle.java index bd20c01..7a4a635 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/Angle.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/Angle.java @@ -9,11 +9,13 @@ public final class Angle implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private Angle(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -21,6 +23,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -28,14 +35,14 @@ public Unit getUnit() { @Override public Angle toBaseUnit() { - double degrees = unit.toBaseUnit(value); + double degrees = unit.toValueInBaseUnit(value); return Angle.of(degrees, AngleUnits.DEGREES); } @Override public Angle toUnit(Unit targetUnit) { - double valueInDegrees = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInDegrees); + double valueInDegrees = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInDegrees); return Angle.of(valueInTargetUnit, targetUnit); } @@ -44,21 +51,13 @@ public Angle createNewWithValue(double value) { return Angle.of(value, unit); } - // Custom value getters - public double getValueOfDegrees(){ - if(unit == AngleUnits.RADIANS){ - return value; - } - return toUnit(AngleUnits.RADIANS).getValue(); - } - - // Custom converter methods for most popular units - public Angle toRadians() { - return toUnit(AngleUnits.RADIANS); + // Convert to target unit + public double getInRadians() { + return getIn(AngleUnits.RADIANS); } - public Angle toDegrees() { - return toUnit(AngleUnits.DEGREES); + public double getInDegrees() { + return getIn(AngleUnits.DEGREES); } @Override @@ -85,6 +84,7 @@ public String toStringWithRelevantDigits(int relevantDigits) { return ValueFormatter.formatDoubleToRelevantDigits(value, relevantDigits) + separator + unit.getSymbol(); } + // Static factory methods public static Angle of(double value, Unit unit) { return new Angle(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/AngleUnits.java b/src/main/java/com/synerset/unitility/unitsystem/common/AngleUnits.java index 15e5b74..b8f5d20 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/AngleUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/AngleUnits.java @@ -30,12 +30,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/Area.java b/src/main/java/com/synerset/unitility/unitsystem/common/Area.java index bd6171c..bce44c7 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/Area.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/Area.java @@ -8,13 +8,14 @@ public final class Area implements PhysicalQuantity { public static final Area PHYSICAL_MIN_LIMIT = Area.ofSquareMeters(0); - private final double value; + private final double baseValue; private final Unit unit; private Area(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -22,6 +23,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -29,14 +35,14 @@ public Unit getUnit() { @Override public Area toBaseUnit() { - double valueInSquareMeters = unit.toBaseUnit(value); + double valueInSquareMeters = unit.toValueInBaseUnit(value); return Area.of(valueInSquareMeters, AreaUnits.SQUARE_METER); } @Override public Area toUnit(Unit targetUnit) { - double valueInSquareMeters = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInSquareMeters); + double valueInSquareMeters = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInSquareMeters); return Area.of(valueInTargetUnit, targetUnit); } @@ -45,57 +51,49 @@ public Area createNewWithValue(double value) { return Area.of(value, unit); } - // Custom value getters - public double getValueOfSquareMeters(){ - if(unit == AreaUnits.SQUARE_METER){ - return value; - } - return toUnit(AreaUnits.SQUARE_METER).getValue(); - } - - // Custom converter methods, for most popular units - public Area toSquareMeters() { - return toUnit(AreaUnits.SQUARE_METER); + // Convert to target unit + public double getInSquareMeters() { + return getIn(AreaUnits.SQUARE_METER); } - public Area toSquareKilometers() { - return toUnit(AreaUnits.SQUARE_KILOMETER); + public double getInSquareKilometers() { + return getIn(AreaUnits.SQUARE_KILOMETER); } - public Area toSquareCentimeters() { - return toUnit(AreaUnits.SQUARE_CENTIMETER); + public double getInSquareCentimeters() { + return getIn(AreaUnits.SQUARE_CENTIMETER); } - public Area toSquareMillimeters() { - return toUnit(AreaUnits.SQUARE_MILLIMETER); + public double getInSquareMillimeters() { + return getIn(AreaUnits.SQUARE_MILLIMETER); } - public Area toAres() { - return toUnit(AreaUnits.ARE); + public double getInAres() { + return getIn(AreaUnits.ARE); } - public Area toHectares() { - return toUnit(AreaUnits.HECTARE); + public double getInHectares() { + return getIn(AreaUnits.HECTARE); } - public Area toSquareInches() { - return toUnit(AreaUnits.SQUARE_INCH); + public double getInSquareInches() { + return getIn(AreaUnits.SQUARE_INCH); } - public Area toSquareFeet() { - return toUnit(AreaUnits.SQUARE_FOOT); + public double getInSquareFeet() { + return getIn(AreaUnits.SQUARE_FOOT); } - public Area toSquareYards() { - return toUnit(AreaUnits.SQUARE_YARD); + public double getInSquareYards() { + return getIn(AreaUnits.SQUARE_YARD); } - public Area toAcres() { - return toUnit(AreaUnits.ACRE); + public double getInAcres() { + return getIn(AreaUnits.ACRE); } - public Area toSquareMiles() { - return toUnit(AreaUnits.SQUARE_MILE); + public double getInSquareMiles() { + return getIn(AreaUnits.SQUARE_MILE); } @Override @@ -116,6 +114,7 @@ public String toString() { return "Area{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static Area of(double value, Unit unit) { return new Area(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/AreaUnits.java b/src/main/java/com/synerset/unitility/unitsystem/common/AreaUnits.java index d29caa2..687f492 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/AreaUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/AreaUnits.java @@ -39,12 +39,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/Distance.java b/src/main/java/com/synerset/unitility/unitsystem/common/Distance.java index 7bcacc0..f54bdf5 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/Distance.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/Distance.java @@ -8,11 +8,13 @@ public final class Distance implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private Distance(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -20,6 +22,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -27,14 +34,14 @@ public Unit getUnit() { @Override public Distance toBaseUnit() { - double valueInMeters = unit.toBaseUnit(value); + double valueInMeters = unit.toValueInBaseUnit(value); return Distance.of(valueInMeters, DistanceUnits.METER); } @Override public Distance toUnit(Unit targetUnit) { - double valueInMeters = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInMeters); + double valueInMeters = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInMeters); return Distance.of(valueInTargetUnit, targetUnit); } @@ -43,41 +50,33 @@ public Distance createNewWithValue(double value) { return Distance.of(value, unit); } - // Custom value getters - public double getValueOfMeters(){ - if(unit == DistanceUnits.METER){ - return value; - } - return toUnit(DistanceUnits.METER).getValue(); - } - - // Custom converter methods for most popular units - public Distance toMeter(){ - return toUnit(DistanceUnits.METER); + // Convert to target unit + public double getInMeters() { + return getIn(DistanceUnits.METER); } - public Distance toCentimeter(){ - return toUnit(DistanceUnits.CENTIMETER); + public double getInCentimeters() { + return getIn(DistanceUnits.CENTIMETER); } - public Distance toMillimeter(){ - return toUnit(DistanceUnits.MILLIMETER); + public double getInMillimeters() { + return getIn(DistanceUnits.MILLIMETER); } - public Distance toKilometer(){ - return toUnit(DistanceUnits.KILOMETER); + public double getInKilometers() { + return getIn(DistanceUnits.KILOMETER); } - public Distance toMile(){ - return toUnit(DistanceUnits.MILE); + public double getInMiles() { + return getIn(DistanceUnits.MILE); } - public Distance toFeet(){ - return toUnit(DistanceUnits.FEET); + public double getInFeet() { + return getIn(DistanceUnits.FEET); } - public Distance toInch(){ - return toUnit(DistanceUnits.INCH); + public double getInInches() { + return getIn(DistanceUnits.INCH); } @Override @@ -98,6 +97,7 @@ public String toString() { return "Distance{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static Distance of(double value, Unit unit) { return new Distance(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/DistanceUnits.java b/src/main/java/com/synerset/unitility/unitsystem/common/DistanceUnits.java index f27d61d..e04d7c1 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/DistanceUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/DistanceUnits.java @@ -35,12 +35,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/Mass.java b/src/main/java/com/synerset/unitility/unitsystem/common/Mass.java index dde1b41..51b1afd 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/Mass.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/Mass.java @@ -8,11 +8,13 @@ public final class Mass implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private Mass(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -20,6 +22,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -27,14 +34,14 @@ public Unit getUnit() { @Override public Mass toBaseUnit() { - double valueInKilogram = unit.toBaseUnit(value); + double valueInKilogram = unit.toValueInBaseUnit(value); return Mass.of(valueInKilogram, MassUnits.KILOGRAM); } @Override public Mass toUnit(Unit targetUnit) { - double valueInKilogram = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInKilogram); + double valueInKilogram = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInKilogram); return Mass.of(valueInTargetUnit, targetUnit); } @@ -43,37 +50,29 @@ public Mass createNewWithValue(double value) { return Mass.of(value, unit); } - // Custom value getters - public double getValueOfKilograms(){ - if(unit == MassUnits.KILOGRAM){ - return value; - } - return toUnit(MassUnits.KILOGRAM).getValue(); - } - - // Custom converter methods, for most popular units - public Mass toKilogram(){ - return toUnit(MassUnits.KILOGRAM); + // Convert to target unit + public double getInKilograms() { + return getIn(MassUnits.KILOGRAM); } - public Mass toGram(){ - return toUnit(MassUnits.GRAM); + public double getIntoGrams() { + return getIn(MassUnits.GRAM); } - public Mass toMiligram(){ - return toUnit(MassUnits.MILLIGRAM); + public double getInMilligrams() { + return getIn(MassUnits.MILLIGRAM); } - public Mass toTonneSI(){ - return toUnit(MassUnits.TONNE_SI); + public double getIntoTonnesSI() { + return getIn(MassUnits.TONNE_SI); } - public Mass toOunce(){ - return toUnit(MassUnits.OUNCE); + public double getIntoOunces() { + return getIn(MassUnits.OUNCE); } - public Mass toPound(){ - return toUnit(MassUnits.POUND); + public double getInPounds() { + return getIn(MassUnits.POUND); } @Override @@ -94,6 +93,7 @@ public String toString() { return "Mass{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static Mass of(double value, Unit unit) { return new Mass(value, unit); } @@ -106,7 +106,7 @@ public static Mass ofGrams(double value) { return new Mass(value, MassUnits.GRAM); } - public static Mass ofMiligrams(double value) { + public static Mass ofMilligrams(double value) { return new Mass(value, MassUnits.MILLIGRAM); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/MassUnits.java b/src/main/java/com/synerset/unitility/unitsystem/common/MassUnits.java index a32e3f5..ed1b7c3 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/MassUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/MassUnits.java @@ -34,12 +34,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/Velocity.java b/src/main/java/com/synerset/unitility/unitsystem/common/Velocity.java index 788341e..c2888ce 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/Velocity.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/Velocity.java @@ -8,11 +8,13 @@ public final class Velocity implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private Velocity(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -20,6 +22,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -27,14 +34,14 @@ public Unit getUnit() { @Override public Velocity toBaseUnit() { - double valueInMetersPerSecond = unit.toBaseUnit(value); + double valueInMetersPerSecond = unit.toValueInBaseUnit(value); return Velocity.of(valueInMetersPerSecond, VelocityUnits.METER_PER_SECOND); } @Override public Velocity toUnit(Unit targetUnit) { - double valueInMetersPerSecond = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInMetersPerSecond); + double valueInMetersPerSecond = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInMetersPerSecond); return Velocity.of(valueInTargetUnit, targetUnit); } @@ -43,45 +50,37 @@ public Velocity createNewWithValue(double value) { return Velocity.of(value, unit); } - // Custom value getters - public double getValueOfMetersPerSecond() { - if (unit == VelocityUnits.METER_PER_SECOND) { - return value; - } - return toUnit(VelocityUnits.METER_PER_SECOND).getValue(); - } - - // Custom converter methods, for most popular units - public Velocity toMetersPerSecond() { - return toUnit(VelocityUnits.METER_PER_SECOND); + // Convert to target unit + public double toMetersPerSecond() { + return getIn(VelocityUnits.METER_PER_SECOND); } - public Velocity toCentimetersPerSecond() { - return toUnit(VelocityUnits.CENTIMETER_PER_SECOND); + public double toCentimetersPerSeconds() { + return getIn(VelocityUnits.CENTIMETER_PER_SECOND); } - public Velocity toKilometersPerHour() { - return toUnit(VelocityUnits.KILOMETER_PER_HOUR); + public double toKilometersPerHours() { + return getIn(VelocityUnits.KILOMETER_PER_HOUR); } - public Velocity toInchesPerSecond() { - return toUnit(VelocityUnits.INCH_PER_SECOND); + public double toInchesPerSeconds() { + return getIn(VelocityUnits.INCH_PER_SECOND); } - public Velocity toFeetPerSecond() { - return toUnit(VelocityUnits.FEET_PER_SECOND); + public double toFeetPerSeconds() { + return getIn(VelocityUnits.FEET_PER_SECOND); } - public Velocity toMilesPerHour() { - return toUnit(VelocityUnits.MILES_PER_HOUR); + public double toMilesPerHours() { + return getIn(VelocityUnits.MILES_PER_HOUR); } - public Velocity toKnots() { - return toUnit(VelocityUnits.KNOTS); + public double toKnots() { + return getIn(VelocityUnits.KNOTS); } - public Velocity toMach() { - return toUnit(VelocityUnits.MACH); + public double toMach() { + return getIn(VelocityUnits.MACH); } @Override @@ -102,6 +101,7 @@ public String toString() { return "Velocity{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static Velocity of(double value, Unit unit) { return new Velocity(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/VelocityUnits.java b/src/main/java/com/synerset/unitility/unitsystem/common/VelocityUnits.java index 3878bc2..3016045 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/VelocityUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/VelocityUnits.java @@ -36,12 +36,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/Volume.java b/src/main/java/com/synerset/unitility/unitsystem/common/Volume.java index 4b921ce..5518f2a 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/Volume.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/Volume.java @@ -7,11 +7,13 @@ public final class Volume implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private Volume(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -19,6 +21,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -26,14 +33,14 @@ public Unit getUnit() { @Override public Volume toBaseUnit() { - double valueInCubicMeter = unit.toBaseUnit(value); + double valueInCubicMeter = unit.toValueInBaseUnit(value); return Volume.of(valueInCubicMeter, VolumeUnits.CUBIC_METER); } @Override public Volume toUnit(Unit targetUnit) { - double valueInCubicMeter = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInCubicMeter); + double valueInCubicMeter = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInCubicMeter); return Volume.of(valueInTargetUnit, targetUnit); } @@ -42,45 +49,37 @@ public Volume createNewWithValue(double value) { return Volume.of(value, unit); } - // Custom value getters - public double getValueOfCubicMeters() { - if (unit == VolumeUnits.CUBIC_METER) { - return value; - } - return toUnit(VolumeUnits.CUBIC_METER).getValue(); - } - - // Custom converter methods, for most popular units - public Volume toCubicMeter() { - return toUnit(VolumeUnits.CUBIC_METER); + // Convert to target unit + public double getInCubicMeters() { + return getIn(VolumeUnits.CUBIC_METER); } - public Volume toLiter() { - return toUnit(VolumeUnits.LITER); + public double getInLiters() { + return getIn(VolumeUnits.LITER); } - public Volume toCubicCentimeter() { - return toUnit(VolumeUnits.CUBIC_CENTIMETER); + public double getInCubicCentimeters() { + return getIn(VolumeUnits.CUBIC_CENTIMETER); } - public Volume toHectoLiter() { - return toUnit(VolumeUnits.HECTOLITRE); + public double getInHectoLiters() { + return getIn(VolumeUnits.HECTOLITRE); } - public Volume toMilliLiter() { - return toUnit(VolumeUnits.MILLILITRE); + public double getInMilliLiters() { + return getIn(VolumeUnits.MILLILITRE); } - public Volume toOunce() { - return toUnit(VolumeUnits.OUNCE); + public double getInOunces() { + return getIn(VolumeUnits.OUNCE); } - public Volume toPint() { - return toUnit(VolumeUnits.PINT); + public double getInPints() { + return getIn(VolumeUnits.PINT); } - public Volume toGallon() { - return toUnit(VolumeUnits.GALLON); + public double getInGallons() { + return getIn(VolumeUnits.GALLON); } @Override @@ -101,6 +100,7 @@ public String toString() { return "Volume{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static Volume of(double value, Unit unit) { return new Volume(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/VolumeUnits.java b/src/main/java/com/synerset/unitility/unitsystem/common/VolumeUnits.java index a6bf6d4..38f8e5e 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/VolumeUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/VolumeUnits.java @@ -36,12 +36,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } diff --git a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactor.java b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactor.java index 5eefca4..3e01b74 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactor.java +++ b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactor.java @@ -11,11 +11,13 @@ public final class BypassFactor implements PhysicalQuantity { public static final BypassFactor BYPASS_MAX_VALUE = BypassFactor.of(1); private final double value; + private final double baseValue; private final Unit unit; private BypassFactor(double value) { this.value = value; this.unit = BypassFactorUnits.DIMENSIONLESS; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -23,6 +25,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -61,6 +68,7 @@ public int hashCode() { return Objects.hash(value); } + // Static factory methods public static BypassFactor of(double value) { return new BypassFactor(value); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactorUnits.java b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactorUnits.java index 473042d..3a7994c 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactorUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactorUnits.java @@ -29,12 +29,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } diff --git a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumber.java b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumber.java index a4afd07..c4dfdc4 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumber.java +++ b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumber.java @@ -7,11 +7,13 @@ public final class GrashofNumber implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private GrashofNumber(double value) { this.value = value; this.unit = GrashofNumberUnits.DIMENSIONLESS; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -19,6 +21,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -57,6 +64,7 @@ public int hashCode() { return Objects.hash(value); } + // Static factory methods public static GrashofNumber of(double value) { return new GrashofNumber(value); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumberUnits.java b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumberUnits.java index f4068ee..154bb00 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumberUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumberUnits.java @@ -29,12 +29,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } diff --git a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumber.java b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumber.java index 4aae65f..b3ef7cb 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumber.java +++ b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumber.java @@ -7,11 +7,13 @@ public final class PrandtlNumber implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private PrandtlNumber(double value) { this.value = value; this.unit = PrandtlNumberUnits.DIMENSIONLESS; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -19,6 +21,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -57,6 +64,7 @@ public int hashCode() { return Objects.hash(value); } + // Static factory methods public static PrandtlNumber of(double value) { return new PrandtlNumber(value); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumberUnits.java b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumberUnits.java index a4ac28b..14f2fb3 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumberUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumberUnits.java @@ -29,12 +29,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } diff --git a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumber.java b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumber.java index 4431043..c0d0a96 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumber.java +++ b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumber.java @@ -11,11 +11,13 @@ public final class ReynoldsNumber implements PhysicalQuantity { public static final ReynoldsNumber PLATE_TURBULENT_THRESHOLD = ReynoldsNumber.of(5 * 10E5); public static final ReynoldsNumber AERO_TURBULENT_THRESHOLD = ReynoldsNumber.of(2 * 10E6); private final double value; + private final double baseValue; private final Unit unit; private ReynoldsNumber(double value) { this.value = value; this.unit = ReynoldsNumberUnits.DIMENSIONLESS; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -23,6 +25,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -61,6 +68,7 @@ public int hashCode() { return Objects.hash(value); } + // Static factory methods public static ReynoldsNumber of(double value) { return new ReynoldsNumber(value); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumberUnits.java b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumberUnits.java index 96e0ffc..13fa659 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumberUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumberUnits.java @@ -29,12 +29,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } diff --git a/src/main/java/com/synerset/unitility/unitsystem/exceptions/UnitSystemArgumentException.java b/src/main/java/com/synerset/unitility/unitsystem/exceptions/UnitSystemArgumentException.java index 1d73d7c..8e0468b 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/exceptions/UnitSystemArgumentException.java +++ b/src/main/java/com/synerset/unitility/unitsystem/exceptions/UnitSystemArgumentException.java @@ -1,15 +1,8 @@ package com.synerset.unitility.unitsystem.exceptions; -public class UnitSystemArgumentException extends RuntimeException{ - public UnitSystemArgumentException() { - } - +public class UnitSystemArgumentException extends RuntimeException { public UnitSystemArgumentException(String message) { super(message); } - public UnitSystemArgumentException(String message, Exception e) { - super(message, e); - } - } diff --git a/src/main/java/com/synerset/unitility/unitsystem/flows/MassFlow.java b/src/main/java/com/synerset/unitility/unitsystem/flows/MassFlow.java index 96cf9ea..0cc27ba 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/flows/MassFlow.java +++ b/src/main/java/com/synerset/unitility/unitsystem/flows/MassFlow.java @@ -8,11 +8,13 @@ public final class MassFlow implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private MassFlow(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -20,6 +22,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -27,14 +34,14 @@ public Unit getUnit() { @Override public MassFlow toBaseUnit() { - double valueInKilogramsPerSecond = unit.toBaseUnit(value); + double valueInKilogramsPerSecond = unit.toValueInBaseUnit(value); return MassFlow.of(valueInKilogramsPerSecond, MassFlowUnits.KILOGRAM_PER_SECOND); } @Override public MassFlow toUnit(Unit targetUnit) { - double valueInKilogramsPerSecond = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInKilogramsPerSecond); + double valueInKilogramsPerSecond = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInKilogramsPerSecond); return MassFlow.of(valueInTargetUnit, targetUnit); } @@ -43,29 +50,21 @@ public MassFlow createNewWithValue(double value) { return MassFlow.of(value, unit); } - // Custom value getters - public double getValueOfKilogramsPerSecond() { - if (unit == MassFlowUnits.KILOGRAM_PER_SECOND) { - return value; - } - return toUnit(MassFlowUnits.KILOGRAM_PER_SECOND).getValue(); - } - - // Custom converter methods, for most popular units - public MassFlow toKilogramsPerSecond(){ - return toUnit(MassFlowUnits.KILOGRAM_PER_SECOND); + // Convert to target unit + public double getInKilogramsPerSecond() { + return getIn(MassFlowUnits.KILOGRAM_PER_SECOND); } - public MassFlow toKiloGramPerHour(){ - return toUnit(MassFlowUnits.KILOGRAM_PER_HOUR); + public double getInKiloGramsPerHour() { + return getIn(MassFlowUnits.KILOGRAM_PER_HOUR); } - public MassFlow toTonnesPerHour(){ - return toUnit(MassFlowUnits.TONNE_PER_HOUR); + public double getInTonnesPerHour() { + return getIn(MassFlowUnits.TONNE_PER_HOUR); } - public MassFlow toPoundsPerSecond(){ - return toUnit(MassFlowUnits.POUND_PER_SECOND); + public double getInPoundsPerSecond() { + return getIn(MassFlowUnits.POUND_PER_SECOND); } @Override @@ -86,6 +85,7 @@ public String toString() { return "MassFlow{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static MassFlow of(double value, Unit unit) { return new MassFlow(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/flows/MassFlowUnits.java b/src/main/java/com/synerset/unitility/unitsystem/flows/MassFlowUnits.java index 8cfa8d8..89cdea6 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/flows/MassFlowUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/flows/MassFlowUnits.java @@ -32,12 +32,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/flows/VolumetricFlow.java b/src/main/java/com/synerset/unitility/unitsystem/flows/VolumetricFlow.java index ef895a3..c23fbac 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/flows/VolumetricFlow.java +++ b/src/main/java/com/synerset/unitility/unitsystem/flows/VolumetricFlow.java @@ -8,11 +8,13 @@ public final class VolumetricFlow implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private VolumetricFlow(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -20,6 +22,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -27,14 +34,14 @@ public Unit getUnit() { @Override public VolumetricFlow toBaseUnit() { - double valueInCubicMetersPerSecond = unit.toBaseUnit(value); + double valueInCubicMetersPerSecond = unit.toValueInBaseUnit(value); return VolumetricFlow.of(valueInCubicMetersPerSecond, VolumetricFlowUnits.CUBIC_METERS_PER_SECOND); } @Override public VolumetricFlow toUnit(Unit targetUnit) { - double valueInCubicMetersPerSecond = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInCubicMetersPerSecond); + double valueInCubicMetersPerSecond = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInCubicMetersPerSecond); return VolumetricFlow.of(valueInTargetUnit, targetUnit); } @@ -43,56 +50,41 @@ public VolumetricFlow createNewWithValue(double value) { return VolumetricFlow.of(value, unit); } - // Custom value getters - public double getValueOfCubicMetersPerSecond() { - if (unit == VolumetricFlowUnits.CUBIC_METERS_PER_SECOND) { - return value; - } - return toUnit(VolumetricFlowUnits.CUBIC_METERS_PER_SECOND).getValue(); - } - - public double getValueOfCubicMetersPerHour() { - if (unit == VolumetricFlowUnits.CUBIC_METERS_PER_HOUR) { - return value; - } - return toUnit(VolumetricFlowUnits.CUBIC_METERS_PER_HOUR).getValue(); - } - - // Custom converter methods, for most popular units - public VolumetricFlow toCubicMetersPerSecond() { - return toUnit(VolumetricFlowUnits.CUBIC_METERS_PER_SECOND); + // Convert to target unit + public double getInCubicMetersPerSecond() { + return getIn(VolumetricFlowUnits.CUBIC_METERS_PER_SECOND); } - public VolumetricFlow toCubicMetersPerMinute() { - return toUnit(VolumetricFlowUnits.CUBIC_METERS_PER_MINUTE); + public double getInCubicMetersPerMinute() { + return getIn(VolumetricFlowUnits.CUBIC_METERS_PER_MINUTE); } - public VolumetricFlow toCubicMetersPerHour() { - return toUnit(VolumetricFlowUnits.CUBIC_METERS_PER_HOUR); + public double getInCubicMetersPerHour() { + return getIn(VolumetricFlowUnits.CUBIC_METERS_PER_HOUR); } - public VolumetricFlow toLitresPerSecond() { - return toUnit(VolumetricFlowUnits.LITRE_PER_SECOND); + public double getInLitresPerSecond() { + return getIn(VolumetricFlowUnits.LITRE_PER_SECOND); } - public VolumetricFlow toLitresPerMinute() { - return toUnit(VolumetricFlowUnits.LITRE_PER_MINUTE); + public double getInLitresPerMinute() { + return getIn(VolumetricFlowUnits.LITRE_PER_MINUTE); } - public VolumetricFlow toLitresPerHour() { - return toUnit(VolumetricFlowUnits.LITRE_PER_HOUR); + public double getInLitresPerHour() { + return getIn(VolumetricFlowUnits.LITRE_PER_HOUR); } - public VolumetricFlow toGallonsPerSecond() { - return toUnit(VolumetricFlowUnits.GALLONS_PER_SECOND); + public double getInGallonsPerSecond() { + return getIn(VolumetricFlowUnits.GALLONS_PER_SECOND); } - public VolumetricFlow toGallonsPerMinute() { - return toUnit(VolumetricFlowUnits.GALLONS_PER_MINUTE); + public double getInGallonsPerMinute() { + return getIn(VolumetricFlowUnits.GALLONS_PER_MINUTE); } - public VolumetricFlow toGallonsPerHour() { - return toUnit(VolumetricFlowUnits.GALLONS_PER_HOUR); + public double getInGallonsPerHour() { + return getIn(VolumetricFlowUnits.GALLONS_PER_HOUR); } @Override @@ -113,6 +105,7 @@ public String toString() { return "VolumetricFlow{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static VolumetricFlow of(double value, Unit unit) { return new VolumetricFlow(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/flows/VolumetricFlowUnits.java b/src/main/java/com/synerset/unitility/unitsystem/flows/VolumetricFlowUnits.java index ecd4001..a99a02f 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/flows/VolumetricFlowUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/flows/VolumetricFlowUnits.java @@ -37,12 +37,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } diff --git a/src/main/java/com/synerset/unitility/unitsystem/humidity/HumidityRatio.java b/src/main/java/com/synerset/unitility/unitsystem/humidity/HumidityRatio.java index 390877a..7db6497 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/humidity/HumidityRatio.java +++ b/src/main/java/com/synerset/unitility/unitsystem/humidity/HumidityRatio.java @@ -9,11 +9,13 @@ public final class HumidityRatio implements PhysicalQuantity { public static final RelativeHumidity HUM_RATIO_MIN_LIMIT = RelativeHumidity.ofPercentage(0); private final double value; + private final double baseValue; private final Unit unit; private HumidityRatio(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -21,6 +23,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -28,14 +35,14 @@ public Unit getUnit() { @Override public HumidityRatio toBaseUnit() { - double valueInKgKg = unit.toBaseUnit(value); + double valueInKgKg = unit.toValueInBaseUnit(value); return HumidityRatio.of(valueInKgKg, HumidityRatioUnits.KILOGRAM_PER_KILOGRAM); } @Override public HumidityRatio toUnit(Unit targetUnit) { - double valueInKgKg = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInKgKg); + double valueInKgKg = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInKgKg); return HumidityRatio.of(valueInTargetUnit, targetUnit); } @@ -44,21 +51,13 @@ public HumidityRatio createNewWithValue(double value) { return HumidityRatio.of(value, unit); } - // Custom value getters - public double getValueOfKilogramPerKilogram() { - if (unit == HumidityRatioUnits.KILOGRAM_PER_KILOGRAM) { - return value; - } - return toUnit(HumidityRatioUnits.KILOGRAM_PER_KILOGRAM).getValue(); - } - - // Custom converter methods, for most popular units - public HumidityRatio toKilogramPerKilogram() { - return toUnit(HumidityRatioUnits.KILOGRAM_PER_KILOGRAM); + // Convert to target unit + public double getInKilogramPerKilogram() { + return getIn(HumidityRatioUnits.KILOGRAM_PER_KILOGRAM); } - public HumidityRatio toPoundPerPound() { - return toUnit(HumidityRatioUnits.POUND_PER_POUND); + public double getInPoundPerPound() { + return getIn(HumidityRatioUnits.POUND_PER_POUND); } @Override @@ -79,6 +78,7 @@ public String toString() { return "HumidityRatio{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static HumidityRatio of(double value, Unit unit) { return new HumidityRatio(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/humidity/HumidityRatioUnits.java b/src/main/java/com/synerset/unitility/unitsystem/humidity/HumidityRatioUnits.java index 3b2d181..757f710 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/humidity/HumidityRatioUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/humidity/HumidityRatioUnits.java @@ -7,7 +7,7 @@ public enum HumidityRatioUnits implements Unit { KILOGRAM_PER_KILOGRAM("kg/kg", val -> val, val -> val), - POUND_PER_POUND("lb/lb", val -> val / 2.20462262184878 , val -> val * 2.20462262184878); + POUND_PER_POUND("lb/lb", val -> val / 2.20462262184878, val -> val * 2.20462262184878); private final String symbol; private final DoubleUnaryOperator toBaseConverter; @@ -30,12 +30,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } diff --git a/src/main/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidity.java b/src/main/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidity.java index c2a6080..2f79abb 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidity.java +++ b/src/main/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidity.java @@ -10,11 +10,13 @@ public final class RelativeHumidity implements PhysicalQuantity unit; private RelativeHumidity(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -22,6 +24,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -29,14 +36,14 @@ public Unit getUnit() { @Override public RelativeHumidity toBaseUnit() { - double valueInPascal = unit.toBaseUnit(value); + double valueInPascal = unit.toValueInBaseUnit(value); return RelativeHumidity.of(valueInPascal, RelativeHumidityUnits.PERCENT); } @Override public RelativeHumidity toUnit(Unit targetUnit) { - double valueInPascal = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInPascal); + double valueInPascal = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInPascal); return RelativeHumidity.of(valueInTargetUnit, targetUnit); } @@ -45,21 +52,13 @@ public RelativeHumidity createNewWithValue(double value) { return RelativeHumidity.of(value, unit); } - // Custom value getters - public double getValueOfPercent() { - if (unit == RelativeHumidityUnits.PERCENT) { - return value; - } - return toUnit(RelativeHumidityUnits.PERCENT).getValue(); - } - - // Custom converter methods, for most popular units - public RelativeHumidity toPercent() { - return toUnit(RelativeHumidityUnits.PERCENT); + // Convert to target unit + public double getInPercent() { + return getIn(RelativeHumidityUnits.PERCENT); } - public RelativeHumidity toDecimal() { - return toUnit(RelativeHumidityUnits.DECIMAL); + public double getInDecimal() { + return getIn(RelativeHumidityUnits.DECIMAL); } @Override @@ -80,6 +79,7 @@ public String toString() { return "RelativeHumidity{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static RelativeHumidity of(double value, Unit unit) { return new RelativeHumidity(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidityUnits.java b/src/main/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidityUnits.java index 637ff68..2b6fe68 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidityUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidityUnits.java @@ -4,7 +4,7 @@ import java.util.function.DoubleUnaryOperator; -public enum RelativeHumidityUnits implements Unit{ +public enum RelativeHumidityUnits implements Unit { PERCENT("%", val -> val, val -> val), DECIMAL("-", val -> val * 100, val -> val / 100); @@ -30,12 +30,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/mechanical/Force.java b/src/main/java/com/synerset/unitility/unitsystem/mechanical/Force.java index 5a44459..a3c7d38 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/mechanical/Force.java +++ b/src/main/java/com/synerset/unitility/unitsystem/mechanical/Force.java @@ -8,11 +8,13 @@ public final class Force implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private Force(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -20,6 +22,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -27,14 +34,14 @@ public Unit getUnit() { @Override public Force toBaseUnit() { - double valueInNewtons = unit.toBaseUnit(value); + double valueInNewtons = unit.toValueInBaseUnit(value); return Force.of(valueInNewtons, ForceUnits.NEWTON); } @Override public Force toUnit(Unit targetUnit) { - double valueInNewtons = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInNewtons); + double valueInNewtons = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInNewtons); return Force.of(valueInTargetUnit, targetUnit); } @@ -43,37 +50,29 @@ public Force createNewWithValue(double value) { return Force.of(value, unit); } - // Custom value getters - public double getValueOfNewtons() { - if (unit == ForceUnits.NEWTON) { - return value; - } - return toUnit(ForceUnits.NEWTON).getValue(); - } - - // Custom converter methods, for most popular units - public Force toNewtons() { - return toUnit(ForceUnits.NEWTON); + // Convert to target unit + public double getInNewtons() { + return getIn(ForceUnits.NEWTON); } - public Force toKiloNewtons() { - return toUnit(ForceUnits.KILONEWTON); + public double getInKiloNewtons() { + return getIn(ForceUnits.KILONEWTON); } - public Force toKiloponds() { - return toUnit(ForceUnits.KILOPOND); + public double getInKiloponds() { + return getIn(ForceUnits.KILOPOND); } - public Force toDynes() { - return toUnit(ForceUnits.DYNE); + public double getInDynes() { + return getIn(ForceUnits.DYNE); } - public Force toPoundForce() { - return toUnit(ForceUnits.POUND_FORCE); + public double getInPoundsForce() { + return getIn(ForceUnits.POUND_FORCE); } - public Force toPoundal() { - return toUnit(ForceUnits.POUNDAL); + public double getInPoundals() { + return getIn(ForceUnits.POUNDAL); } @Override @@ -94,6 +93,7 @@ public String toString() { return "Force{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static Force of(double value, Unit unit) { return new Force(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/mechanical/ForceUnits.java b/src/main/java/com/synerset/unitility/unitsystem/mechanical/ForceUnits.java index af75616..af82c86 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/mechanical/ForceUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/mechanical/ForceUnits.java @@ -34,12 +34,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/mechanical/Momentum.java b/src/main/java/com/synerset/unitility/unitsystem/mechanical/Momentum.java index f03b55a..3af35d3 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/mechanical/Momentum.java +++ b/src/main/java/com/synerset/unitility/unitsystem/mechanical/Momentum.java @@ -8,11 +8,13 @@ public final class Momentum implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private Momentum(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -20,6 +22,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -27,14 +34,14 @@ public Unit getUnit() { @Override public Momentum toBaseUnit() { - double valueInKilogramMeterPerSecond = unit.toBaseUnit(value); + double valueInKilogramMeterPerSecond = unit.toValueInBaseUnit(value); return Momentum.of(valueInKilogramMeterPerSecond, MomentumUnits.KILOGRAM_METER_PER_SECOND); } @Override public Momentum toUnit(Unit targetUnit) { - double valueInKilogramMeterPerSecond = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInKilogramMeterPerSecond); + double valueInKilogramMeterPerSecond = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInKilogramMeterPerSecond); return Momentum.of(valueInTargetUnit, targetUnit); } @@ -43,25 +50,17 @@ public Momentum createNewWithValue(double value) { return Momentum.of(value, unit); } - // Custom value getters - public double getValueOfKilogramMetersPerSecond() { - if (unit == MomentumUnits.KILOGRAM_METER_PER_SECOND) { - return value; - } - return toUnit(MomentumUnits.KILOGRAM_METER_PER_SECOND).getValue(); - } - - // Custom converter methods, for most popular units - public Momentum toKilogramMeterPerSecond(){ - return toUnit(MomentumUnits.KILOGRAM_METER_PER_SECOND); + // Convert to target unit + public double getInKilogramMetersPerSecond() { + return getIn(MomentumUnits.KILOGRAM_METER_PER_SECOND); } - public Momentum toPoundFeetPerSecond(){ - return toUnit(MomentumUnits.POUND_FEET_PER_SECOND); + public double getInPoundFeetPerSecond() { + return getIn(MomentumUnits.POUND_FEET_PER_SECOND); } - public Momentum toGramCentimetrePerSecond(){ - return toUnit(MomentumUnits.GRAM_CENTIMETRE_PER_SECOND); + public double getInGramCentimetersPerSecond() { + return getIn(MomentumUnits.GRAM_CENTIMETRE_PER_SECOND); } @Override @@ -82,6 +81,7 @@ public String toString() { return "Momentum{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static Momentum of(double value, Unit unit) { return new Momentum(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/mechanical/MomentumUnits.java b/src/main/java/com/synerset/unitility/unitsystem/mechanical/MomentumUnits.java index 2e2fd74..3b6a07c 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/mechanical/MomentumUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/mechanical/MomentumUnits.java @@ -30,12 +30,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } diff --git a/src/main/java/com/synerset/unitility/unitsystem/mechanical/Torque.java b/src/main/java/com/synerset/unitility/unitsystem/mechanical/Torque.java index a513322..4d7d7f7 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/mechanical/Torque.java +++ b/src/main/java/com/synerset/unitility/unitsystem/mechanical/Torque.java @@ -9,11 +9,13 @@ public final class Torque implements PhysicalQuantity { public static final Torque PHYSICAL_MIN_LIMIT = Torque.ofNewtonMeters(0); private final double value; + private final double baseValue; private final Unit unit; private Torque(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -21,6 +23,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -28,14 +35,14 @@ public Unit getUnit() { @Override public Torque toBaseUnit() { - double valueInNewtonMeters = unit.toBaseUnit(value); + double valueInNewtonMeters = unit.toValueInBaseUnit(value); return Torque.of(valueInNewtonMeters, TorqueUnits.NEWTON_METER); } @Override public Torque toUnit(Unit targetUnit) { - double valueInNewtonMeters = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInNewtonMeters); + double valueInNewtonMeters = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInNewtonMeters); return Torque.of(valueInTargetUnit, targetUnit); } @@ -44,33 +51,25 @@ public Torque createNewWithValue(double value) { return Torque.of(value, unit); } - // Custom value getters - public double getValueOfKilogramMetersPerSecond() { - if (unit == TorqueUnits.NEWTON_METER) { - return value; - } - return toUnit(TorqueUnits.NEWTON_METER).getValue(); - } - - // Custom converter methods for the most popular units - public Torque toNewtonMeters() { - return toUnit(TorqueUnits.NEWTON_METER); + // Convert to target unit + public double getInNewtonMeters() { + return getIn(TorqueUnits.NEWTON_METER); } - public Torque toMillinewtonMeters() { - return toUnit(TorqueUnits.MILLINEWTON_METER); + public double getInMillinewtonMeters() { + return getIn(TorqueUnits.MILLINEWTON_METER); } - public Torque toKilopondMeters() { - return toUnit(TorqueUnits.KILOPOND_METER); + public double getInKilopondMeters() { + return getIn(TorqueUnits.KILOPOND_METER); } - public Torque toPoundFeet() { - return toUnit(TorqueUnits.FOOT_POUND); + public double getInPoundFeet() { + return getIn(TorqueUnits.FOOT_POUND); } - public Torque toInchPounds() { - return toUnit(TorqueUnits.INCH_POUND); + public double getInInchPounds() { + return getIn(TorqueUnits.INCH_POUND); } @Override @@ -91,6 +90,7 @@ public String toString() { return "Torque{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static Torque of(double value, Unit unit) { return new Torque(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/mechanical/TorqueUnits.java b/src/main/java/com/synerset/unitility/unitsystem/mechanical/TorqueUnits.java index bea9fe7..75a0bba 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/mechanical/TorqueUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/mechanical/TorqueUnits.java @@ -33,12 +33,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Density.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Density.java index 679dbde..45c8c51 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Density.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Density.java @@ -8,11 +8,13 @@ public final class Density implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private Density(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -20,6 +22,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -27,14 +34,14 @@ public Unit getUnit() { @Override public Density toBaseUnit() { - double valueInKGpM3 = unit.toBaseUnit(value); + double valueInKGpM3 = unit.toValueInBaseUnit(value); return Density.of(valueInKGpM3, DensityUnits.KILOGRAM_PER_CUBIC_METER); } @Override public Density toUnit(Unit targetUnit) { - double valueInKGpM3 = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInKGpM3); + double valueInKGpM3 = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInKGpM3); return Density.of(valueInTargetUnit, targetUnit); } @@ -43,21 +50,17 @@ public Density createNewWithValue(double value) { return Density.of(value, unit); } - // Custom value getters - public double getValueOfKilogramPerCubicMeter() { - if (unit == DensityUnits.KILOGRAM_PER_CUBIC_METER) { - return value; - } - return toUnit(DensityUnits.KILOGRAM_PER_CUBIC_METER).getValue(); + // Convert to target unit + public double getInKilogramsPerCubicMeters() { + return getIn(DensityUnits.KILOGRAM_PER_CUBIC_METER); } - // Custom converter methods, for most popular units - public Density toKilogramPerCubicMeter() { - return toUnit(DensityUnits.KILOGRAM_PER_CUBIC_METER); + public double getInPoundsPerCubicFoot() { + return getIn(DensityUnits.POUND_PER_CUBIC_FOOT); } - public Density toPoundPerCubicFoot() { - return toUnit(DensityUnits.POUND_PER_CUBIC_FOOT); + public double getInPoundsPerCubicInches() { + return getIn(DensityUnits.POUND_PER_CUBIC_INCH); } @Override @@ -78,6 +81,7 @@ public String toString() { return "Density{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static Density of(double value, Unit unit) { return new Density(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DensityUnits.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DensityUnits.java index 2d42c0f..7f07569 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DensityUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DensityUnits.java @@ -8,7 +8,7 @@ public enum DensityUnits implements Unit { KILOGRAM_PER_CUBIC_METER("kg/m³", val -> val, val -> val), POUND_PER_CUBIC_FOOT("lb/ft³", val -> val * 16.0184633739599, val -> val / 16.0184633739599), - POUNDS_PER_CUBIC_INCH("lb/in³", val -> val / 0.000036127292218, val -> val * 0.000036127292218); + POUND_PER_CUBIC_INCH("lb/in³", val -> val / 0.000036127292218, val -> val * 0.000036127292218); private final String symbol; private final DoubleUnaryOperator toBaseConverter; @@ -31,12 +31,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosity.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosity.java index 7761fd9..c2f1013 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosity.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosity.java @@ -8,11 +8,13 @@ public final class DynamicViscosity implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private DynamicViscosity(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -20,6 +22,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -27,14 +34,14 @@ public Unit getUnit() { @Override public DynamicViscosity toBaseUnit() { - double valueInPascalSecond = unit.toBaseUnit(value); + double valueInPascalSecond = unit.toValueInBaseUnit(value); return DynamicViscosity.of(valueInPascalSecond, DynamicViscosityUnits.PASCAL_SECOND); } @Override public DynamicViscosity toUnit(Unit targetUnit) { - double valueInPascalSecond = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInPascalSecond); + double valueInPascalSecond = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInPascalSecond); return DynamicViscosity.of(valueInTargetUnit, targetUnit); } @@ -43,25 +50,17 @@ public DynamicViscosity createNewWithValue(double value) { return DynamicViscosity.of(value, unit); } - // Custom value getters - public double getValueOfPascalSecond() { - if (unit == DynamicViscosityUnits.PASCAL_SECOND) { - return value; - } - return toUnit(DynamicViscosityUnits.PASCAL_SECOND).getValue(); - } - - // Custom converter methods, for most popular units - public DynamicViscosity toKiloGramPerMeterSecond(){ - return toUnit(DynamicViscosityUnits.KILOGRAM_PER_METER_SECOND); + // Convert to target unit + public double getInKiloGramPerMeterSecond() { + return getIn(DynamicViscosityUnits.KILOGRAM_PER_METER_SECOND); } - public DynamicViscosity toPascalSecond(){ - return toUnit(DynamicViscosityUnits.PASCAL_SECOND); + public double getInPascalsSecond() { + return getIn(DynamicViscosityUnits.PASCAL_SECOND); } - public DynamicViscosity toPoise(){ - return toUnit(DynamicViscosityUnits.POISE); + public double getInPoise() { + return getIn(DynamicViscosityUnits.POISE); } @Override @@ -82,6 +81,7 @@ public String toString() { return "DynamicViscosity{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static DynamicViscosity of(double value, Unit unit) { return new DynamicViscosity(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosityUnits.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosityUnits.java index 57ac4d6..b64d541 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosityUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosityUnits.java @@ -31,12 +31,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Energy.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Energy.java index 94feeba..3025b9b 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Energy.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Energy.java @@ -8,11 +8,13 @@ public final class Energy implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private Energy(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -20,6 +22,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -27,14 +34,14 @@ public Unit getUnit() { @Override public Energy toBaseUnit() { - double valueInJoules = unit.toBaseUnit(value); + double valueInJoules = unit.toValueInBaseUnit(value); return Energy.of(valueInJoules, EnergyUnits.JOULE); } @Override public Energy toUnit(Unit targetUnit) { - double valueInJoules = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInJoules); + double valueInJoules = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInJoules); return Energy.of(valueInTargetUnit, targetUnit); } @@ -43,56 +50,41 @@ public Energy createNewWithValue(double value) { return Energy.of(value, unit); } - // Custom value getters - public double getValueOfJoules() { - if (unit == EnergyUnits.JOULE) { - return value; - } - return toUnit(EnergyUnits.JOULE).getValue(); - } - - public double getValueOfKiloJoules() { - if (unit == EnergyUnits.KILOJOULE) { - return value; - } - return toUnit(EnergyUnits.KILOJOULE).getValue(); - } - - // Custom converter methods, for most popular units - public Energy toJoules() { - return toUnit(EnergyUnits.JOULE); + // Convert to target unit + public double getInJoules() { + return getIn(EnergyUnits.JOULE); } - public Energy toMilliJoules() { - return toUnit(EnergyUnits.MILLIJOULE); + public double getInMilliJoules() { + return getIn(EnergyUnits.MILLIJOULE); } - public Energy toKiloJoules() { - return toUnit(EnergyUnits.KILOJOULE); + public double getInKiloJoules() { + return getIn(EnergyUnits.KILOJOULE); } - public Energy toMegaJoules() { - return toUnit(EnergyUnits.MEGAJOULE); + public double getInMegaJoules() { + return getIn(EnergyUnits.MEGAJOULE); } - public Energy toBTU() { - return toUnit(EnergyUnits.BTU); + public double getInBTUs() { + return getIn(EnergyUnits.BTU); } - public Energy toCalories() { - return toUnit(EnergyUnits.CALORIE); + public double getInCalories() { + return getIn(EnergyUnits.CALORIE); } - public Energy toKiloCalories() { - return toUnit(EnergyUnits.KILOCALORIE); + public double getInKiloCalories() { + return getIn(EnergyUnits.KILOCALORIE); } - public Energy toWattHour() { - return toUnit(EnergyUnits.WATT_HOUR); + public double getInWattHours() { + return getIn(EnergyUnits.WATT_HOUR); } - public Energy toKilowattHour() { - return toUnit(EnergyUnits.KILOWATT_HOUR); + public double getInKilowattHours() { + return getIn(EnergyUnits.KILOWATT_HOUR); } @Override @@ -113,6 +105,7 @@ public String toString() { return "Energy{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static Energy of(double value, Unit unit) { return new Energy(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/EnergyUnits.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/EnergyUnits.java index 0a2b2e8..a2ce83f 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/EnergyUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/EnergyUnits.java @@ -37,12 +37,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } \ No newline at end of file diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosity.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosity.java index 3d51d04..f23f860 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosity.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosity.java @@ -8,11 +8,13 @@ public final class KinematicViscosity implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private KinematicViscosity(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -20,6 +22,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -27,14 +34,14 @@ public Unit getUnit() { @Override public KinematicViscosity toBaseUnit() { - double valueInSquareMeterPerSecond = unit.toBaseUnit(value); + double valueInSquareMeterPerSecond = unit.toValueInBaseUnit(value); return KinematicViscosity.of(valueInSquareMeterPerSecond, KinematicViscosityUnits.SQUARE_METER_PER_SECOND); } @Override public KinematicViscosity toUnit(Unit targetUnit) { - double valueInSquareMeterPerSecond = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInSquareMeterPerSecond); + double valueInSquareMeterPerSecond = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInSquareMeterPerSecond); return KinematicViscosity.of(valueInTargetUnit, targetUnit); } @@ -43,21 +50,13 @@ public KinematicViscosity createNewWithValue(double value) { return KinematicViscosity.of(value, unit); } - // Custom value getters - public double getValueOfSquareMetersPerSecond() { - if (unit == KinematicViscosityUnits.SQUARE_METER_PER_SECOND) { - return value; - } - return toUnit(KinematicViscosityUnits.SQUARE_METER_PER_SECOND).getValue(); - } - - // Custom converter methods, for most popular units - public KinematicViscosity toSquareMeterPerSecond(){ - return toUnit(KinematicViscosityUnits.SQUARE_METER_PER_SECOND); + // Convert to target unit + public double getInSquareMetersPerSecond() { + return getIn(KinematicViscosityUnits.SQUARE_METER_PER_SECOND); } - public KinematicViscosity toSquareFootPerSecond(){ - return toUnit(KinematicViscosityUnits.SQUARE_FOOT_PER_SECOND); + public double getInSquareFeetPerSecond() { + return getIn(KinematicViscosityUnits.SQUARE_FOOT_PER_SECOND); } @Override @@ -78,6 +77,7 @@ public String toString() { return "KinematicViscosity{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static KinematicViscosity of(double value, Unit unit) { return new KinematicViscosity(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosityUnits.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosityUnits.java index 4d358ca..333aa92 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosityUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosityUnits.java @@ -29,12 +29,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Power.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Power.java index 141d459..0a346fd 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Power.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Power.java @@ -7,11 +7,13 @@ public final class Power implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private Power(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -19,6 +21,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -26,14 +33,14 @@ public Unit getUnit() { @Override public Power toBaseUnit() { - double valueInWatts = unit.toBaseUnit(value); + double valueInWatts = unit.toValueInBaseUnit(value); return Power.of(valueInWatts, PowerUnits.WATT); } @Override public Power toUnit(Unit targetUnit) { - double valueInWatts = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInWatts); + double valueInWatts = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInWatts); return Power.of(valueInTargetUnit, targetUnit); } @@ -42,40 +49,25 @@ public Power createNewWithValue(double value) { return Power.of(value, unit); } - // Custom value getters - public double getValueOfWatts() { - if (unit == PowerUnits.WATT) { - return value; - } - return toUnit(PowerUnits.WATT).getValue(); - } - - public double getValueOfKiloWatts() { - if (unit == PowerUnits.KILOWATT) { - return value; - } - return toUnit(PowerUnits.KILOWATT).getValue(); - } - - // Custom converter methods, for most popular units - public Power toWatts(){ - return toUnit(PowerUnits.WATT); + // Convert to target unit + public double getInWatts() { + return getIn(PowerUnits.WATT); } - public Power toKiloWatts(){ - return toUnit(PowerUnits.KILOWATT); + public double getInKiloWatts() { + return getIn(PowerUnits.KILOWATT); } - public Power toBTUPerHour(){ - return toUnit(PowerUnits.BTU_PER_HOUR); + public double getInBTUPerHour() { + return getIn(PowerUnits.BTU_PER_HOUR); } - public Power toMegaWatts(){ - return toUnit(PowerUnits.MEGAWATT); + public double getInMegaWatts() { + return getIn(PowerUnits.MEGAWATT); } - public Power toHorsePower(){ - return toUnit(PowerUnits.HORSE_POWER); + public double getInHorsePower() { + return getIn(PowerUnits.HORSE_POWER); } @Override @@ -96,6 +88,7 @@ public String toString() { return "Power{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static Power of(double value, Unit unit) { return new Power(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/PowerUnits.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/PowerUnits.java index 3139699..6e9dcaa 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/PowerUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/PowerUnits.java @@ -33,12 +33,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Pressure.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Pressure.java index ffd7466..76e5aa9 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Pressure.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Pressure.java @@ -9,13 +9,14 @@ public final class Pressure implements PhysicalQuantity { public static final Pressure STANDARD_ATMOSPHERE = Pressure.ofPascal(101_325); public static final Pressure TECHNICAL_ATMOSPHERE = Pressure.ofPascal(98_067); - private final double value; + private final double baseValue; private final Unit unit; private Pressure(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -23,6 +24,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -30,14 +36,14 @@ public Unit getUnit() { @Override public Pressure toBaseUnit() { - double valueInPascal = unit.toBaseUnit(value); + double valueInPascal = unit.toValueInBaseUnit(value); return Pressure.of(valueInPascal, PressureUnits.PASCAL); } @Override public Pressure toUnit(Unit targetUnit) { - double valueInPascal = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInPascal); + double valueInPascal = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInPascal); return Pressure.of(valueInTargetUnit, targetUnit); } @@ -46,41 +52,33 @@ public Pressure createNewWithValue(double value) { return Pressure.of(value, unit); } - // Custom value getters - public double getValueOfPascals() { - if (unit == PressureUnits.PASCAL) { - return value; - } - return toUnit(PressureUnits.PASCAL).getValue(); - } - - // Custom converter methods, for most popular units - public Pressure toPascal() { - return toUnit(PressureUnits.PASCAL); + // Convert to target unit + public double getInPascals() { + return getIn(PressureUnits.PASCAL); } - public Pressure toHectoPascal() { - return toUnit(PressureUnits.HECTOPASCAL); + public double getInHectoPascals() { + return getIn(PressureUnits.HECTOPASCAL); } - public Pressure toMegaPascal() { - return toUnit(PressureUnits.MEGAPASCAL); + public double getInMegaPascals() { + return getIn(PressureUnits.MEGAPASCAL); } - public Pressure toBar() { - return toUnit(PressureUnits.BAR); + public double getInBar() { + return getIn(PressureUnits.BAR); } - public Pressure toMilliBar() { - return toUnit(PressureUnits.MILLIBAR); + public double getInMilliBar() { + return getIn(PressureUnits.MILLIBAR); } - public Pressure toPsi() { - return toUnit(PressureUnits.PSI); + public double getInPsi() { + return getIn(PressureUnits.PSI); } - public Pressure toTorr() { - return toUnit(PressureUnits.TORR); + public double getInTorr() { + return getIn(PressureUnits.TORR); } @Override @@ -101,6 +99,7 @@ public String toString() { return "Pressure{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static Pressure of(double value, Unit unit) { return new Pressure(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/PressureUnits.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/PressureUnits.java index dbcc014..37305e1 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/PressureUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/PressureUnits.java @@ -35,12 +35,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpy.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpy.java index c02ec2a..e8b8689 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpy.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpy.java @@ -7,11 +7,13 @@ public final class SpecificEnthalpy implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private SpecificEnthalpy(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -19,6 +21,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -26,14 +33,14 @@ public Unit getUnit() { @Override public SpecificEnthalpy toBaseUnit() { - double valueInJoulePerKilogram = unit.toBaseUnit(value); + double valueInJoulePerKilogram = unit.toValueInBaseUnit(value); return SpecificEnthalpy.of(valueInJoulePerKilogram, SpecificEnthalpyUnits.JOULE_PER_KILOGRAM); } @Override public SpecificEnthalpy toUnit(Unit targetUnit) { - double valueInJoulePerKilogram = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInJoulePerKilogram); + double valueInJoulePerKilogram = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInJoulePerKilogram); return SpecificEnthalpy.of(valueInTargetUnit, targetUnit); } @@ -42,25 +49,17 @@ public SpecificEnthalpy createNewWithValue(double value) { return SpecificEnthalpy.of(value, unit); } - // Custom value getters - public double getValueOfKiloJoulePerKilogram() { - if (unit == SpecificEnthalpyUnits.KILOJOULE_PER_KILOGRAM) { - return value; - } - return toUnit(SpecificEnthalpyUnits.KILOJOULE_PER_KILOGRAM).getValue(); - } - - // Custom converter methods, for most popular units - public SpecificEnthalpy toJoulePerKiloGram() { - return toUnit(SpecificEnthalpyUnits.JOULE_PER_KILOGRAM); + // Convert to target unit + public double getInJoulesPerKiloGram() { + return getIn(SpecificEnthalpyUnits.JOULE_PER_KILOGRAM); } - public SpecificEnthalpy toKiloJoulePerKiloGram() { - return toUnit(SpecificEnthalpyUnits.KILOJOULE_PER_KILOGRAM); + public double getInKiloJoulesPerKiloGram() { + return getIn(SpecificEnthalpyUnits.KILOJOULE_PER_KILOGRAM); } - public SpecificEnthalpy toBTUPerPound() { - return toUnit(SpecificEnthalpyUnits.BTU_PER_POUND); + public double getInBTUsPerPound() { + return getIn(SpecificEnthalpyUnits.BTU_PER_POUND); } @Override @@ -81,6 +80,7 @@ public String toString() { return "SpecificEnthalpy{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static SpecificEnthalpy of(double value, Unit unit) { return new SpecificEnthalpy(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpyUnits.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpyUnits.java index 591a274..c5fc63b 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpyUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpyUnits.java @@ -31,12 +31,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeat.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeat.java index 121e1e5..ab23521 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeat.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeat.java @@ -7,11 +7,13 @@ public final class SpecificHeat implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private SpecificHeat(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -19,6 +21,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -26,14 +33,14 @@ public Unit getUnit() { @Override public SpecificHeat toBaseUnit() { - double valueInJoulePerKiloGramKelvin = unit.toBaseUnit(value); + double valueInJoulePerKiloGramKelvin = unit.toValueInBaseUnit(value); return SpecificHeat.of(valueInJoulePerKiloGramKelvin, SpecificHeatUnits.JOULES_PER_KILOGRAM_KELVIN); } @Override public SpecificHeat toUnit(Unit targetUnit) { - double valueInJoulePerKiloGramKelvin = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInJoulePerKiloGramKelvin); + double valueInJoulePerKiloGramKelvin = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInJoulePerKiloGramKelvin); return SpecificHeat.of(valueInTargetUnit, targetUnit); } @@ -42,25 +49,17 @@ public SpecificHeat createNewWithValue(double value) { return SpecificHeat.of(value, unit); } - // Custom value getters - public double getValueOfKiloJoulesPerKilogramKelvin() { - if (unit == SpecificHeatUnits.KILOJOULES_PER_KILOGRAM_KELVIN) { - return value; - } - return toUnit(SpecificHeatUnits.KILOJOULES_PER_KILOGRAM_KELVIN).getValue(); - } - - // Custom converter methods, for most popular units - public SpecificHeat toJoulePerKiloGramKelvin() { - return toUnit(SpecificHeatUnits.JOULES_PER_KILOGRAM_KELVIN); + // Convert to target unit + public double getInJoulePerKiloGramKelvin() { + return getIn(SpecificHeatUnits.JOULES_PER_KILOGRAM_KELVIN); } - public SpecificHeat toKiloJoulePerKiloGramKelvin() { - return toUnit(SpecificHeatUnits.KILOJOULES_PER_KILOGRAM_KELVIN); + public double getInKiloJoulesPerKiloGramKelvin() { + return getIn(SpecificHeatUnits.KILOJOULES_PER_KILOGRAM_KELVIN); } - public SpecificHeat toBTUPerPoundFahrenheit() { - return toUnit(SpecificHeatUnits.BTU_PER_POUND_FAHRENHEIT); + public double getInBTUsPerPoundFahrenheit() { + return getIn(SpecificHeatUnits.BTU_PER_POUND_FAHRENHEIT); } @Override @@ -81,6 +80,7 @@ public String toString() { return "SpecificHeat{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static SpecificHeat of(double value, Unit unit) { return new SpecificHeat(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeatUnits.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeatUnits.java index 4b9773b..247eb71 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeatUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeatUnits.java @@ -31,12 +31,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Temperature.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Temperature.java index f424044..614ede3 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Temperature.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Temperature.java @@ -10,11 +10,13 @@ public final class Temperature implements PhysicalQuantity { public static final Temperature PHYSICAL_MIN_LIMIT = Temperature.ofKelvins(0); private final double value; + private final double baseValue; private final Unit unit; private Temperature(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -22,6 +24,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -29,14 +36,14 @@ public Unit getUnit() { @Override public Temperature toBaseUnit() { - double valueInKelvin = unit.toBaseUnit(value); + double valueInKelvin = unit.toValueInBaseUnit(value); return Temperature.of(valueInKelvin, TemperatureUnits.KELVIN); } @Override public Temperature toUnit(Unit targetUnit) { - double valueInKelvin = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInKelvin); + double valueInKelvin = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInKelvin); return Temperature.of(valueInTargetUnit, targetUnit); } @@ -45,32 +52,17 @@ public Temperature createNewWithValue(double value) { return Temperature.of(value, unit); } - // Custom value getters - public double getValueOfCelsius() { - if (unit == TemperatureUnits.CELSIUS) { - return value; - } - return toUnit(TemperatureUnits.CELSIUS).getValue(); - } - - public double getValueOfKelvin() { - if (unit == TemperatureUnits.KELVIN) { - return value; - } - return toUnit(TemperatureUnits.KELVIN).getValue(); - } - - // Custom converter methods, for most popular units - public Temperature toKelvin(){ - return toUnit(TemperatureUnits.KELVIN); + // Convert to target unit + public double getInKelvins() { + return getIn(TemperatureUnits.KELVIN); } - public Temperature toCelsius(){ - return toUnit(TemperatureUnits.CELSIUS); + public double getInCelsius() { + return getIn(TemperatureUnits.CELSIUS); } - public Temperature toFahrenheit(){ - return toUnit(TemperatureUnits.FAHRENHEIT); + public double getInFahrenheits() { + return getIn(TemperatureUnits.FAHRENHEIT); } @Override @@ -97,6 +89,7 @@ public String toStringWithRelevantDigits(int relevantDigits) { return ValueFormatter.formatDoubleToRelevantDigits(value, relevantDigits) + separator + unit.getSymbol(); } + // Static factory methods public static Temperature of(double value, Unit unit) { return new Temperature(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/TemperatureUnits.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/TemperatureUnits.java index 5ead76d..0f73e94 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/TemperatureUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/TemperatureUnits.java @@ -8,7 +8,7 @@ public enum TemperatureUnits implements Unit { KELVIN("K", val -> val, val -> val), CELSIUS("°C", val -> val + 273.15, val -> val - 273.15), - FAHRENHEIT("°F", val -> (val - 32) * 5/9 + 273.15, val -> (val - 273.15) * 9/5 + 32); + FAHRENHEIT("°F", val -> (val - 32) * 5 / 9 + 273.15, val -> (val - 273.15) * 9 / 5 + 32); private final String symbol; private final DoubleUnaryOperator toBaseConverter; @@ -31,12 +31,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivity.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivity.java index ba52c50..c1ebcd7 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivity.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivity.java @@ -7,11 +7,13 @@ public final class ThermalConductivity implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private ThermalConductivity(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -19,6 +21,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -26,14 +33,14 @@ public Unit getUnit() { @Override public ThermalConductivity toBaseUnit() { - double valueInWattsPerMeterKelvin = unit.toBaseUnit(value); + double valueInWattsPerMeterKelvin = unit.toValueInBaseUnit(value); return ThermalConductivity.of(valueInWattsPerMeterKelvin, ThermalConductivityUnits.WATTS_PER_METER_KELVIN); } @Override public ThermalConductivity toUnit(Unit targetUnit) { - double valueInWattsPerMeterKelvin = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInWattsPerMeterKelvin); + double valueInWattsPerMeterKelvin = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInWattsPerMeterKelvin); return ThermalConductivity.of(valueInTargetUnit, targetUnit); } @@ -42,25 +49,17 @@ public ThermalConductivity createNewWithValue(double value) { return ThermalConductivity.of(value, unit); } - // Custom value getters - public double getValueOfWatsPerMeterKelvin() { - if (unit == ThermalConductivityUnits.WATTS_PER_METER_KELVIN) { - return value; - } - return toUnit(ThermalConductivityUnits.WATTS_PER_METER_KELVIN).getValue(); - } - - // Custom converter methods, for most popular units - public ThermalConductivity toWattsPerMeterKelvin() { - return toUnit(ThermalConductivityUnits.WATTS_PER_METER_KELVIN); + // Convert to target unit + public double getInWattsPerMeterKelvin() { + return getIn(ThermalConductivityUnits.WATTS_PER_METER_KELVIN); } - public ThermalConductivity toKilowattsPerMeterKelvin() { - return toUnit(ThermalConductivityUnits.KILOWATTS_PER_METER_KELVIN); + public double getInKilowattsPerMeterKelvin() { + return getIn(ThermalConductivityUnits.KILOWATTS_PER_METER_KELVIN); } - public ThermalConductivity toBTUPerHourFeetFahrenheit() { - return toUnit(ThermalConductivityUnits.BTU_PER_HOUR_FOOT_FAHRENHEIT); + public double getInBTUsPerHourFeetFahrenheit() { + return getIn(ThermalConductivityUnits.BTU_PER_HOUR_FOOT_FAHRENHEIT); } @Override @@ -81,6 +80,7 @@ public String toString() { return "ThermalConductivity{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static ThermalConductivity of(double value, Unit unit) { return new ThermalConductivity(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivityUnits.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivityUnits.java index eb772c6..4a71707 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivityUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivityUnits.java @@ -31,12 +31,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivity.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivity.java index 60fca6c..4f4d2a9 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivity.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivity.java @@ -8,11 +8,13 @@ public final class ThermalDiffusivity implements PhysicalQuantity { private final double value; + private final double baseValue; private final Unit unit; private ThermalDiffusivity(double value, Unit unit) { this.value = value; this.unit = unit; + this.baseValue = unit.toValueInBaseUnit(value); } @Override @@ -20,6 +22,11 @@ public double getValue() { return value; } + @Override + public double getBaseValue() { + return baseValue; + } + @Override public Unit getUnit() { return unit; @@ -27,14 +34,14 @@ public Unit getUnit() { @Override public ThermalDiffusivity toBaseUnit() { - double valueInSquareMeterPerSecond = unit.toBaseUnit(value); + double valueInSquareMeterPerSecond = unit.toValueInBaseUnit(value); return ThermalDiffusivity.of(valueInSquareMeterPerSecond, ThermalDiffusivityUnits.SQUARE_METER_PER_SECOND); } @Override public ThermalDiffusivity toUnit(Unit targetUnit) { - double valueInSquareMeterPerSecond = unit.toBaseUnit(value); - double valueInTargetUnit = targetUnit.fromBaseToThisUnit(valueInSquareMeterPerSecond); + double valueInSquareMeterPerSecond = unit.toValueInBaseUnit(value); + double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInSquareMeterPerSecond); return ThermalDiffusivity.of(valueInTargetUnit, targetUnit); } @@ -43,21 +50,13 @@ public ThermalDiffusivity createNewWithValue(double value) { return ThermalDiffusivity.of(value, unit); } - // Custom value getters - public double getValueOfSquareMetersPerSecond() { - if (unit == ThermalDiffusivityUnits.SQUARE_METER_PER_SECOND) { - return value; - } - return toUnit(ThermalDiffusivityUnits.SQUARE_METER_PER_SECOND).getValue(); - } - - // Custom converter methods, for most popular units - public ThermalDiffusivity toSquareMeterPerSecond() { - return toUnit(ThermalDiffusivityUnits.SQUARE_METER_PER_SECOND); + // Convert to target unit + public double getInSquareMetersPerSecond() { + return getIn(ThermalDiffusivityUnits.SQUARE_METER_PER_SECOND); } - public ThermalDiffusivity toSquareFeetPerSecond() { - return toUnit(ThermalDiffusivityUnits.SQUARE_FEET_PER_SECOND); + public double getInSquareFeetPerSecond() { + return getIn(ThermalDiffusivityUnits.SQUARE_FEET_PER_SECOND); } @Override @@ -78,6 +77,7 @@ public String toString() { return "ThermalDiffusivity{" + value + " " + unit.getSymbol() + '}'; } + // Static factory methods public static ThermalDiffusivity of(double value, Unit unit) { return new ThermalDiffusivity(value, unit); } diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivityUnits.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivityUnits.java index 9716f43..4677aeb 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivityUnits.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivityUnits.java @@ -30,12 +30,12 @@ public Unit getBaseUnit() { } @Override - public double toBaseUnit(double valueInThisUnit) { + public double toValueInBaseUnit(double valueInThisUnit) { return toBaseConverter.applyAsDouble(valueInThisUnit); } @Override - public double fromBaseToThisUnit(double valueInBaseUnit) { + public double fromValueInBaseUnit(double valueInBaseUnit) { return fromBaseToUnitConverter.applyAsDouble(valueInBaseUnit); } } diff --git a/src/test/java/com/synerset/unitility/unitsystem/PhysicalQuantityTest.java b/src/test/java/com/synerset/unitility/unitsystem/PhysicalQuantityTest.java index e2c21b8..ff240ac 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/PhysicalQuantityTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/PhysicalQuantityTest.java @@ -2,12 +2,18 @@ import com.synerset.unitility.unitsystem.common.Angle; import com.synerset.unitility.unitsystem.common.Distance; +import com.synerset.unitility.unitsystem.common.DistanceUnits; +import com.synerset.unitility.unitsystem.exceptions.UnitSystemArgumentException; import com.synerset.unitility.unitsystem.thermodynamic.Pressure; import com.synerset.unitility.unitsystem.thermodynamic.Temperature; +import com.synerset.unitility.unitsystem.thermodynamic.ThermalDiffusivity; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.util.Arrays; + import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; class PhysicalQuantityTest { @@ -17,7 +23,7 @@ void shouldBeEquals_whenBaseUnitsAndValuesAreTheSame() { // Given // When Distance distanceInMeters = Distance.ofMeters(100); - Distance distanceInMiles = distanceInMeters.toMile(); + Distance distanceInMiles = distanceInMeters.toUnit(DistanceUnits.MILE); // Then @@ -169,6 +175,18 @@ void shouldDivideValueToQuantity() { assertThat(actualTemperature).isEqualTo(exptectedTemperature); } + @Test + @DisplayName("Should throw an exception if divided by 0") + void shouldNotDivideByZeroThrowingException() { + // Given + Temperature temperature = Temperature.ofCelsius(20); + + // Then + assertThatThrownBy(() -> temperature.divide(0)) + .isInstanceOf(UnitSystemArgumentException.class) + .hasMessage("Division by zero is not allowed. Please provide a non-zero divider value."); + } + @Test @DisplayName("Should correctly divide quantities of the same type, but different units") void shouldDivideQuantityToSourceQuantity() { @@ -229,4 +247,44 @@ void shouldIndicateIfValueIsPositiveNegativeOrZero() { } + @Test + @DisplayName("Should return property unit symbol") + void shouldReturnPropertyUnitSymbol() { + // Given + ThermalDiffusivity thermalDiffusivity = ThermalDiffusivity.ofSquareFeetPerSecond(0.5); + + // When + String actualUnitSymbol = thermalDiffusivity.getUnitSymbol(); + + // Then + String expectedUnitSymbol = "ft²/s"; + assertThat(actualUnitSymbol).isEqualTo(expectedUnitSymbol); + } + + @Test + @DisplayName("Should properly sort all quantities in the list") + void shouldSortQuantitiesInTheList() { + // Given + Temperature[] temperatures = { + Temperature.ofCelsius(54), + Temperature.ofKelvins(10), + Temperature.ofCelsius(-20), + Temperature.ofCelsius(100) + }; + + // When + Arrays.sort(temperatures); + + // Then + Temperature[] correctOrderTemperatures = { + Temperature.ofKelvins(10), + Temperature.ofCelsius(-20), + Temperature.ofCelsius(54), + Temperature.ofCelsius(100) + }; + + assertThat(temperatures).isEqualTo(correctOrderTemperatures); + + } + } \ No newline at end of file diff --git a/src/test/java/com/synerset/unitility/unitsystem/common/AngleTest.java b/src/test/java/com/synerset/unitility/unitsystem/common/AngleTest.java index fe9090f..cc72350 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/common/AngleTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/common/AngleTest.java @@ -15,13 +15,17 @@ void shouldProperlyConvertFromDegreeToRadian() { Angle initialAngleInDegrees = Angle.ofDegrees(45); // When - Angle actualInRadians = initialAngleInDegrees.toRadians(); - Angle actualInDegrees = actualInRadians.toBaseUnit(); + Angle actualInRadians = initialAngleInDegrees.toUnit(AngleUnits.RADIANS); + double actualRadiansVal = initialAngleInDegrees.getInRadians(); + Angle actualInDegrees = actualInRadians.toUnit(AngleUnits.DEGREES); + double actualInDegreesVal = actualInRadians.getInDegrees(); // Then Angle expectedRadian = Angle.of(Math.PI/4, AngleUnits.RADIANS); assertThat(actualInRadians).isEqualTo(expectedRadian); - assertThat(actualInDegrees).isEqualTo(initialAngleInDegrees); + assertThat(actualRadiansVal).isEqualTo(actualInRadians.getValue()); + assertThat(actualRadiansVal).isEqualTo(actualInRadians.getValue()); + assertThat(actualInDegrees.getValue()).isEqualTo(actualInDegreesVal); } @Test diff --git a/src/test/java/com/synerset/unitility/unitsystem/common/AreaTest.java b/src/test/java/com/synerset/unitility/unitsystem/common/AreaTest.java index 16af6c3..9b928f5 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/common/AreaTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/common/AreaTest.java @@ -16,12 +16,16 @@ void shouldProperlyConvertSquareMetersToSquareKilometers() { Area initialArea = Area.ofSquareMeters(1_000_000); // When - Area actualInSquareKilometers = initialArea.toSquareKilometers(); + Area actualInSquareKilometers = initialArea.toUnit(AreaUnits.SQUARE_KILOMETER); + double actualSquareKilometersVal = initialArea.getInSquareKilometers(); Area actualInSquareMeters = actualInSquareKilometers.toBaseUnit(); + double actualInSquareMetersVal = actualInSquareKilometers.getInSquareMeters(); // Then Area expectedInSquareKilometers = Area.ofSquareKilometers(1); assertThat(actualInSquareKilometers).isEqualTo(expectedInSquareKilometers); + assertThat(actualInSquareKilometers.getValue()).isEqualTo(actualSquareKilometersVal); + assertThat(actualInSquareMeters.getValue()).isEqualTo(actualInSquareMetersVal); assertThat(actualInSquareMeters).isEqualTo(initialArea); } @@ -32,12 +36,14 @@ void shouldProperlyConvertSquareMetersToSquareCentimeters() { Area initialArea = Area.ofSquareMeters(1); // When - Area actualInSquareCentimeters = initialArea.toSquareCentimeters(); + Area actualInSquareCentimeters = initialArea.toUnit(AreaUnits.SQUARE_CENTIMETER); + double actualSquareCentimetersVal = initialArea.getInSquareCentimeters(); Area actualInSquareMeters = actualInSquareCentimeters.toBaseUnit(); // Then Area expectedInSquareCentimeters = Area.ofSquareCentimeters(10_000); assertThat(actualInSquareCentimeters).isEqualTo(expectedInSquareCentimeters); + assertThat(actualInSquareCentimeters.getValue()).isEqualTo(actualSquareCentimetersVal); assertThat(actualInSquareMeters).isEqualTo(initialArea); } @@ -48,11 +54,13 @@ void shouldProperlyConvertSquareMetersToSquareMillimeters() { Area initialArea = Area.ofSquareMeters(1); // When - Area actualInSquareMillimeters = initialArea.toSquareMillimeters(); + Area actualInSquareMillimeters = initialArea.toUnit(AreaUnits.SQUARE_MILLIMETER); + double actualInSquareMillimetersVal = initialArea.getInSquareMillimeters(); Area actualInSquareMeters = actualInSquareMillimeters.toBaseUnit(); // Then Area expectedInSquareMillimeters = Area.ofSquareMillimeters(1_000_000); + assertThat(actualInSquareMillimeters.getValue()).isEqualTo(actualInSquareMillimetersVal); assertThat(actualInSquareMillimeters).isEqualTo(expectedInSquareMillimeters); assertThat(actualInSquareMeters).isEqualTo(initialArea); } @@ -64,11 +72,13 @@ void shouldProperlyConvertSquareMetersToAres() { Area initialArea = Area.ofSquareMeters(1); // When - Area actualInAres = initialArea.toAres(); + Area actualInAres = initialArea.toUnit(AreaUnits.ARE); + double actualInAresVal = initialArea.getInAres(); Area actualInSquareMeters = actualInAres.toBaseUnit(); // Then Area expectedInAres = Area.ofAres(0.01); + assertThat(actualInAres.getValue()).isEqualTo(actualInAresVal); assertThat(actualInAres).isEqualTo(expectedInAres); assertThat(actualInSquareMeters).isEqualTo(initialArea); } @@ -80,11 +90,13 @@ void shouldProperlyConvertSquareMetersToHectares() { Area initialArea = Area.ofSquareMeters(10_000); // When - Area actualInHectares = initialArea.toHectares(); - Area actualInSquareMeters = actualInHectares.toSquareMeters(); + Area actualInHectares = initialArea.toUnit(AreaUnits.HECTARE); + double actualInHectaresVal = initialArea.getInHectares(); + Area actualInSquareMeters = actualInHectares.toBaseUnit(); // Then Area expectedInHectares = Area.ofHectares(1); + assertThat(actualInHectares.getValue()).isEqualTo(actualInHectaresVal); assertThat(actualInHectares).isEqualTo(expectedInHectares); assertThat(actualInSquareMeters).isEqualTo(initialArea); } @@ -96,11 +108,13 @@ void shouldProperlyConvertSquareMetersToSquareInches() { Area initialArea = Area.ofSquareMeters(1); // When - Area actualInSquareInches = initialArea.toSquareInches(); + Area actualInSquareInches = initialArea.toUnit(AreaUnits.SQUARE_INCH); + double actualInSquareInchesVal = initialArea.getInSquareInches(); Area actualInSquareMeters = actualInSquareInches.toBaseUnit(); // Then Area expectedInSquareInches = Area.ofSquareInches(1550.0031000062); + assertThat(expectedInSquareInches.getValue()).isEqualTo(actualInSquareInchesVal, withPrecision(10E-10)); assertThat(actualInSquareInches.getValue()).isEqualTo(expectedInSquareInches.getValue(), withPrecision(2E-13)); assertThat(actualInSquareMeters).isEqualTo(initialArea); } @@ -112,11 +126,13 @@ void shouldProperlyConvertSquareMetersToSquareFeet() { Area initialArea = Area.ofSquareMeters(100); // When - Area actualInSquareFeet = initialArea.toSquareFeet(); + Area actualInSquareFeet = initialArea.toUnit(AreaUnits.SQUARE_FOOT); + double actualInSquareFeetVal = initialArea.getInSquareFeet(); Area actualInSquareMeters = actualInSquareFeet.toBaseUnit(); // Then Area expectedInSquareFeet = Area.ofSquareFeet(1076.391041670972); + assertThat(actualInSquareFeet.getValue()).isEqualTo(actualInSquareFeetVal); assertThat(actualInSquareFeet.getValue()).isEqualTo(expectedInSquareFeet.getValue(), withPrecision(1E-15)); assertThat(actualInSquareMeters.getValue()).isEqualTo(initialArea.getValue(), withPrecision(1E-14)); } @@ -128,11 +144,13 @@ void shouldProperlyConvertSquareMetersToSquareYards() { Area initialArea = Area.ofSquareMeters(100); // When - Area actualInSquareYards = initialArea.toSquareYards(); + Area actualInSquareYards = initialArea.toUnit(AreaUnits.SQUARE_YARD); + double actualInSquareYardsVal = initialArea.getInSquareYards(); Area actualInSquareMeters = actualInSquareYards.toBaseUnit(); // Then Area expectedInSquareYards = Area.ofSquareYards(119.599004630108); + assertThat(actualInSquareYards.getValue()).isEqualTo(actualInSquareYardsVal); assertThat(actualInSquareYards.getValue()).isEqualTo(expectedInSquareYards.getValue(), withPrecision(1E-13)); assertThat(actualInSquareMeters).isEqualTo(initialArea); } @@ -144,11 +162,13 @@ void shouldProperlyConvertSquareMetersToAcres() { Area initialArea = Area.ofSquareMeters(100); // When - Area actualInAcres = initialArea.toAcres(); + Area actualInAcres = initialArea.toUnit(AreaUnits.ACRE); + double actualInAcresVal = initialArea.getInAcres(); Area actualInSquareMeters = actualInAcres.toBaseUnit(); // Then Area expectedInAcres = Area.ofSquareYards(0.0247105381467165); + assertThat(actualInAcres.getValue()).isEqualTo(actualInAcresVal); assertThat(actualInAcres.getValue()).isEqualTo(expectedInAcres.getValue(), withPrecision(1E-15)); assertThat(actualInSquareMeters).isEqualTo(initialArea); } @@ -160,11 +180,13 @@ void shouldProperlyConvertSquareMetersToSquareMiles() { Area initialArea = Area.ofSquareMeters(100_000); // When - Area actualInSquareMiles = initialArea.toSquareMiles(); + Area actualInSquareMiles = initialArea.toUnit(AreaUnits.SQUARE_MILE); + double actualInSquareMilesVal = initialArea.getInSquareMiles(); Area actualInSquareMeters = actualInSquareMiles.toBaseUnit(); // Then Area expectedInSquareMiles = Area.ofSquareMiles(0.0386102158542446); + assertThat(actualInSquareMiles.getValue()).isEqualTo(actualInSquareMilesVal); assertThat(actualInSquareMiles.getValue()).isEqualTo(expectedInSquareMiles.getValue(), withPrecision(1E-15)); assertThat(actualInSquareMeters).isEqualTo(initialArea); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/common/DistanceTest.java b/src/test/java/com/synerset/unitility/unitsystem/common/DistanceTest.java index 2301984..2f37cd5 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/common/DistanceTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/common/DistanceTest.java @@ -15,11 +15,15 @@ void shouldProperlyConvertToMetersFromMillimeters() { Distance initialDistanceInMillimeters = Distance.ofMillimeters(1000.0); // When - Distance actualInMeters = initialDistanceInMillimeters.toBaseUnit(); + Distance actualInMeters = initialDistanceInMillimeters.toUnit(DistanceUnits.METER); + double actualInMetersVal = actualInMeters.getInMeters(); Distance actualInMillimeters = actualInMeters.toUnit(DistanceUnits.MILLIMETER); + double actualInMillimetersVal = actualInMeters.getInMillimeters(); // Then Distance expectedInMeters = Distance.ofMeters(1.0); + assertThat(actualInMeters.getValue()).isEqualTo(actualInMetersVal); + assertThat(actualInMillimeters.getValue()).isEqualTo(actualInMillimetersVal); assertThat(actualInMeters).isEqualTo(expectedInMeters); assertThat(actualInMillimeters).isEqualTo(initialDistanceInMillimeters); } @@ -33,9 +37,11 @@ void shouldProperlyConvertToMetersFromCentimeters() { // When Distance actualInMeters = initialDistanceInCentimeters.toBaseUnit(); Distance actualInCentimeters = actualInMeters.toUnit(DistanceUnits.CENTIMETER); + double actualInCentimetersVal = actualInMeters.getInCentimeters(); // Then Distance expectedInMeters = Distance.ofMeters(1.0); + assertThat(actualInCentimeters.getValue()).isEqualTo(actualInCentimetersVal); assertThat(actualInMeters).isEqualTo(expectedInMeters); assertThat(actualInCentimeters).isEqualTo(initialDistanceInCentimeters); } @@ -49,9 +55,11 @@ void shouldProperlyConvertToMetersFromKilometers() { // When Distance actualInMeters = initialDistanceInKilometers.toBaseUnit(); Distance actualInKilometers = actualInMeters.toUnit(DistanceUnits.KILOMETER); + double actualInKilometersVal = actualInMeters.getInKilometers(); // Then Distance expectedInMeters = Distance.ofMeters(1000.0); + assertThat(actualInKilometers.getValue()).isEqualTo(actualInKilometersVal); assertThat(actualInMeters).isEqualTo(expectedInMeters); assertThat(actualInKilometers).isEqualTo(initialDistanceInKilometers); } @@ -65,9 +73,11 @@ void shouldProperlyConvertToMetersFromMile() { // When Distance actualInMeters = initialDistanceInMiles.toBaseUnit(); Distance actualInMiles = actualInMeters.toUnit(DistanceUnits.MILE); + double actualInMilesVal = actualInMeters.getInMiles(); // Then Distance expectedInMeters = Distance.ofMeters(1609.344); + assertThat(actualInMiles.getValue()).isEqualTo(actualInMilesVal); assertThat(actualInMeters).isEqualTo(expectedInMeters); assertThat(actualInMiles).isEqualTo(initialDistanceInMiles); } @@ -81,9 +91,11 @@ void shouldProperlyConvertToMetersFromFeet() { // When Distance actualInMeters = initialDistanceInFeet.toBaseUnit(); Distance actualInFeet = actualInMeters.toUnit(DistanceUnits.FEET); + double actualInFeetVal = actualInMeters.getInFeet(); // Then Distance expectedInMeters = Distance.ofMeters(3.048); + assertThat(actualInFeet.getValue()).isEqualTo(actualInFeetVal); assertThat(actualInMeters).isEqualTo(expectedInMeters); assertThat(actualInFeet).isEqualTo(initialDistanceInFeet); } @@ -97,9 +109,11 @@ void shouldProperlyConvertToMetersFromInch() { // When Distance actualInMeters = initialDistanceInInch.toBaseUnit(); Distance actualInInch = actualInMeters.toUnit(DistanceUnits.INCH); + double actualInInchVal = actualInMeters.getInInches(); // Then Distance expectedInMeters = Distance.ofMeters(0.254); + assertThat(actualInInch.getValue()).isEqualTo(actualInInchVal); assertThat(actualInMeters).isEqualTo(expectedInMeters); assertThat(actualInInch).isEqualTo(initialDistanceInInch); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/common/MassTest.java b/src/test/java/com/synerset/unitility/unitsystem/common/MassTest.java index 5b185ba..a9b2642 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/common/MassTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/common/MassTest.java @@ -18,9 +18,13 @@ void shouldProperlyConvertToKilogramsFromGrams() { // When Mass actualInKilograms = initialMassInGrams.toUnit(MassUnits.KILOGRAM); Mass actualInGrams = actualInKilograms.toUnit(MassUnits.GRAM); + double actualInGramsVal = actualInKilograms.getIntoGrams(); + double actualInKilogramsVal = initialMassInGrams.getInKilograms(); // Then Mass expectedInKilograms = Mass.ofKilograms(1.0); + assertThat(actualInGrams.getValue()).isEqualTo(actualInGramsVal); + assertThat(actualInKilograms.getValue()).isEqualTo(actualInKilogramsVal); assertThat(actualInKilograms).isEqualTo(expectedInKilograms); assertThat(actualInGrams).isEqualTo(initialMassInGrams); } @@ -34,9 +38,11 @@ void shouldProperlyConvertToKilogramsFromTonneSi() { // When Mass actualInKilograms = initialMassInTonneSi.toBaseUnit(); Mass actualInTonneSi = actualInKilograms.toUnit(MassUnits.TONNE_SI); + double actualInTonneSiVal = actualInKilograms.getIntoTonnesSI(); // Then Mass expectedInKilograms = Mass.ofKilograms(1000.0); + assertThat(actualInTonneSi.getValue()).isEqualTo(actualInTonneSiVal); assertThat(actualInKilograms).isEqualTo(expectedInKilograms); assertThat(actualInTonneSi).isEqualTo(initialMassInTonneSi); } @@ -45,14 +51,16 @@ void shouldProperlyConvertToKilogramsFromTonneSi() { @DisplayName("should convert to kg from mg and vice versa") void shouldProperlyConvertToKilogramsFromMilligrams() { // Given - Mass initialMassInMilligrams = Mass.ofMiligrams(1000.0); + Mass initialMassInMilligrams = Mass.ofMilligrams(1000.0); // When Mass actualInKilograms = initialMassInMilligrams.toBaseUnit(); Mass actualInMilligrams = actualInKilograms.toUnit(MassUnits.MILLIGRAM); + double actualInMilligramsVal = actualInKilograms.getInMilligrams(); // Then Mass expectedInKilograms = Mass.ofKilograms(0.001); + assertThat(actualInMilligrams.getValue()).isEqualTo(actualInMilligramsVal); assertThat(actualInKilograms).isEqualTo(expectedInKilograms); assertThat(actualInMilligrams.getValue()).isEqualTo(initialMassInMilligrams.getValue(), withPrecision(1E-13)); } @@ -66,9 +74,11 @@ void shouldProperlyConvertToKilogramsFromOunces() { // When Mass actualInKilograms = initialMassInOunces.toUnit(MassUnits.KILOGRAM); Mass actualInOunces = actualInKilograms.toUnit(MassUnits.OUNCE); + double actualInOuncesVal = actualInKilograms.getIntoOunces(); // Then Mass expectedInKilograms = Mass.ofKilograms(0.28349523125); + assertThat(actualInOunces.getValue()).isEqualTo(actualInOuncesVal); assertThat(actualInKilograms.getValue()).isEqualTo(expectedInKilograms.getValue(), withPrecision(1E-15)); assertThat(actualInOunces).isEqualTo(initialMassInOunces); } @@ -82,9 +92,11 @@ void shouldProperlyConvertToKilogramsFromPounds() { // When Mass actualInKilograms = initialMassInPounds.toUnit(MassUnits.KILOGRAM); Mass actualInPounds = actualInKilograms.toUnit(MassUnits.POUND); + double actualInPoundsVal = actualInKilograms.getInPounds(); // Then Mass expectedInKilograms = Mass.ofKilograms(4.5359237); + assertThat(actualInPounds.getValue()).isEqualTo(actualInPoundsVal); assertThat(actualInKilograms.getValue()).isEqualTo(expectedInKilograms.getValue(), withPrecision(1E-15)); assertThat(actualInPounds).isEqualTo(initialMassInPounds); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/common/VelocityTest.java b/src/test/java/com/synerset/unitility/unitsystem/common/VelocityTest.java index ca90ca6..f99a6bb 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/common/VelocityTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/common/VelocityTest.java @@ -16,11 +16,15 @@ void shouldProperlyConvertMetersPerSecondToCentimetersPerSecond() { Velocity initialVelocity = Velocity.ofMetersPerSecond(10.0); // When - Velocity actualInCentimetersPerSec = initialVelocity.toCentimetersPerSecond(); + Velocity actualInCentimetersPerSec = initialVelocity.toUnit(VelocityUnits.CENTIMETER_PER_SECOND); + double actualInCentimetersPerSecVal = initialVelocity.toCentimetersPerSeconds(); Velocity actualInMetersPerSecond = actualInCentimetersPerSec.toBaseUnit(); + double actualInMetersPerSecondVal = actualInCentimetersPerSec.toMetersPerSecond(); // Then Velocity expectedInKilometersPerHour = Velocity.ofCentimetersPerSecond(1000.0); + assertThat(actualInCentimetersPerSec.getValue()).isEqualTo(actualInCentimetersPerSecVal); + assertThat(actualInMetersPerSecond.getValue()).isEqualTo(actualInMetersPerSecondVal); assertThat(actualInCentimetersPerSec).isEqualTo(expectedInKilometersPerHour); assertThat(actualInMetersPerSecond).isEqualTo(initialVelocity); } @@ -32,11 +36,13 @@ void shouldProperlyConvertMetersPerSecondToKilometersPerHour() { Velocity initialVelocity = Velocity.ofMetersPerSecond(10.0); // When - Velocity actualInKilometersPerHour = initialVelocity.toKilometersPerHour(); + Velocity actualInKilometersPerHour = initialVelocity.toUnit(VelocityUnits.KILOMETER_PER_HOUR); + double actualInKilometersPerHourVal = initialVelocity.toKilometersPerHours(); Velocity actualInMetersPerSecond = actualInKilometersPerHour.toBaseUnit(); // Then Velocity expectedInKilometersPerHour = Velocity.ofKilometersPerHour(36.0); + assertThat(actualInKilometersPerHour.getValue()).isEqualTo(actualInKilometersPerHourVal); assertThat(actualInKilometersPerHour).isEqualTo(expectedInKilometersPerHour); assertThat(actualInMetersPerSecond).isEqualTo(initialVelocity); } @@ -48,11 +54,13 @@ void shouldProperlyConvertMetersPerSecondToInchesPerSecond() { Velocity initialVelocity = Velocity.ofMetersPerSecond(10.0); // When - Velocity actualInInchesPerSec = initialVelocity.toInchesPerSecond(); + Velocity actualInInchesPerSec = initialVelocity.toUnit(VelocityUnits.INCH_PER_SECOND); + double actualInInchesPerSecVal = initialVelocity.toInchesPerSeconds(); Velocity actualInMetersPerSecond = actualInInchesPerSec.toBaseUnit(); // Then Velocity expectedInInchesPerSec = Velocity.ofInchesPerSecond(393.7007874015748); + assertThat(actualInInchesPerSec.getValue()).isEqualTo(actualInInchesPerSecVal); assertThat(actualInInchesPerSec.getValue()).isEqualTo(expectedInInchesPerSec.getValue(), withPrecision(1e-15)); assertThat(actualInMetersPerSecond).isEqualTo(initialVelocity); } @@ -64,11 +72,13 @@ void shouldProperlyConvertMetersPerSecondToFeetPerSecond() { Velocity initialVelocity = Velocity.ofMetersPerSecond(10.0); // When - Velocity actualInFeetPerSecond = initialVelocity.toFeetPerSecond(); + Velocity actualInFeetPerSecond = initialVelocity.toUnit(VelocityUnits.FEET_PER_SECOND); + double actualInFeetPerSecondVal = initialVelocity.toFeetPerSeconds(); Velocity actualInMetersPerSecond = actualInFeetPerSecond.toBaseUnit(); // Then Velocity expectedInFeetPerSecond = Velocity.ofFeetPerSecond(32.80839895013123); + assertThat(actualInFeetPerSecond.getValue()).isEqualTo(actualInFeetPerSecondVal); assertThat(actualInFeetPerSecond.getValue()).isEqualTo(expectedInFeetPerSecond.getValue(), withPrecision(1e-14)); assertThat(actualInMetersPerSecond).isEqualTo(initialVelocity); } @@ -80,11 +90,13 @@ void shouldProperlyConvertMetersPerSecondToMilesPerHour() { Velocity initialVelocity = Velocity.ofMetersPerSecond(10.0); // When - Velocity actualInMilesPerHour = initialVelocity.toMilesPerHour(); + Velocity actualInMilesPerHour = initialVelocity.toUnit(VelocityUnits.MILES_PER_HOUR); + double actualInMilesPerHourVal = initialVelocity.toMilesPerHours(); Velocity actualInMetersPerSecond = actualInMilesPerHour.toBaseUnit(); // Then Velocity expectedInMilesPerHour = Velocity.ofMilesPerHour(22.36936292054402); + assertThat(actualInMilesPerHour.getValue()).isEqualTo(actualInMilesPerHourVal); assertThat(actualInMilesPerHour.getValue()).isEqualTo(expectedInMilesPerHour.getValue(), withPrecision(1e-14)); assertThat(actualInMetersPerSecond).isEqualTo(initialVelocity); } @@ -96,11 +108,13 @@ void shouldProperlyConvertMetersPerSecondToKnots() { Velocity initialVelocity = Velocity.ofMetersPerSecond(10.0); // When - Velocity actualInKnots = initialVelocity.toKnots(); + Velocity actualInKnots = initialVelocity.toUnit(VelocityUnits.KNOTS); + double actualInKnotsVal = initialVelocity.toKnots(); Velocity actualInMetersPerSecond = actualInKnots.toBaseUnit(); // Then Velocity expectedInKnots = Velocity.ofKnots(19.43844492440606); + assertThat(actualInKnots.getValue()).isEqualTo(actualInKnotsVal); assertThat(actualInKnots.getValue()).isEqualTo(expectedInKnots.getValue(), withPrecision(1e-14)); assertThat(actualInMetersPerSecond).isEqualTo(initialVelocity); } @@ -112,11 +126,13 @@ void shouldProperlyConvertMetersPerSecondToMach() { Velocity initialVelocity = Velocity.ofMetersPerSecond(100.0); // When - Velocity actualInMach = initialVelocity.toMach(); + Velocity actualInMach = initialVelocity.toUnit(VelocityUnits.MACH); + double actualInMachVal = initialVelocity.toMach(); Velocity actualInMetersPerSecond = actualInMach.toBaseUnit(); // Then Velocity expectedInMachs = Velocity.ofMach(0.293866995797702); + assertThat(actualInMach.getValue()).isEqualTo(actualInMachVal); assertThat(actualInMach.getValue()).isEqualTo(expectedInMachs.getValue(), withPrecision(1e-14)); assertThat(actualInMetersPerSecond).isEqualTo(initialVelocity); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/common/VolumeTest.java b/src/test/java/com/synerset/unitility/unitsystem/common/VolumeTest.java index 03c8e3a..876586a 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/common/VolumeTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/common/VolumeTest.java @@ -18,9 +18,13 @@ void shouldProperlyConvertToCubicMeterFromLiter() { // When Volume actualInCubicMeter = initialVolumeInLiter.toBaseUnit(); Volume actualInLiter = actualInCubicMeter.toUnit(VolumeUnits.LITER); + double actualInLiterVal = actualInCubicMeter.getInLiters(); + double actualInCubicMeterVal = initialVolumeInLiter.getInCubicMeters(); // Then Volume expectedInCubicMeter = Volume.ofCubicMeters(1.0); + assertThat(actualInLiter.getValue()).isEqualTo(actualInLiterVal); + assertThat(actualInCubicMeter.getValue()).isEqualTo(actualInCubicMeterVal); assertThat(actualInCubicMeter).isEqualTo(expectedInCubicMeter); assertThat(actualInLiter).isEqualTo(initialVolumeInLiter); } @@ -33,12 +37,14 @@ void shouldProperlyConvertToCubicMeterFromCubicCentimeter() { // When Volume actualInCubicMeter = initialVolumeInCubicCentimeters.toBaseUnit(); - Volume actualInLiter = actualInCubicMeter.toCubicCentimeter(); + Volume actualInCubicCM = actualInCubicMeter.toUnit(VolumeUnits.CUBIC_CENTIMETER); + double actualInCubicCMVal = actualInCubicMeter.getInCubicCentimeters(); // Then Volume expectedInCubicMeter = Volume.ofCubicMeters(1.0); + assertThat(actualInCubicCM.getValue()).isEqualTo(actualInCubicCMVal); assertThat(actualInCubicMeter).isEqualTo(expectedInCubicMeter); - assertThat(actualInLiter).isEqualTo(initialVolumeInCubicCentimeters); + assertThat(actualInCubicCM).isEqualTo(initialVolumeInCubicCentimeters); } @Test @@ -48,12 +54,14 @@ void shouldProperlyConvertToCubicMetersFromHectoLiters() { Volume initialVolumeInHectoLiters = Volume.ofHectoLiters(10.0); // When - Volume actualInCubicMeters = initialVolumeInHectoLiters.toBaseUnit(); - Volume actualInHectoLiters = actualInCubicMeters.toHectoLiter(); + Volume actualInCubicMeter = initialVolumeInHectoLiters.toBaseUnit(); + Volume actualInHectoLiters = actualInCubicMeter.toUnit(VolumeUnits.HECTOLITRE); + double actualInHectoLitersVal = actualInCubicMeter.getInHectoLiters(); // Then Volume expectedInCubicMeters = Volume.ofCubicMeters(1.0); - assertThat(actualInCubicMeters).isEqualTo(expectedInCubicMeters); + assertThat(actualInHectoLiters.getValue()).isEqualTo(actualInHectoLitersVal); + assertThat(actualInCubicMeter).isEqualTo(expectedInCubicMeters); assertThat(actualInHectoLiters).isEqualTo(initialVolumeInHectoLiters); } @@ -65,10 +73,12 @@ void shouldProperlyConvertToCubicMeterFromMilliliter() { // When Volume actualInCubicMeter = initialVolumeInMilliliter.toBaseUnit(); - Volume actualInMilliliter = actualInCubicMeter.toMilliLiter(); + Volume actualInMilliliter = actualInCubicMeter.toUnit(VolumeUnits.MILLILITRE); + double actualInMilliliterVal = actualInCubicMeter.getInMilliLiters(); // Then Volume expectedInCubicMeter = Volume.ofCubicMeters(100); + assertThat(actualInMilliliter.getValue()).isEqualTo(actualInMilliliterVal); assertThat(actualInCubicMeter.getValue()).isEqualTo(expectedInCubicMeter.getValue(), withPrecision(1E-15)); assertThat(actualInMilliliter).isEqualTo(initialVolumeInMilliliter); } @@ -81,10 +91,12 @@ void shouldProperlyConvertToCubicMeterFromPint() { // When Volume actualInCubicMeter = initialVolumeInPint.toBaseUnit(); - Volume actualInPint = actualInCubicMeter.toPint(); + Volume actualInPint = actualInCubicMeter.toUnit(VolumeUnits.PINT); + double actualInPintVal = actualInCubicMeter.getInPints(); // Then Volume expectedInCubicMeter = Volume.ofCubicMeters(0.473176473); + assertThat(actualInPint.getValue()).isEqualTo(actualInPintVal); assertThat(actualInCubicMeter.getValue()).isEqualTo(expectedInCubicMeter.getValue(), withPrecision(1E-15)); assertThat(actualInPint).isEqualTo(initialVolumeInPint); } @@ -97,10 +109,12 @@ void shouldProperlyConvertToCubicMeterFromGallon() { // When Volume actualInCubicMeter = initialVolumeInGallon.toBaseUnit(); - Volume actualInGallon = actualInCubicMeter.toGallon(); + Volume actualInGallon = actualInCubicMeter.toUnit(VolumeUnits.GALLON); + double actualInGallonVal = actualInCubicMeter.getInGallons(); // Then Volume expectedInCubicMeter = Volume.ofCubicMeters(3.785411784); + assertThat(actualInGallon.getValue()).isEqualTo(actualInGallonVal); assertThat(actualInCubicMeter.getValue()).isEqualTo(expectedInCubicMeter.getValue(), withPrecision(1E-15)); assertThat(actualInGallon).isEqualTo(initialVolumeInGallon); } @@ -112,12 +126,14 @@ void shouldProperlyConvertToCubicMetersFromOunce() { Volume initialVolumeInOunces = Volume.ofOunces(10.0); // When - Volume actualInCubicMeters = initialVolumeInOunces.toBaseUnit(); - Volume actualInOunces = actualInCubicMeters.toOunce(); + Volume actualInCubicMeter = initialVolumeInOunces.toBaseUnit(); + Volume actualInOunces = actualInCubicMeter.toUnit(VolumeUnits.OUNCE); + double actualInOuncesVal = actualInCubicMeter.getInOunces(); // Then Volume expectedInCubicMeters = Volume.ofCubicMeters(0.000295735295625); - assertThat(actualInCubicMeters.getValue()).isEqualTo(expectedInCubicMeters.getValue(), withPrecision(1E-15)); + assertThat(actualInOunces.getValue()).isEqualTo(actualInOuncesVal); + assertThat(actualInCubicMeter.getValue()).isEqualTo(expectedInCubicMeters.getValue(), withPrecision(1E-15)); assertThat(actualInOunces).isEqualTo(initialVolumeInOunces); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactorTest.java b/src/test/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactorTest.java new file mode 100644 index 0000000..d769c06 --- /dev/null +++ b/src/test/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactorTest.java @@ -0,0 +1,27 @@ +package com.synerset.unitility.unitsystem.dimensionless; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class BypassFactorTest { + + @Test + @DisplayName("should create By-pass factor") + void shouldCreatBypassFactor() { + // Given + double expectedValue = 0.2; + + // When + BypassFactor actualBypassFactor = BypassFactor.of(expectedValue); + + // Then + BypassFactor expectedBypassFactor = BypassFactor.of(0.2); + assertThat(actualBypassFactor.getValue()).isEqualTo(expectedValue); + assertThat(actualBypassFactor.toUnit(BypassFactorUnits.DIMENSIONLESS)).isEqualTo(actualBypassFactor.toBaseUnit()); + assertThat(actualBypassFactor.getBaseValue()).isEqualTo(actualBypassFactor.getValue()); + assertThat(actualBypassFactor).isEqualTo(expectedBypassFactor); + } + +} diff --git a/src/test/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumberTest.java b/src/test/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumberTest.java index 36c8b83..c8ec64e 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumberTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumberTest.java @@ -18,6 +18,8 @@ void shouldCreateGrashofNumber(){ // Then GrashofNumber expectedGrashofNumber = GrashofNumber.of(10.0); assertThat(actualGrashofNumber.getValue()).isEqualTo(expectedValue); + assertThat(actualGrashofNumber.getBaseValue()).isEqualTo(actualGrashofNumber.getValue()); + assertThat(actualGrashofNumber.toUnit(GrashofNumberUnits.DIMENSIONLESS)).isEqualTo(actualGrashofNumber.toBaseUnit()); assertThat(actualGrashofNumber).isEqualTo(expectedGrashofNumber); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumberTest.java b/src/test/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumberTest.java index 359b7bd..8c782b5 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumberTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumberTest.java @@ -19,6 +19,8 @@ void shouldCreatePrandtlNumber(){ // Then PrandtlNumber expectedPrandtlNum = PrandtlNumber.of(10.0); assertThat(actualPrandtlNum.getValue()).isEqualTo(expectedValue); + assertThat(actualPrandtlNum.getBaseValue()).isEqualTo(actualPrandtlNum.getValue()); + assertThat(actualPrandtlNum.toUnit(PrandtlNumberUnits.DIMENSIONLESS)).isEqualTo(actualPrandtlNum.toBaseUnit()); assertThat(actualPrandtlNum).isEqualTo(expectedPrandtlNum); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumberTest.java b/src/test/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumberTest.java index dac4788..60188c2 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumberTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumberTest.java @@ -19,6 +19,8 @@ void shouldCreateReynoldsNumber(){ // Then ReynoldsNumber expectedReynoldsNumber = ReynoldsNumber.of(10.0); assertThat(actualReynoldsNumber.getValue()).isEqualTo(expectedValue); + assertThat(actualReynoldsNumber.getBaseValue()).isEqualTo(actualReynoldsNumber.getValue()); + assertThat(actualReynoldsNumber.toUnit(ReynoldsNumberUnits.DIMENSIONLESS)).isEqualTo(actualReynoldsNumber.toBaseUnit()); assertThat(actualReynoldsNumber).isEqualTo(expectedReynoldsNumber); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/flows/MassFlowTest.java b/src/test/java/com/synerset/unitility/unitsystem/flows/MassFlowTest.java index 9c953e0..a74dfab 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/flows/MassFlowTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/flows/MassFlowTest.java @@ -16,13 +16,17 @@ void shouldProperlyConvertKilogramPerSecondToKilogramPerHour() { MassFlow initialMassFlow = MassFlow.ofKilogramsPerSecond(1.5); // When - MassFlow actual_KG_PER_H = initialMassFlow.toKiloGramPerHour(); - MassFlow actual_KG_PER_S = actual_KG_PER_H.toKilogramsPerSecond(); + MassFlow actual_KG_PER_Hr = initialMassFlow.toUnit(MassFlowUnits.KILOGRAM_PER_HOUR); + double actual_KG_PER_HrVal = initialMassFlow.getInKiloGramsPerHour(); + MassFlow actual_KG_PER_Sec = actual_KG_PER_Hr.toBaseUnit(); + double actual_KG_PER_SecVal = actual_KG_PER_Hr.getInKilogramsPerSecond(); // Then MassFlow expected_KG_PER_H = MassFlow.ofKilogramsPerHour(5400); - assertThat(actual_KG_PER_H).isEqualTo(expected_KG_PER_H); - assertThat(actual_KG_PER_S).isEqualTo(initialMassFlow); + assertThat(actual_KG_PER_Hr.getValue()).isEqualTo(actual_KG_PER_HrVal); + assertThat(actual_KG_PER_Sec.getValue()).isEqualTo(actual_KG_PER_SecVal); + assertThat(actual_KG_PER_Hr).isEqualTo(expected_KG_PER_H); + assertThat(actual_KG_PER_Sec).isEqualTo(initialMassFlow); } @Test @@ -32,11 +36,13 @@ void shouldProperlyConvertKilogramPerSecondToTonnePerHour() { MassFlow initialMassFlow = MassFlow.ofKilogramsPerSecond(1.5); // When - MassFlow actual_TON_PER_H = initialMassFlow.toTonnesPerHour(); - MassFlow actual_KG_PER_S = actual_TON_PER_H.toKilogramsPerSecond(); + MassFlow actual_TON_PER_H = initialMassFlow.toUnit(MassFlowUnits.TONNE_PER_HOUR); + double actual_TON_PER_HVal = initialMassFlow.getInTonnesPerHour(); + MassFlow actual_KG_PER_S = actual_TON_PER_H.toBaseUnit(); // Then MassFlow expected_TON_PER_H = MassFlow.ofTonnesPerHour(5.4); + assertThat(actual_TON_PER_H.getValue()).isEqualTo(actual_TON_PER_HVal); assertThat(actual_TON_PER_H.getValue()).isEqualTo(expected_TON_PER_H.getValue(), withPrecision(1E-15)); assertThat(actual_KG_PER_S).isEqualTo(initialMassFlow); } @@ -48,11 +54,13 @@ void shouldProperlyConvertKilogramPerSecondToPoundPerSecond() { MassFlow initialMassFlow = MassFlow.ofKilogramsPerSecond(1.5); // When - MassFlow actual_LB_PER_S = initialMassFlow.toPoundsPerSecond(); - MassFlow actual_KG_PER_S = actual_LB_PER_S.toKilogramsPerSecond(); + MassFlow actual_LB_PER_S = initialMassFlow.toUnit(MassFlowUnits.POUND_PER_SECOND); + double actual_LB_PER_SVal = initialMassFlow.getInPoundsPerSecond(); + MassFlow actual_KG_PER_S = actual_LB_PER_S.toBaseUnit(); // Then MassFlow expected_LB_PER_S = MassFlow.ofPoundsPerSecond(3.306933932773164); + assertThat(actual_LB_PER_S.getValue()).isEqualTo(actual_LB_PER_SVal); assertThat(actual_LB_PER_S.getValue()).isEqualTo(expected_LB_PER_S.getValue(), withPrecision(1E-15)); assertThat(actual_KG_PER_S).isEqualTo(initialMassFlow); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/flows/VolumetricFlowTest.java b/src/test/java/com/synerset/unitility/unitsystem/flows/VolumetricFlowTest.java index 98a7baa..bc986cd 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/flows/VolumetricFlowTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/flows/VolumetricFlowTest.java @@ -15,11 +15,15 @@ void shouldProperlyConvertToMetersCubedPerSecondFromCubicMetersPerMinute() { VolumetricFlow initialFlowInM3pSec = VolumetricFlow.ofCubicMetersPerSecond(1.0); // When - VolumetricFlow actualFlowInM3pMin = initialFlowInM3pSec.toCubicMetersPerMinute(); + VolumetricFlow actualFlowInM3pMin = initialFlowInM3pSec.toUnit(VolumetricFlowUnits.CUBIC_METERS_PER_MINUTE); + double actualFlowInM3pMinVal = initialFlowInM3pSec.getInCubicMetersPerMinute(); VolumetricFlow actualFlowInM3pSec = actualFlowInM3pMin.toBaseUnit(); + double actualFlowInM3pSecVal = actualFlowInM3pMin.getInCubicMetersPerSecond(); // Then VolumetricFlow expectedFlowInM3pMin = VolumetricFlow.ofCubicMetersPerMinute(60.0); + assertThat(actualFlowInM3pMin.getValue()).isEqualTo(actualFlowInM3pMinVal); + assertThat(actualFlowInM3pSec.getValue()).isEqualTo(actualFlowInM3pSecVal); assertThat(actualFlowInM3pMin).isEqualTo(expectedFlowInM3pMin); assertThat(actualFlowInM3pSec).isEqualTo(initialFlowInM3pSec); } @@ -31,11 +35,13 @@ void shouldProperlyConvertToMetersCubedPerSecondFromCubicMetersPerHour() { VolumetricFlow initialFlowInM3pSec = VolumetricFlow.ofCubicMetersPerSecond(1.0); // When - VolumetricFlow actualFlowInM3pHr = initialFlowInM3pSec.toCubicMetersPerHour(); + VolumetricFlow actualFlowInM3pHr = initialFlowInM3pSec.toUnit(VolumetricFlowUnits.CUBIC_METERS_PER_HOUR); + double actualFlowInM3pHrVal = initialFlowInM3pSec.getInCubicMetersPerHour(); VolumetricFlow actualFlowInM3pSec = actualFlowInM3pHr.toBaseUnit(); // Then VolumetricFlow expectedFlowInM3pMin = VolumetricFlow.ofCubicMetersPerHour(3600.0); + assertThat(actualFlowInM3pHr.getValue()).isEqualTo(actualFlowInM3pHrVal); assertThat(actualFlowInM3pHr).isEqualTo(expectedFlowInM3pMin); assertThat(actualFlowInM3pSec).isEqualTo(initialFlowInM3pSec); } @@ -47,11 +53,13 @@ void shouldProperlyConvertToMetersCubedPerSecondFromLitrePerSecond() { VolumetricFlow initialFlowInM3pSec = VolumetricFlow.ofCubicMetersPerSecond(1.0); // When - VolumetricFlow actualFlowInLpSec = initialFlowInM3pSec.toLitresPerSecond(); + VolumetricFlow actualFlowInLpSec = initialFlowInM3pSec.toUnit(VolumetricFlowUnits.LITRE_PER_SECOND); + double actualFlowInLpSecVal = initialFlowInM3pSec.getInLitresPerSecond(); VolumetricFlow actualFlowInM3pSec = actualFlowInLpSec.toBaseUnit(); // Then VolumetricFlow expectedFlowInLpSec = VolumetricFlow.ofLitresPerSecond(1000.0); + assertThat(actualFlowInLpSec.getValue()).isEqualTo(actualFlowInLpSecVal); assertThat(actualFlowInLpSec).isEqualTo(expectedFlowInLpSec); assertThat(actualFlowInM3pSec).isEqualTo(initialFlowInM3pSec); } @@ -63,11 +71,13 @@ void shouldProperlyConvertToMetersCubedPerSecondFromLitrePerMinute() { VolumetricFlow initialFlowInM3pSec = VolumetricFlow.ofCubicMetersPerSecond(1.0); // When - VolumetricFlow actualFlowInLpMin = initialFlowInM3pSec.toLitresPerMinute(); + VolumetricFlow actualFlowInLpMin = initialFlowInM3pSec.toUnit(VolumetricFlowUnits.LITRE_PER_MINUTE); + double actualFlowInLpMinVal = initialFlowInM3pSec.getInLitresPerMinute(); VolumetricFlow actualFlowInM3pSec = actualFlowInLpMin.toBaseUnit(); // Then VolumetricFlow expectedFlowInLpMin = VolumetricFlow.ofLitresPerMinute(60000.0); + assertThat(actualFlowInLpMin.getValue()).isEqualTo(actualFlowInLpMinVal); assertThat(actualFlowInLpMin).isEqualTo(expectedFlowInLpMin); assertThat(actualFlowInM3pSec).isEqualTo(initialFlowInM3pSec); } @@ -79,11 +89,13 @@ void shouldProperlyConvertToMetersCubedPerSecondFromLitrePerHour() { VolumetricFlow initialFlowInM3pSec = VolumetricFlow.ofCubicMetersPerSecond(1.0); // When - VolumetricFlow actualFlowInLpHr = initialFlowInM3pSec.toLitresPerHour(); + VolumetricFlow actualFlowInLpHr = initialFlowInM3pSec.toUnit(VolumetricFlowUnits.LITRE_PER_HOUR); + double actualFlowInLpHrVal = initialFlowInM3pSec.getInLitresPerHour(); VolumetricFlow actualFlowInM3pSec = actualFlowInLpHr.toBaseUnit(); // Then VolumetricFlow expectedFlowInLpHr = VolumetricFlow.ofLitresPerHour(3600000.0); + assertThat(actualFlowInLpHr.getValue()).isEqualTo(actualFlowInLpHrVal); assertThat(actualFlowInLpHr).isEqualTo(expectedFlowInLpHr); assertThat(actualFlowInM3pSec).isEqualTo(initialFlowInM3pSec); } @@ -95,11 +107,13 @@ void shouldProperlyConvertToMetersCubedPerSecondFromGallonsPerSecond() { VolumetricFlow initialFlowInM3pSec = VolumetricFlow.ofCubicMetersPerSecond(1.0); // When - VolumetricFlow actualFlowInGalpSec = initialFlowInM3pSec.toGallonsPerSecond(); + VolumetricFlow actualFlowInGalpSec = initialFlowInM3pSec.toUnit(VolumetricFlowUnits.GALLONS_PER_SECOND); + double actualFlowInGalpSecVal = initialFlowInM3pSec.getInGallonsPerSecond(); VolumetricFlow actualFlowInM3pSec = actualFlowInGalpSec.toBaseUnit(); // Then VolumetricFlow expectedFlowInGalpSec = VolumetricFlow.ofGallonsPerSecond(0.2641720523581484); + assertThat(actualFlowInGalpSec.getValue()).isEqualTo(actualFlowInGalpSecVal); assertThat(actualFlowInGalpSec).isEqualTo(expectedFlowInGalpSec); assertThat(actualFlowInM3pSec).isEqualTo(initialFlowInM3pSec); } @@ -111,11 +125,13 @@ void shouldProperlyConvertToMetersCubedPerSecondFromGallonsPerMinute() { VolumetricFlow initialFlowInM3pSec = VolumetricFlow.ofCubicMetersPerSecond(1.0); // When - VolumetricFlow actualFlowInGalpMin = initialFlowInM3pSec.toGallonsPerMinute(); + VolumetricFlow actualFlowInGalpMin = initialFlowInM3pSec.toUnit(VolumetricFlowUnits.GALLONS_PER_MINUTE); + double actualFlowInGalpMinVal = initialFlowInM3pSec.getInGallonsPerMinute(); VolumetricFlow actualFlowInM3pSec = actualFlowInGalpMin.toBaseUnit(); // Then VolumetricFlow expectedFlowInGalpMin = VolumetricFlow.ofGallonsPerMinute(15.850610141490908); + assertThat(actualFlowInGalpMin.getValue()).isEqualTo(actualFlowInGalpMinVal); assertThat(actualFlowInGalpMin).isEqualTo(expectedFlowInGalpMin); assertThat(actualFlowInM3pSec).isEqualTo(initialFlowInM3pSec); } @@ -127,11 +143,13 @@ void shouldProperlyConvertToMetersCubedPerSecondFromGallonsPerHour() { VolumetricFlow initialFlowInM3PerSec = VolumetricFlow.ofCubicMetersPerSecond(1.0); // When - VolumetricFlow actualFlowInGalPerHr = initialFlowInM3PerSec.toGallonsPerHour(); + VolumetricFlow actualFlowInGalPerHr = initialFlowInM3PerSec.toUnit(VolumetricFlowUnits.GALLONS_PER_HOUR); + double actualFlowInGalPerHrVal = initialFlowInM3PerSec.getInGallonsPerHour(); VolumetricFlow actualFlowInM3PerSec = actualFlowInGalPerHr.toBaseUnit(); // Then VolumetricFlow expectedFlowInGalPerHr = VolumetricFlow.ofGallonsPerHour(951.0366084894545); + assertThat(actualFlowInGalPerHr.getValue()).isEqualTo(actualFlowInGalPerHrVal); assertThat(actualFlowInGalPerHr).isEqualTo(expectedFlowInGalPerHr); assertThat(actualFlowInM3PerSec).isEqualTo(initialFlowInM3PerSec); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/humidity/HumidityRatioTest.java b/src/test/java/com/synerset/unitility/unitsystem/humidity/HumidityRatioTest.java index f8fe7b5..c6edfd4 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/humidity/HumidityRatioTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/humidity/HumidityRatioTest.java @@ -18,13 +18,18 @@ void shouldProperlyConvertFromKgKgToLbLb() { // When HumidityRatio actualInLbPerLb = initialHumidityRatio.toUnit(HumidityRatioUnits.POUND_PER_POUND); + double actualInLbPerLbVal = initialHumidityRatio.getInPoundPerPound(); HumidityRatio actualInKgPerKg = actualInLbPerLb.toBaseUnit(); + double actualInKgPerKgVal = actualInLbPerLb.getInKilogramPerKilogram(); // Then HumidityRatio expectedInLbPerLb = HumidityRatio.of(0.033069339826536, HumidityRatioUnits.POUND_PER_POUND); assertThat(actualInKgPerKg.getValue()).isEqualTo(initialValue); + assertThat(actualInLbPerLb.getValue()).isEqualTo(actualInLbPerLbVal); + assertThat(actualInKgPerKg.getValue()).isEqualTo(actualInKgPerKgVal); assertThat(actualInLbPerLb.getValue()).isEqualTo(expectedInLbPerLb.getValue(), withPrecision(1E-9)); assertThat(actualInKgPerKg.getUnit()).isEqualTo(HumidityRatioUnits.KILOGRAM_PER_KILOGRAM); + assertThat(initialHumidityRatio).isEqualTo(HumidityRatio.ofKilogramPerKilogram(initialValue)); } @Test diff --git a/src/test/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidityTest.java b/src/test/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidityTest.java index 4acf353..d3e1157 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidityTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidityTest.java @@ -14,11 +14,15 @@ void shouldProperlyConvertPascalToPsi() { RelativeHumidity initialHumidity = RelativeHumidity.ofPercentage(50.5); // When - RelativeHumidity actualInDecimal = initialHumidity.toDecimal(); - RelativeHumidity actualInPercent = actualInDecimal.toPercent(); + RelativeHumidity actualInDecimal = initialHumidity.toUnit(RelativeHumidityUnits.DECIMAL); + double actualInDecimalVal = initialHumidity.getInDecimal(); + RelativeHumidity actualInPercent = actualInDecimal.toBaseUnit(); + double actualInPercentVal = actualInDecimal.getInPercent(); // Then RelativeHumidity expectedInDecimal = RelativeHumidity.ofDecimal(0.505); + assertThat(actualInDecimal.getValue()).isEqualTo(actualInDecimalVal); + assertThat(actualInPercent.getValue()).isEqualTo(actualInPercentVal); assertThat(actualInDecimal).isEqualTo(expectedInDecimal); assertThat(actualInPercent).isEqualTo(initialHumidity); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/mechanical/ForceTest.java b/src/test/java/com/synerset/unitility/unitsystem/mechanical/ForceTest.java index cfd0f20..e0b464c 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/mechanical/ForceTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/mechanical/ForceTest.java @@ -14,12 +14,17 @@ class ForceTest { void shouldProperlyConvertNewtonsToKiloNewtons() { // Given Force initialForce = Force.ofNewtons(1000); + // When - Force actualInKiloNewtons = initialForce.toKiloNewtons(); + Force actualInKiloNewtons = initialForce.toUnit(ForceUnits.KILONEWTON); + double actualInKiloNewtonsVal = initialForce.getInKiloNewtons(); Force actualInNewtons = actualInKiloNewtons.toBaseUnit(); + double actualInNewtonsVal = actualInKiloNewtons.getInNewtons(); // Then Force expectedInKiloNewtons = Force.ofKiloNewtons(1); + assertThat(actualInKiloNewtons.getValue()).isEqualTo(actualInKiloNewtonsVal); + assertThat(actualInNewtons.getValue()).isEqualTo(actualInNewtonsVal); assertThat(actualInKiloNewtons).isEqualTo(expectedInKiloNewtons); assertThat(actualInNewtons).isEqualTo(initialForce); } @@ -31,11 +36,13 @@ void shouldProperlyConvertNewtonsToKiloPonds() { Force initialForce = Force.ofNewtons(1000); // When - Force actualInKiloPonds = initialForce.toKiloponds(); - Force actualInNewtons = actualInKiloPonds.toNewtons(); + Force actualInKiloPonds = initialForce.toUnit(ForceUnits.KILOPOND); + double actualInKiloPondsVal = initialForce.getInKiloponds(); + Force actualInNewtons = actualInKiloPonds.toBaseUnit(); // Then Force expectedInKiloPonds = Force.ofKiloponds(101.97162129779283); + assertThat(actualInKiloPonds.getValue()).isEqualTo(actualInKiloPondsVal); assertThat(actualInKiloPonds.getValue()).isEqualTo(expectedInKiloPonds.getValue(), withPrecision(1E-14)); assertThat(actualInNewtons.getValue()).isEqualTo(initialForce.getValue(), withPrecision(1E-13)); } @@ -47,11 +54,13 @@ void shouldProperlyConvertNewtonsToDynes() { Force initialForce = Force.ofNewtons(1.0); // When - Force actualInDyn = initialForce.toDynes(); - Force actualInNewtons = actualInDyn.toNewtons(); + Force actualInDyn = initialForce.toUnit(ForceUnits.DYNE); + double actualInDynVal = initialForce.getInDynes(); + Force actualInNewtons = actualInDyn.toBaseUnit(); // Then Force expectedInDyn = Force.ofDynes(100_000.0); + assertThat(actualInDyn.getValue()).isEqualTo(actualInDynVal); assertThat(actualInDyn.getValue()).isEqualTo(expectedInDyn.getValue(), withPrecision(1E-11)); assertThat(actualInNewtons.getValue()).isEqualTo(initialForce.getValue(), withPrecision(1E-15)); } @@ -63,11 +72,13 @@ void shouldProperlyConvertNewtonsToPoundForce() { Force initialForce = Force.ofNewtons(1000); // When - Force actualInPoundForce = initialForce.toPoundForce(); - Force actualInNewtons = actualInPoundForce.toNewtons(); + Force actualInPoundForce = initialForce.toUnit(ForceUnits.POUND_FORCE); + double actualInPoundForceVal = initialForce.getInPoundsForce(); + Force actualInNewtons = actualInPoundForce.toBaseUnit(); // Then Force expectedInPoundForce = Force.ofPoundForce(224.8089430997105); + assertThat(actualInPoundForce.getValue()).isEqualTo(actualInPoundForceVal); assertThat(actualInPoundForce.getValue()).isEqualTo(expectedInPoundForce.getValue(), withPrecision(1E-15)); assertThat(actualInNewtons).isEqualTo(initialForce); } @@ -78,11 +89,13 @@ void shouldProperlyConvertNewtonsToPoundal() { // Given Force initialForce = Force.ofNewtons(1000); // When - Force actualInPoundal = initialForce.toPoundal(); + Force actualInPoundal = initialForce.toUnit(ForceUnits.POUNDAL); + double actualInPoundalVal = initialForce.getInPoundals(); Force actualInNewtons = actualInPoundal.toBaseUnit(); // Then Force expectedInPoundal = Force.ofPoundal(7233.013851209894); + assertThat(actualInPoundal.getValue()).isEqualTo(actualInPoundalVal); assertThat(actualInPoundal.getValue()).isEqualTo(expectedInPoundal.getValue(), withPrecision(1E-12)); assertThat(actualInNewtons).isEqualTo(initialForce); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/mechanical/MomentumTest.java b/src/test/java/com/synerset/unitility/unitsystem/mechanical/MomentumTest.java index da8ca65..0c184c4 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/mechanical/MomentumTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/mechanical/MomentumTest.java @@ -17,12 +17,16 @@ void shouldProperlyConvertToKilogramMeterPerSecondFromPoundFeetPerSecond() { // When Momentum actualInKgMPerS = initialMomentumInLbFtPerS.toUnit(MomentumUnits.KILOGRAM_METER_PER_SECOND); - Momentum actualInPoundFeetPerSecond = actualInKgMPerS.toUnit(MomentumUnits.POUND_FEET_PER_SECOND); + Momentum actualInPoundFeetPerSec = actualInKgMPerS.toUnit(MomentumUnits.POUND_FEET_PER_SECOND); + double actualInPoundFeetPerSecVal = actualInKgMPerS.getInPoundFeetPerSecond(); + double actualInKgMPerSVal = actualInPoundFeetPerSec.getInKilogramMetersPerSecond(); // Then Momentum expectedInKgMPerS = Momentum.ofKilogramMeterPerSecond(1.38254954376); + assertThat(actualInPoundFeetPerSec.getValue()).isEqualTo(actualInPoundFeetPerSecVal); + assertThat(actualInKgMPerS.getValue()).isEqualTo(actualInKgMPerSVal); assertThat(actualInKgMPerS.getValue()).isEqualTo(expectedInKgMPerS.getValue(), withPrecision(1E-15)); - assertThat(actualInPoundFeetPerSecond).isEqualTo(initialMomentumInLbFtPerS); + assertThat(actualInPoundFeetPerSec).isEqualTo(initialMomentumInLbFtPerS); } @Test @@ -34,9 +38,11 @@ void shouldProperlyConvertToKilogramMeterPerSecondFromGramCentimetrePerSecond() // When Momentum actualInKgMPerS = initialMomentumInGCmPerS.toUnit(MomentumUnits.KILOGRAM_METER_PER_SECOND); Momentum actualInGCmPerS = actualInKgMPerS.toUnit(MomentumUnits.GRAM_CENTIMETRE_PER_SECOND); + double actualInGCmPerSVal = actualInKgMPerS.getInGramCentimetersPerSecond(); // Then Momentum expectedInKgMPerS = Momentum.ofKilogramMeterPerSecond(0.01); + assertThat(actualInGCmPerS.getValue()).isEqualTo(actualInGCmPerSVal); assertThat(actualInKgMPerS).isEqualTo(expectedInKgMPerS); assertThat(actualInGCmPerS.getValue()).isEqualTo(initialMomentumInGCmPerS.getValue(), withPrecision(1E-13)); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/mechanical/TorqueTest.java b/src/test/java/com/synerset/unitility/unitsystem/mechanical/TorqueTest.java index 97b9f6b..21647bc 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/mechanical/TorqueTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/mechanical/TorqueTest.java @@ -17,10 +17,14 @@ void shouldProperlyConvertNewtonMetersToMilliNewtonMeters() { // When Torque actualInMilliNewtonMeters = initialTorque.toUnit(TorqueUnits.MILLINEWTON_METER); + double actualInMilliNewtonMetersVal = initialTorque.getInMillinewtonMeters(); Torque actualInNewtonMeters = actualInMilliNewtonMeters.toBaseUnit(); + double actualInNewtonMetersVal = actualInMilliNewtonMeters.getInNewtonMeters(); // Then Torque expectedInMilliNewtonMeters = Torque.ofMillinewtonMeters(1_000_000); + assertThat(actualInMilliNewtonMeters.getValue()).isEqualTo(actualInMilliNewtonMetersVal); + assertThat(actualInNewtonMeters.getValue()).isEqualTo(actualInNewtonMetersVal); assertThat(actualInMilliNewtonMeters).isEqualTo(expectedInMilliNewtonMeters); assertThat(actualInNewtonMeters).isEqualTo(initialTorque); } @@ -32,13 +36,15 @@ void shouldProperlyConvertNewtonMetersToKilopondMeters() { Torque initialTorque = Torque.ofNewtonMeters(1000); // When - Torque actualInKilopondMeters = initialTorque.toKilopondMeters(); + Torque actualInKilopondMeters = initialTorque.toUnit(TorqueUnits.KILOPOND_METER); + double actualInKilopondMetersVal = initialTorque.getInKilopondMeters(); Torque actualInNewtonMeters = actualInKilopondMeters.toBaseUnit(); // Then Torque expectedInKilopondMeters = Torque.ofKilopondMeters(101.9716212977928); + assertThat(actualInKilopondMeters.getValue()).isEqualTo(actualInKilopondMetersVal); assertThat(actualInKilopondMeters.getValue()).isEqualTo(expectedInKilopondMeters.getValue(), withPrecision(1E-13)); - assertThat(actualInNewtonMeters.getValue()).isEqualTo(initialTorque.getValue(),withPrecision(1E-13)); + assertThat(actualInNewtonMeters.getValue()).isEqualTo(initialTorque.getValue(), withPrecision(1E-13)); } @Test @@ -48,11 +54,13 @@ void shouldProperlyConvertNewtonMetersToFootPounds() { Torque initialTorque = Torque.ofNewtonMeters(1000); // When - Torque actualInFootPounds = initialTorque.toPoundFeet(); + Torque actualInFootPounds = initialTorque.toUnit(TorqueUnits.FOOT_POUND); + double actualInFootPoundsVal = initialTorque.getInPoundFeet(); Torque actualInNewtonMeters = actualInFootPounds.toBaseUnit(); // Then Torque expectedInFootPounds = Torque.ofFootPounds(737.56214927726536388); + assertThat(actualInFootPounds.getValue()).isEqualTo(actualInFootPoundsVal); assertThat(actualInFootPounds.getValue()).isEqualTo(expectedInFootPounds.getValue(), withPrecision(1E-13)); assertThat(actualInNewtonMeters.getValue()).isEqualTo(initialTorque.getValue(), withPrecision(1E-13)); } @@ -64,11 +72,13 @@ void shouldProperlyConvertNewtonMetersToInchPounds() { Torque initialTorque = Torque.ofNewtonMeters(1000); // When - Torque actualInInchPounds = initialTorque.toInchPounds(); + Torque actualInInchPounds = initialTorque.toUnit(TorqueUnits.INCH_POUND); + double actualInInchPoundsVal = initialTorque.getInInchPounds(); Torque actualInNewtonMeters = actualInInchPounds.toBaseUnit(); // Then Torque expectedInInchPounds = Torque.ofInchPounds(8850.74579132718436654); + assertThat(actualInInchPounds.getValue()).isEqualTo(actualInInchPoundsVal); assertThat(actualInInchPounds.getValue()).isEqualTo(expectedInInchPounds.getValue(), withPrecision(1E-10)); assertThat(actualInNewtonMeters).isEqualTo(initialTorque); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/DensityTest.java b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/DensityTest.java index 623ade1..65d0289 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/DensityTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/DensityTest.java @@ -16,11 +16,15 @@ void shouldProperlyConvertKilogramsPerCubicMeterToPoundPerCubicFoot() { Density initialDensity = Density.ofKilogramPerCubicMeter(1.2); // When - Density actualInPoundsPerCubicFoot = initialDensity.toPoundPerCubicFoot(); - Density actualInKilogramPerCubicMeter = actualInPoundsPerCubicFoot.toKilogramPerCubicMeter(); + Density actualInPoundsPerCubicFoot = initialDensity.toUnit(DensityUnits.POUND_PER_CUBIC_FOOT); + double actualInPoundsPerCubicFootVal = initialDensity.getInPoundsPerCubicFoot(); + Density actualInKilogramPerCubicMeter = actualInPoundsPerCubicFoot.toBaseUnit(); + double actualInKilogramPerCubicMeterVal = actualInPoundsPerCubicFoot.getInKilogramsPerCubicMeters(); // Then Density expectedInPoundsPerCubicFoot = Density.ofPoundPerCubicFoot(0.0749135526913747); + assertThat(actualInPoundsPerCubicFoot.getValue()).isEqualTo(actualInPoundsPerCubicFootVal); + assertThat(actualInKilogramPerCubicMeter.getValue()).isEqualTo(actualInKilogramPerCubicMeterVal); assertThat(actualInPoundsPerCubicFoot.getValue()).isEqualTo(expectedInPoundsPerCubicFoot.getValue(), withPrecision(1E-16)); assertThat(actualInKilogramPerCubicMeter.getValue()).isEqualTo(1.2, withPrecision(1E-16)); } @@ -32,11 +36,13 @@ void shouldProperlyConvertKilogramsPerCubicMeterToPoundPerCubicInch() { Density initialDensity = Density.ofKilogramPerCubicMeter(1.2); // When - Density actualInPoundsPerCubicInch = initialDensity.toUnit(DensityUnits.POUNDS_PER_CUBIC_INCH); + Density actualInPoundsPerCubicInch = initialDensity.toUnit(DensityUnits.POUND_PER_CUBIC_INCH); + double actualInPoundsPerCubicInchVal = initialDensity.getInPoundsPerCubicInches(); Density actualInKilogramPerCubicMeter = actualInPoundsPerCubicInch.toBaseUnit(); // Then - Density expectedInPoundsPerCubicInch = Density.of(0.0000433527506616, DensityUnits.POUNDS_PER_CUBIC_INCH); + Density expectedInPoundsPerCubicInch = Density.of(0.0000433527506616, DensityUnits.POUND_PER_CUBIC_INCH); + assertThat(actualInPoundsPerCubicInch.getValue()).isEqualTo(actualInPoundsPerCubicInchVal); assertThat(actualInPoundsPerCubicInch.getValue()).isEqualTo(expectedInPoundsPerCubicInch.getValue(), withPrecision(1E-16)); assertThat(actualInKilogramPerCubicMeter.getValue()).isEqualTo(1.2, withPrecision(1E-16)); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosityTest.java b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosityTest.java index 039329a..c9824eb 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosityTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosityTest.java @@ -15,11 +15,15 @@ void shouldProperlyConvertKilogramsPerMeterSecondToPoise() { DynamicViscosity initialViscosity = DynamicViscosity.ofKiloGramPerMeterSecond(100); // When - DynamicViscosity actual_Poise = initialViscosity.toPoise(); - DynamicViscosity actual_KG_PER_M_S = actual_Poise.toKiloGramPerMeterSecond(); + DynamicViscosity actual_Poise = initialViscosity.toUnit(DynamicViscosityUnits.POISE); + double actual_PoiseVal = initialViscosity.getInPoise(); + DynamicViscosity actual_KG_PER_M_S = actual_Poise.toBaseUnit(); + double actual_KG_PER_M_SVal = actual_Poise.getInKiloGramPerMeterSecond(); // Then DynamicViscosity expected_Poise = DynamicViscosity.ofPoise(1000); + assertThat(actual_Poise.getValue()).isEqualTo(actual_PoiseVal); + assertThat(actual_KG_PER_M_S.getValue()).isEqualTo(actual_KG_PER_M_SVal); assertThat(actual_Poise.getValue()).isEqualTo(expected_Poise.getValue()); assertThat(actual_KG_PER_M_S.getValue()).isEqualTo(initialViscosity.getValue()); } @@ -31,11 +35,13 @@ void shouldProperlyConvertKilogramsPerMeterSecondToPascalSecond() { DynamicViscosity initialViscosity = DynamicViscosity.ofKiloGramPerMeterSecond(100); // When - DynamicViscosity actual_PaS = initialViscosity.toPascalSecond(); - DynamicViscosity actual_KG_PER_M_S = actual_PaS.toKiloGramPerMeterSecond(); + DynamicViscosity actual_PaS = initialViscosity.toUnit(DynamicViscosityUnits.PASCAL_SECOND); + double actual_PaSVal = initialViscosity.getInPascalsSecond(); + DynamicViscosity actual_KG_PER_M_S = actual_PaS.toBaseUnit(); // Then DynamicViscosity expected_PaS = DynamicViscosity.ofPascalSecond(100); + assertThat(actual_PaS.getValue()).isEqualTo(actual_PaSVal); assertThat(actual_PaS.getValue()).isEqualTo(expected_PaS.getValue()); assertThat(actual_KG_PER_M_S.getValue()).isEqualTo(initialViscosity.getValue()); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/EnergyTest.java b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/EnergyTest.java index 9ec4e80..c0f6d35 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/EnergyTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/EnergyTest.java @@ -14,11 +14,15 @@ void shouldProperlyConvertToJoulesFromKiloJoules() { Energy initialEnergyInJoule = Energy.ofJoules(1000.0); // When - Energy actualInKiloJoule = initialEnergyInJoule.toKiloJoules(); + Energy actualInKiloJoule = initialEnergyInJoule.toUnit(EnergyUnits.KILOJOULE); + double actualInKiloJouleVal = initialEnergyInJoule.getInKiloJoules(); Energy actualInJoule = actualInKiloJoule.toBaseUnit(); + double actualInJouleVal = actualInKiloJoule.getInJoules(); // Then Energy expectedInKiloJoule = Energy.ofKiloJoules(1.0); + assertThat(actualInKiloJoule.getValue()).isEqualTo(actualInKiloJouleVal); + assertThat(actualInJoule.getValue()).isEqualTo(actualInJouleVal); assertThat(actualInKiloJoule).isEqualTo(expectedInKiloJoule); assertThat(actualInJoule).isEqualTo(initialEnergyInJoule); } @@ -30,11 +34,13 @@ void shouldProperlyConvertToJoulesFromMilliJoules() { Energy initialEnergyInJoule = Energy.ofJoules(1); // When - Energy actualInMilliJoule = initialEnergyInJoule.toMilliJoules(); + Energy actualInMilliJoule = initialEnergyInJoule.toUnit(EnergyUnits.MILLIJOULE); + double actualInMilliJouleVal = initialEnergyInJoule.getInMilliJoules(); Energy actualInJoule = actualInMilliJoule.toBaseUnit(); // Then Energy expectedInMilliJoule = Energy.ofMilliJoules(1000.0); + assertThat(actualInMilliJoule.getValue()).isEqualTo(actualInMilliJouleVal); assertThat(actualInMilliJoule).isEqualTo(expectedInMilliJoule); assertThat(actualInJoule).isEqualTo(initialEnergyInJoule); } @@ -43,48 +49,54 @@ void shouldProperlyConvertToJoulesFromMilliJoules() { @DisplayName("should convert from J to MJ and vice versa") void shouldProperlyConvertToJoulesFromMegaJoules() { // Given - Energy initialEnergyInJoules = Energy.ofJoules(1000_000.0); + Energy initialEnergyInJoule = Energy.ofJoules(1000_000.0); // When - Energy actualInMegaJoules = initialEnergyInJoules.toMegaJoules(); + Energy actualInMegaJoules = initialEnergyInJoule.toUnit(EnergyUnits.MEGAJOULE); + double actualInMegaJoulesVal = initialEnergyInJoule.getInMegaJoules(); Energy actualInJoules = actualInMegaJoules.toBaseUnit(); // Then Energy expectedInMegaJoules = Energy.ofMegaJoules(1.0); + assertThat(actualInMegaJoules.getValue()).isEqualTo(actualInMegaJoulesVal); assertThat(actualInMegaJoules).isEqualTo(expectedInMegaJoules); - assertThat(actualInJoules).isEqualTo(initialEnergyInJoules); + assertThat(actualInJoules).isEqualTo(initialEnergyInJoule); } @Test @DisplayName("should convert from J to BTU and vice versa") void shouldProperlyConvertToJoulesFromBTU() { // Given - Energy initialEnergyInJoules = Energy.ofJoules(1000.0); + Energy initialEnergyInJoule = Energy.ofJoules(1000.0); // When - Energy actualInBTU = initialEnergyInJoules.toBTU(); + Energy actualInBTU = initialEnergyInJoule.toUnit(EnergyUnits.BTU); + double actualInBTUVal = initialEnergyInJoule.getInBTUs(); Energy actualInJoules = actualInBTU.toBaseUnit(); // Then Energy expectedInBTU = Energy.ofBTU(0.9478171203133172); + assertThat(actualInBTU.getValue()).isEqualTo(actualInBTUVal); assertThat(actualInBTU).isEqualTo(expectedInBTU); - assertThat(actualInJoules).isEqualTo(initialEnergyInJoules); + assertThat(actualInJoules).isEqualTo(initialEnergyInJoule); } @Test @DisplayName("should convert from J to cal and vice versa") void shouldProperlyConvertToJoulesFromCalories() { // Given - Energy initialEnergyInJoules = Energy.ofJoules(4.184); + Energy initialEnergyInJoule = Energy.ofJoules(4.184); // When - Energy actualInCalories = initialEnergyInJoules.toCalories(); + Energy actualInCalories = initialEnergyInJoule.toUnit(EnergyUnits.CALORIE); + double actualInCaloriesVal = initialEnergyInJoule.getInCalories(); Energy actualInJoules = actualInCalories.toBaseUnit(); // Then Energy expectedInCalories = Energy.ofCalorie(1.0); + assertThat(actualInCalories.getValue()).isEqualTo(actualInCaloriesVal); assertThat(actualInCalories).isEqualTo(expectedInCalories); - assertThat(actualInJoules).isEqualTo(initialEnergyInJoules); + assertThat(actualInJoules).isEqualTo(initialEnergyInJoule); } @Test @@ -94,11 +106,13 @@ void shouldProperlyConvertToJoulesFromKilocalories() { Energy initialEnergyInJoule = Energy.ofJoules(4184.0); // When - Energy actualInKilocalorie = initialEnergyInJoule.toKiloCalories(); + Energy actualInKilocalorie = initialEnergyInJoule.toUnit(EnergyUnits.KILOCALORIE); + double actualInKilocalorieVal = initialEnergyInJoule.getInKiloCalories(); Energy actualInJoule = actualInKilocalorie.toBaseUnit(); // Then Energy expectedInKilocalorie = Energy.ofKiloCalorie(1.0); + assertThat(actualInKilocalorie.getValue()).isEqualTo(actualInKilocalorieVal); assertThat(actualInKilocalorie).isEqualTo(expectedInKilocalorie); assertThat(actualInJoule).isEqualTo(initialEnergyInJoule); } @@ -110,11 +124,13 @@ void shouldProperlyConvertToJoulesFromWattHours() { Energy initialEnergyInJoule = Energy.ofJoules(3600.0); // When - Energy actualInWattHour = initialEnergyInJoule.toWattHour(); + Energy actualInWattHour = initialEnergyInJoule.toUnit(EnergyUnits.WATT_HOUR); + double actualInWattHourVal = initialEnergyInJoule.getInWattHours(); Energy actualInJoule = actualInWattHour.toBaseUnit(); // Then Energy expectedInWattHour = Energy.ofWattHour(1.0); + assertThat(actualInWattHour.getValue()).isEqualTo(actualInWattHourVal); assertThat(actualInWattHour).isEqualTo(expectedInWattHour); assertThat(actualInJoule).isEqualTo(initialEnergyInJoule); } @@ -126,14 +142,17 @@ void shouldProperlyConvertToJoulesFromKilowattHours() { Energy initialEnergyInJoule = Energy.ofJoules(3.6e+6); // When - Energy actualInKilowattHour = initialEnergyInJoule.toKilowattHour(); + Energy actualInKilowattHour = initialEnergyInJoule.toUnit(EnergyUnits.KILOWATT_HOUR); + double actualInKiloWattHourVal = initialEnergyInJoule.getInKilowattHours(); Energy actualInJoule = actualInKilowattHour.toBaseUnit(); // Then Energy expectedInKilowattHour = Energy.ofKilowattHour(1.0); + assertThat(actualInKilowattHour.getValue()).isEqualTo(actualInKiloWattHourVal); assertThat(actualInKilowattHour).isEqualTo(expectedInKilowattHour); assertThat(actualInJoule).isEqualTo(initialEnergyInJoule); } + @Test @DisplayName("should have J as base unit") void shouldHaveJouleAsBaseUnit() { diff --git a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosityTest.java b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosityTest.java index 623270c..8edb534 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosityTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosityTest.java @@ -15,11 +15,15 @@ void shouldProperlyConvertSquareMeterPerSecondToSquareFootPerSecond() { KinematicViscosity initialKinematicViscosity = KinematicViscosity.ofSquareMeterPerSecond(1000); // When - KinematicViscosity actual_FT2_PER_SEC = initialKinematicViscosity.toSquareFootPerSecond(); - KinematicViscosity actual_M2_PER_SEC = actual_FT2_PER_SEC.toSquareMeterPerSecond(); + KinematicViscosity actual_FT2_PER_SEC = initialKinematicViscosity.toUnit(KinematicViscosityUnits.SQUARE_FOOT_PER_SECOND); + double actual_FT2_PER_SECVal = initialKinematicViscosity.getInSquareFeetPerSecond(); + KinematicViscosity actual_M2_PER_SEC = actual_FT2_PER_SEC.toBaseUnit(); + double actual_M2_PER_SECVal = actual_FT2_PER_SEC.getInSquareMetersPerSecond(); // Then KinematicViscosity expected_FT2_PER_SEC = KinematicViscosity.ofSquareFootPerSecond(10763.91041670972); + assertThat(actual_FT2_PER_SEC.getValue()).isEqualTo(actual_FT2_PER_SECVal); + assertThat(actual_M2_PER_SEC.getValue()).isEqualTo(actual_M2_PER_SECVal); assertThat(actual_FT2_PER_SEC.getValue()).isEqualTo(expected_FT2_PER_SEC.getValue(), withPrecision(1E-10)); assertThat(actual_M2_PER_SEC.getValue()).isEqualTo(initialKinematicViscosity.getValue(), withPrecision(1E-10)); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/PowerTest.java b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/PowerTest.java index 06f9315..e1cac87 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/PowerTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/PowerTest.java @@ -13,14 +13,18 @@ class PowerTest { @DisplayName("should convert W from BTU/hour and vice versa") void shouldProperlyConvertWattsFromBTUPerHour() { // Given - Power initialPower = Power.ofWatts(1000); + Power initialPowerInWatts = Power.ofWatts(1000); // When - Power actualInBTUPerHour = initialPower.toBTUPerHour(); - Power actualInWatts = actualInBTUPerHour.toWatts(); + Power actualInBTUPerHour = initialPowerInWatts.toUnit(PowerUnits.BTU_PER_HOUR); + double actualInBTUPerHourVal = initialPowerInWatts.getInBTUPerHour(); + Power actualInWatts = actualInBTUPerHour.toBaseUnit(); + double actualInWattsVal = actualInBTUPerHour.getInWatts(); // Then Power expectedInBTUPerHour = Power.ofBTUPerHour(3412.141633127942); + assertThat(actualInBTUPerHour.getValue()).isEqualTo(actualInBTUPerHourVal); + assertThat(actualInWatts.getValue()).isEqualTo(actualInWattsVal); assertThat(actualInBTUPerHour.getValue()).isEqualTo(expectedInBTUPerHour.getValue(), withPrecision(1E-14)); assertThat(actualInWatts.getValue()).isEqualTo(1000, withPrecision(1E-9)); } @@ -32,11 +36,13 @@ void shouldProperlyConvertWattsFromKiloWatts() { Power initialPowerInWatts = Power.ofWatts(10_000); // When - Power actualInKilowatts = initialPowerInWatts.toKiloWatts(); + Power actualInKilowatts = initialPowerInWatts.toUnit(PowerUnits.KILOWATT); + double actualInKilowattsVal = initialPowerInWatts.getInKiloWatts(); Power actualInWatts = actualInKilowatts.toBaseUnit(); // Then Power expectedInKiloWatts = Power.ofKiloWatts(10); + assertThat(actualInKilowatts.getValue()).isEqualTo(actualInKilowattsVal); assertThat(actualInKilowatts).isEqualTo(expectedInKiloWatts); assertThat(actualInWatts).isEqualTo(initialPowerInWatts); } @@ -48,11 +54,13 @@ void shouldProperlyConvertWattsFromMegaWatts() { Power initialPowerInWatts = Power.ofWatts(2_000_000); // When - Power actualInMegaWatts = initialPowerInWatts.toMegaWatts(); + Power actualInMegaWatts = initialPowerInWatts.toUnit(PowerUnits.MEGAWATT); + double actualInMegaWattsVal = initialPowerInWatts.getInMegaWatts(); Power actualInWatts = actualInMegaWatts.toBaseUnit(); // Then Power expectedInMegaWatts = Power.ofMegaWatts(2); + assertThat(actualInMegaWatts.getValue()).isEqualTo(actualInMegaWattsVal); assertThat(actualInMegaWatts).isEqualTo(expectedInMegaWatts); assertThat(actualInWatts).isEqualTo(initialPowerInWatts); } @@ -64,11 +72,13 @@ void shouldProperlyConvertWattsFromHorsePower() { Power initialPowerInWatts = Power.ofWatts(2000); // When - Power actualInHorsePower = initialPowerInWatts.toHorsePower(); + Power actualInHorsePower = initialPowerInWatts.toUnit(PowerUnits.HORSE_POWER); + double actualInHorsePowerVal = initialPowerInWatts.getInHorsePower(); Power actualInWatts = actualInHorsePower.toBaseUnit(); // Then Power expectedInHorsePower = Power.ofHorsePower(2.68204417919006); + assertThat(actualInHorsePower.getValue()).isEqualTo(actualInHorsePowerVal); assertThat(actualInHorsePower.getValue()).isEqualTo(expectedInHorsePower.getValue(), withPrecision(1E-13)); assertThat(actualInWatts.getValue()).isEqualTo(initialPowerInWatts.getValue(), withPrecision(1E-12)); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/PressureTest.java b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/PressureTest.java index 2774257..d289f21 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/PressureTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/PressureTest.java @@ -15,11 +15,15 @@ void shouldProperlyConvertPascalToPsi() { Pressure initialPressure = Pressure.ofPascal(101325); // When - Pressure actualInPsi = initialPressure.toPsi(); - Pressure actualInPascal = actualInPsi.toPascal(); + Pressure actualInPsi = initialPressure.toUnit(PressureUnits.PSI); + double actualInPsiVal = initialPressure.getInPsi(); + Pressure actualInPascal = actualInPsi.toBaseUnit(); + double actualInPascalVal = actualInPsi.getInPascals(); // Then Pressure expectedInPsi = Pressure.ofPsi(14.6959487755131); + assertThat(actualInPsi.getValue()).isEqualTo(actualInPsiVal); + assertThat(actualInPascal.getValue()).isEqualTo(actualInPascalVal); assertThat(actualInPsi.getValue()).isEqualTo(expectedInPsi.getValue(), withPrecision(1E-11)); assertThat(actualInPascal.getValue()).isEqualTo(101325, withPrecision(1E-11)); } @@ -31,11 +35,13 @@ void shouldProperlyConvertPascalToBar() { Pressure initialPressure = Pressure.ofPascal(101325); // When - Pressure actualInBar = initialPressure.toBar(); - Pressure actualInPascal = actualInBar.toPascal(); + Pressure actualInBar = initialPressure.toUnit(PressureUnits.BAR); + double actualInBarVal = initialPressure.getInBar(); + Pressure actualInPascal = actualInBar.toBaseUnit(); // Then Pressure expectedInBar = Pressure.ofBar(1.01325); + assertThat(actualInBar.getValue()).isEqualTo(actualInBarVal); assertThat(actualInBar.getValue()).isEqualTo(expectedInBar.getValue(), withPrecision(1E-11)); assertThat(actualInPascal.getValue()).isEqualTo(101325, withPrecision(1E-11)); } @@ -47,11 +53,13 @@ void shouldProperlyConvertPascalToHectopascal() { Pressure initialPressure = Pressure.ofPascal(101325); // When - Pressure actualInHectopascal = initialPressure.toHectoPascal(); - Pressure actualInPascal = actualInHectopascal.toPascal(); + Pressure actualInHectopascal = initialPressure.toUnit(PressureUnits.HECTOPASCAL); + double actualInHectopascalVal = initialPressure.getInHectoPascals(); + Pressure actualInPascal = actualInHectopascal.toBaseUnit(); // Then Pressure expectedInHectopascal = Pressure.ofHectoPascal(1013.25); + assertThat(actualInHectopascal.getValue()).isEqualTo(actualInHectopascalVal); assertThat(actualInHectopascal.getValue()).isEqualTo(expectedInHectopascal.getValue(), withPrecision(1E-10)); assertThat(actualInPascal.getValue()).isEqualTo(101325, withPrecision(1E-11)); } @@ -63,11 +71,13 @@ void shouldProperlyConvertPascalToMegapascal() { Pressure initialPressure = Pressure.ofPascal(101325); // When - Pressure actualInMegapascal = initialPressure.toMegaPascal(); - Pressure actualInPascal = actualInMegapascal.toPascal(); + Pressure actualInMegapascal = initialPressure.toUnit(PressureUnits.MEGAPASCAL); + double actualInMegapascalVal = initialPressure.getInMegaPascals(); + Pressure actualInPascal = actualInMegapascal.toBaseUnit(); // Then Pressure expectedInMegapascal = Pressure.ofMegaPascal(0.101325); + assertThat(actualInMegapascal.getValue()).isEqualTo(actualInMegapascalVal); assertThat(actualInMegapascal.getValue()).isEqualTo(expectedInMegapascal.getValue(), withPrecision(1E-10)); assertThat(actualInPascal.getValue()).isEqualTo(101325, withPrecision(1E-11)); } @@ -79,11 +89,13 @@ void shouldProperlyConvertPascalToMillibar() { Pressure initialPressure = Pressure.ofPascal(101325.0); // When - Pressure actualInMillibar = initialPressure.toMilliBar(); - Pressure actualInPascal = actualInMillibar.toPascal(); + Pressure actualInMillibar = initialPressure.toUnit(PressureUnits.MILLIBAR); + double actualInMillibarVal = initialPressure.getInMilliBar(); + Pressure actualInPascal = actualInMillibar.toBaseUnit(); // Then Pressure expectedInMillibar = Pressure.ofMilliBar(1013.25); + assertThat(actualInMillibar.getValue()).isEqualTo(actualInMillibarVal); assertThat(actualInMillibar).isEqualTo(expectedInMillibar); assertThat(actualInPascal).isEqualTo(initialPressure); } @@ -95,11 +107,13 @@ void shouldProperlyConvertPascalToTorr() { Pressure initialPressure = Pressure.ofPascal(101325.0); // When - Pressure actualInTorr = initialPressure.toTorr(); - Pressure actualInPascal = actualInTorr.toPascal(); + Pressure actualInTorr = initialPressure.toUnit(PressureUnits.TORR); + double actualInTorrValue = initialPressure.getInTorr(); + Pressure actualInPascal = actualInTorr.toBaseUnit(); // Then Pressure expectedInTorr = Pressure.ofTorr(759.9999999999979); + assertThat(actualInTorr.getValue()).isEqualTo(actualInTorrValue); assertThat(actualInTorr.getValue()).isEqualTo(expectedInTorr.getValue(), withPrecision(1E-15)); assertThat(actualInPascal).isEqualTo(initialPressure); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpyTest.java b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpyTest.java index 5def4c5..7276ce5 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpyTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpyTest.java @@ -16,11 +16,15 @@ void shouldProperlyConvertJoulesPerKilogramToKilojoulesPerKilogram() { SpecificEnthalpy initialSpecificEnthalpy = SpecificEnthalpy.ofJoulePerKiloGram(1000); // When - SpecificEnthalpy actual_KJ_PER_KG = initialSpecificEnthalpy.toKiloJoulePerKiloGram(); - SpecificEnthalpy actual_J_PER_KG = actual_KJ_PER_KG.toJoulePerKiloGram(); + SpecificEnthalpy actual_KJ_PER_KG = initialSpecificEnthalpy.toUnit(SpecificEnthalpyUnits.KILOJOULE_PER_KILOGRAM); + double actual_KJ_PER_KGVal = initialSpecificEnthalpy.getInKiloJoulesPerKiloGram(); + SpecificEnthalpy actual_J_PER_KG = actual_KJ_PER_KG.toBaseUnit(); + double actual_J_PER_KGVal = actual_KJ_PER_KG.getInJoulesPerKiloGram(); // Then SpecificEnthalpy expected_KJ_PER_KG = SpecificEnthalpy.ofKiloJoulePerKiloGram(1); + assertThat(actual_KJ_PER_KG.getValue()).isEqualTo(actual_KJ_PER_KGVal); + assertThat(actual_J_PER_KG.getValue()).isEqualTo(actual_J_PER_KGVal); assertThat(actual_KJ_PER_KG.getValue()).isEqualTo(expected_KJ_PER_KG.getValue()); assertThat(actual_J_PER_KG.getValue()).isEqualTo(1000); } @@ -32,11 +36,13 @@ void shouldProperlyConvertJoulesPerKilogramToBTUPerPound() { SpecificEnthalpy initialSpecificEnthalpy = SpecificEnthalpy.ofJoulePerKiloGram(1000); // When - SpecificEnthalpy actual_BTU_PER_LB = initialSpecificEnthalpy.toBTUPerPound(); - SpecificEnthalpy actual_J_PER_KG = actual_BTU_PER_LB.toJoulePerKiloGram(); + SpecificEnthalpy actual_BTU_PER_LB = initialSpecificEnthalpy.toUnit(SpecificEnthalpyUnits.BTU_PER_POUND); + double actual_BTU_PER_LBVal = initialSpecificEnthalpy.getInBTUsPerPound(); + SpecificEnthalpy actual_J_PER_KG = actual_BTU_PER_LB.toBaseUnit(); // Then SpecificEnthalpy expected_BTU_PER_LB = SpecificEnthalpy.ofBTUPerPound(0.429922614); + assertThat(actual_BTU_PER_LB.getValue()).isEqualTo(actual_BTU_PER_LBVal); assertThat(actual_BTU_PER_LB.getValue()).isEqualTo(expected_BTU_PER_LB.getValue(), withPrecision(1E-10)); assertThat(actual_J_PER_KG.getValue()).isEqualTo(1000, withPrecision(1E-10)); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeatTest.java b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeatTest.java index 4f82ef8..a7ffc8e 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeatTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeatTest.java @@ -16,11 +16,15 @@ void shouldProperlyConvertJoulesPerKilogramKelvinToKilojoulesPerKilogramKelvin() SpecificHeat initialSpecificHeat = SpecificHeat.ofJoulePerKiloGramKelvin(1000); // When - SpecificHeat actual_KJ_PER_KG_K = initialSpecificHeat.toKiloJoulePerKiloGramKelvin(); - SpecificHeat actual_J_PER_KG_K = actual_KJ_PER_KG_K.toJoulePerKiloGramKelvin(); + SpecificHeat actual_KJ_PER_KG_K = initialSpecificHeat.toUnit(SpecificHeatUnits.KILOJOULES_PER_KILOGRAM_KELVIN); + double actual_KJ_PER_KG_KVal = initialSpecificHeat.getInKiloJoulesPerKiloGramKelvin(); + SpecificHeat actual_J_PER_KG_K = actual_KJ_PER_KG_K.toBaseUnit(); + double actual_J_PER_KG_KVal = actual_KJ_PER_KG_K.getInJoulePerKiloGramKelvin(); // Then SpecificHeat expected_KJ_PER_KG_K = SpecificHeat.ofKiloJoulePerKiloGramKelvin(1); + assertThat(actual_KJ_PER_KG_K.getValue()).isEqualTo(actual_KJ_PER_KG_KVal); + assertThat(actual_J_PER_KG_K.getValue()).isEqualTo(actual_J_PER_KG_KVal); assertThat(actual_KJ_PER_KG_K.getValue()).isEqualTo(expected_KJ_PER_KG_K.getValue(), withPrecision(1E-10)); assertThat(actual_J_PER_KG_K.getValue()).isEqualTo(1000, withPrecision(1E-10)); } @@ -32,11 +36,13 @@ void shouldProperlyConvertJoulesPerKilogramKelvinToBTUPerPoundFahrenheit() { SpecificHeat initialSpecificHeat = SpecificHeat.ofJoulePerKiloGramKelvin(1000); // When - SpecificHeat actual_BTU_PER_KG_F = initialSpecificHeat.toBTUPerPoundFahrenheit(); - SpecificHeat actual_J_PER_KG_KG = actual_BTU_PER_KG_F.toJoulePerKiloGramKelvin(); + SpecificHeat actual_BTU_PER_KG_F = initialSpecificHeat.toUnit(SpecificHeatUnits.BTU_PER_POUND_FAHRENHEIT); + double actual_BTU_PER_KG_FVal = initialSpecificHeat.getInBTUsPerPoundFahrenheit(); + SpecificHeat actual_J_PER_KG_KG = actual_BTU_PER_KG_F.toBaseUnit(); // Then SpecificHeat expected_BTU_PER_KG_F = SpecificHeat.ofBTUPerPoundFahrenheit(0.2388458969999981); + assertThat(actual_BTU_PER_KG_F.getValue()).isEqualTo(actual_BTU_PER_KG_FVal); assertThat(actual_BTU_PER_KG_F.getValue()).isEqualTo(expected_BTU_PER_KG_F.getValue(), withPrecision(1E-10)); assertThat(actual_J_PER_KG_KG.getValue()).isEqualTo(1000, withPrecision(1E-10)); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/TemperatureTest.java b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/TemperatureTest.java index 9a2e45c..5b1f9fd 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/TemperatureTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/TemperatureTest.java @@ -17,9 +17,13 @@ void shouldProperlyConvertToKelvinFromCelsius() { // When Temperature actualInKelvins = initialTempInCelsius.toBaseUnit(); Temperature actualInCelsius = actualInKelvins.toUnit(TemperatureUnits.CELSIUS); + double actualInKelvinsVal = initialTempInCelsius.getInKelvins(); + double actualInCelsiusVal = actualInKelvins.getInCelsius(); // Then Temperature expectedInKelvins = Temperature.ofKelvins(20.5 + 273.15); + assertThat(actualInKelvins.getValue()).isEqualTo(actualInKelvinsVal); + assertThat(actualInCelsius.getValue()).isEqualTo(actualInCelsiusVal); assertThat(actualInKelvins).isEqualTo(expectedInKelvins); assertThat(actualInCelsius).isEqualTo(initialTempInCelsius); } @@ -31,11 +35,13 @@ void shouldProperlyConvertToKelvinFromFahrenheit() { Temperature initialTempInKelvin = Temperature.ofKelvins(273.15 + 20.5); // When - Temperature actualInFahrenheit = initialTempInKelvin.toFahrenheit(); + Temperature actualInFahrenheit = initialTempInKelvin.toUnit(TemperatureUnits.FAHRENHEIT); Temperature actualInKelvin = actualInFahrenheit.toBaseUnit(); + double actualInFahrenheitVal = actualInFahrenheit.getInFahrenheits(); // Then Temperature expectedInFahrenheit = Temperature.ofFahrenheit(68.9); + assertThat(actualInFahrenheit.getValue()).isEqualTo(actualInFahrenheitVal); assertThat(actualInFahrenheit).isEqualTo(expectedInFahrenheit); assertThat(actualInKelvin).isEqualTo(initialTempInKelvin); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivityTest.java b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivityTest.java index 66086b8..8d8b050 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivityTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivityTest.java @@ -16,11 +16,15 @@ void shouldProperlyConvertWattsPerMeterKelvinToKilowattsPerMeterKelvin() { ThermalConductivity initialUnits = ThermalConductivity.ofWattsPerMeterKelvin(1000); // When - ThermalConductivity actual_KW_PER_M_K = initialUnits.toKilowattsPerMeterKelvin(); - ThermalConductivity actual_W_PER_M_K = actual_KW_PER_M_K.toWattsPerMeterKelvin(); + ThermalConductivity actual_KW_PER_M_K = initialUnits.toUnit(ThermalConductivityUnits.KILOWATTS_PER_METER_KELVIN); + double actual_KW_PER_M_KVal = initialUnits.getInKilowattsPerMeterKelvin(); + ThermalConductivity actual_W_PER_M_K = actual_KW_PER_M_K.toBaseUnit(); + double actual_W_PER_M_KVal = actual_KW_PER_M_K.getInWattsPerMeterKelvin(); // Then ThermalConductivity expected_KW_PER_M_K = ThermalConductivity.ofKilowattsPerMeterKelvin(1); + assertThat(actual_KW_PER_M_K.getValue()).isEqualTo(actual_KW_PER_M_KVal); + assertThat(actual_W_PER_M_K.getValue()).isEqualTo(actual_W_PER_M_KVal); assertThat(actual_KW_PER_M_K.getValue()).isEqualTo(expected_KW_PER_M_K.getValue(), withPrecision(1E-10)); assertThat(actual_W_PER_M_K.getValue()).isEqualTo(1000, withPrecision(1E-10)); } @@ -32,11 +36,13 @@ void shouldProperlyConvertWattsPerMeterKelvinToBTUPerHourFootFahrenheit() { ThermalConductivity initialUnits = ThermalConductivity.ofWattsPerMeterKelvin(1000); // When - ThermalConductivity actual_BTU_PER_HR_FT_F = initialUnits.toBTUPerHourFeetFahrenheit(); - ThermalConductivity actual_W_PER_M_K = actual_BTU_PER_HR_FT_F.toWattsPerMeterKelvin(); + ThermalConductivity actual_BTU_PER_HR_FT_F = initialUnits.toUnit(ThermalConductivityUnits.BTU_PER_HOUR_FOOT_FAHRENHEIT); + double actual_BTU_PER_HR_FT_FVal = initialUnits.getInBTUsPerHourFeetFahrenheit(); + ThermalConductivity actual_W_PER_M_K = actual_BTU_PER_HR_FT_F.toBaseUnit(); // Then ThermalConductivity expected_BTU_PER_HR_FT_F = ThermalConductivity.ofBTUPerHourFeetFahrenheit(577.7891109505047); + assertThat(actual_BTU_PER_HR_FT_F.getValue()).isEqualTo(actual_BTU_PER_HR_FT_FVal); assertThat(actual_BTU_PER_HR_FT_F.getValue()).isEqualTo(expected_BTU_PER_HR_FT_F.getValue(), withPrecision(1E-10)); assertThat(actual_W_PER_M_K.getValue()).isEqualTo(1000, withPrecision(1E-10)); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivityTest.java b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivityTest.java index 52c44fb..23e1571 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivityTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivityTest.java @@ -18,9 +18,13 @@ void shouldProperlyConvertToSquareMeterPerSecondFromSquareFeetPerSecond() { // When ThermalDiffusivity actualInSquareMPerS = initialDiffSquareFtPerS.toUnit(ThermalDiffusivityUnits.SQUARE_METER_PER_SECOND); ThermalDiffusivity actualInSquareFtPerS = actualInSquareMPerS.toUnit(ThermalDiffusivityUnits.SQUARE_FEET_PER_SECOND); + double actualInSquareFtPerSVal = actualInSquareMPerS.getInSquareFeetPerSecond(); + double actualInSquareMPerSVal = actualInSquareFtPerS.getInSquareMetersPerSecond(); // Then ThermalDiffusivity expectedSquareMPerS = ThermalDiffusivity.ofSquareMeterPerSecond(0.9290304); + assertThat(actualInSquareFtPerS.getValue()).isEqualTo(actualInSquareFtPerSVal); + assertThat(actualInSquareMPerS.getValue()).isEqualTo(actualInSquareMPerSVal); assertThat(actualInSquareMPerS.getValue()).isEqualTo(expectedSquareMPerS.getValue(), withPrecision(1E-15)); assertThat(actualInSquareFtPerS).isEqualTo(initialDiffSquareFtPerS); } From 2a7458a2d183023bf856dbd3afcea8c39f06724b Mon Sep 17 00:00:00 2001 From: Piotr Jazdzyk Date: Sat, 26 Aug 2023 14:07:03 +0200 Subject: [PATCH 2/2] feat(SNSUN-24): remove "final" from classes, set constructors to "public" --- .../java/com/synerset/unitility/unitsystem/common/Angle.java | 4 ++-- .../java/com/synerset/unitility/unitsystem/common/Area.java | 4 ++-- .../com/synerset/unitility/unitsystem/common/Distance.java | 4 ++-- .../java/com/synerset/unitility/unitsystem/common/Mass.java | 4 ++-- .../com/synerset/unitility/unitsystem/common/Velocity.java | 4 ++-- .../java/com/synerset/unitility/unitsystem/common/Volume.java | 4 ++-- .../unitility/unitsystem/dimensionless/BypassFactor.java | 4 ++-- .../unitility/unitsystem/dimensionless/GrashofNumber.java | 4 ++-- .../unitility/unitsystem/dimensionless/PrandtlNumber.java | 4 ++-- .../unitility/unitsystem/dimensionless/ReynoldsNumber.java | 4 ++-- .../com/synerset/unitility/unitsystem/flows/MassFlow.java | 4 ++-- .../synerset/unitility/unitsystem/flows/VolumetricFlow.java | 4 ++-- .../synerset/unitility/unitsystem/humidity/HumidityRatio.java | 4 ++-- .../unitility/unitsystem/humidity/RelativeHumidity.java | 4 ++-- .../com/synerset/unitility/unitsystem/mechanical/Force.java | 4 ++-- .../synerset/unitility/unitsystem/mechanical/Momentum.java | 4 ++-- .../com/synerset/unitility/unitsystem/mechanical/Torque.java | 4 ++-- .../synerset/unitility/unitsystem/thermodynamic/Density.java | 4 ++-- .../unitility/unitsystem/thermodynamic/DynamicViscosity.java | 4 ++-- .../synerset/unitility/unitsystem/thermodynamic/Energy.java | 4 ++-- .../unitsystem/thermodynamic/KinematicViscosity.java | 4 ++-- .../synerset/unitility/unitsystem/thermodynamic/Power.java | 4 ++-- .../synerset/unitility/unitsystem/thermodynamic/Pressure.java | 4 ++-- .../unitility/unitsystem/thermodynamic/SpecificEnthalpy.java | 4 ++-- .../unitility/unitsystem/thermodynamic/SpecificHeat.java | 4 ++-- .../unitility/unitsystem/thermodynamic/Temperature.java | 4 ++-- .../unitsystem/thermodynamic/ThermalConductivity.java | 4 ++-- .../unitsystem/thermodynamic/ThermalDiffusivity.java | 4 ++-- .../com/synerset/unitility/unitsystem/common/AngleTest.java | 1 - .../unitility/unitsystem/utils/ValueFormatterTest.java | 2 ++ 30 files changed, 58 insertions(+), 57 deletions(-) diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/Angle.java b/src/main/java/com/synerset/unitility/unitsystem/common/Angle.java index 7a4a635..3b42bf3 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/Angle.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/Angle.java @@ -6,13 +6,13 @@ import java.util.Objects; -public final class Angle implements PhysicalQuantity { +public class Angle implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private Angle(double value, Unit unit) { + public Angle(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/Area.java b/src/main/java/com/synerset/unitility/unitsystem/common/Area.java index bce44c7..d592e48 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/Area.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/Area.java @@ -5,14 +5,14 @@ import java.util.Objects; -public final class Area implements PhysicalQuantity { +public class Area implements PhysicalQuantity { public static final Area PHYSICAL_MIN_LIMIT = Area.ofSquareMeters(0); private final double value; private final double baseValue; private final Unit unit; - private Area(double value, Unit unit) { + public Area(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/Distance.java b/src/main/java/com/synerset/unitility/unitsystem/common/Distance.java index f54bdf5..6be2a9c 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/Distance.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/Distance.java @@ -5,13 +5,13 @@ import java.util.Objects; -public final class Distance implements PhysicalQuantity { +public class Distance implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private Distance(double value, Unit unit) { + public Distance(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/Mass.java b/src/main/java/com/synerset/unitility/unitsystem/common/Mass.java index 51b1afd..66feb0f 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/Mass.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/Mass.java @@ -5,13 +5,13 @@ import java.util.Objects; -public final class Mass implements PhysicalQuantity { +public class Mass implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private Mass(double value, Unit unit) { + public Mass(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/Velocity.java b/src/main/java/com/synerset/unitility/unitsystem/common/Velocity.java index c2888ce..a44cbfa 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/Velocity.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/Velocity.java @@ -5,13 +5,13 @@ import java.util.Objects; -public final class Velocity implements PhysicalQuantity { +public class Velocity implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private Velocity(double value, Unit unit) { + public Velocity(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/common/Volume.java b/src/main/java/com/synerset/unitility/unitsystem/common/Volume.java index 5518f2a..b5979e1 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/common/Volume.java +++ b/src/main/java/com/synerset/unitility/unitsystem/common/Volume.java @@ -5,12 +5,12 @@ import java.util.Objects; -public final class Volume implements PhysicalQuantity { +public class Volume implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private Volume(double value, Unit unit) { + public Volume(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactor.java b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactor.java index 3e01b74..d9ae933 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactor.java +++ b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/BypassFactor.java @@ -5,7 +5,7 @@ import java.util.Objects; -public final class BypassFactor implements PhysicalQuantity { +public class BypassFactor implements PhysicalQuantity { public static final BypassFactor BYPASS_MIN_VALUE = BypassFactor.of(0); public static final BypassFactor BYPASS_MAX_VALUE = BypassFactor.of(1); @@ -14,7 +14,7 @@ public final class BypassFactor implements PhysicalQuantity { private final double baseValue; private final Unit unit; - private BypassFactor(double value) { + public BypassFactor(double value) { this.value = value; this.unit = BypassFactorUnits.DIMENSIONLESS; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumber.java b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumber.java index c4dfdc4..785101c 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumber.java +++ b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/GrashofNumber.java @@ -5,12 +5,12 @@ import java.util.Objects; -public final class GrashofNumber implements PhysicalQuantity { +public class GrashofNumber implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private GrashofNumber(double value) { + public GrashofNumber(double value) { this.value = value; this.unit = GrashofNumberUnits.DIMENSIONLESS; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumber.java b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumber.java index b3ef7cb..967dcb1 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumber.java +++ b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/PrandtlNumber.java @@ -5,12 +5,12 @@ import java.util.Objects; -public final class PrandtlNumber implements PhysicalQuantity { +public class PrandtlNumber implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private PrandtlNumber(double value) { + public PrandtlNumber(double value) { this.value = value; this.unit = PrandtlNumberUnits.DIMENSIONLESS; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumber.java b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumber.java index c0d0a96..c6a32be 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumber.java +++ b/src/main/java/com/synerset/unitility/unitsystem/dimensionless/ReynoldsNumber.java @@ -5,7 +5,7 @@ import java.util.Objects; -public final class ReynoldsNumber implements PhysicalQuantity { +public class ReynoldsNumber implements PhysicalQuantity { public static final ReynoldsNumber PIPE_TURBULENT_THRESHOLD = ReynoldsNumber.of(2300); public static final ReynoldsNumber PLATE_TURBULENT_THRESHOLD = ReynoldsNumber.of(5 * 10E5); @@ -14,7 +14,7 @@ public final class ReynoldsNumber implements PhysicalQuantity { private final double baseValue; private final Unit unit; - private ReynoldsNumber(double value) { + public ReynoldsNumber(double value) { this.value = value; this.unit = ReynoldsNumberUnits.DIMENSIONLESS; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/flows/MassFlow.java b/src/main/java/com/synerset/unitility/unitsystem/flows/MassFlow.java index 0cc27ba..1cca448 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/flows/MassFlow.java +++ b/src/main/java/com/synerset/unitility/unitsystem/flows/MassFlow.java @@ -5,13 +5,13 @@ import java.util.Objects; -public final class MassFlow implements PhysicalQuantity { +public class MassFlow implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private MassFlow(double value, Unit unit) { + public MassFlow(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/flows/VolumetricFlow.java b/src/main/java/com/synerset/unitility/unitsystem/flows/VolumetricFlow.java index c23fbac..7dd2cd2 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/flows/VolumetricFlow.java +++ b/src/main/java/com/synerset/unitility/unitsystem/flows/VolumetricFlow.java @@ -5,13 +5,13 @@ import java.util.Objects; -public final class VolumetricFlow implements PhysicalQuantity { +public class VolumetricFlow implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private VolumetricFlow(double value, Unit unit) { + public VolumetricFlow(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/humidity/HumidityRatio.java b/src/main/java/com/synerset/unitility/unitsystem/humidity/HumidityRatio.java index 7db6497..1b70e56 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/humidity/HumidityRatio.java +++ b/src/main/java/com/synerset/unitility/unitsystem/humidity/HumidityRatio.java @@ -5,14 +5,14 @@ import java.util.Objects; -public final class HumidityRatio implements PhysicalQuantity { +public class HumidityRatio implements PhysicalQuantity { public static final RelativeHumidity HUM_RATIO_MIN_LIMIT = RelativeHumidity.ofPercentage(0); private final double value; private final double baseValue; private final Unit unit; - private HumidityRatio(double value, Unit unit) { + public HumidityRatio(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidity.java b/src/main/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidity.java index 2f79abb..8107e57 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidity.java +++ b/src/main/java/com/synerset/unitility/unitsystem/humidity/RelativeHumidity.java @@ -5,7 +5,7 @@ import java.util.Objects; -public final class RelativeHumidity implements PhysicalQuantity { +public class RelativeHumidity implements PhysicalQuantity { public static final RelativeHumidity RH_MIN_LIMIT = RelativeHumidity.ofPercentage(0); public static final RelativeHumidity RH_MAX_LIMIT = RelativeHumidity.ofPercentage(100); @@ -13,7 +13,7 @@ public final class RelativeHumidity implements PhysicalQuantity unit; - private RelativeHumidity(double value, Unit unit) { + public RelativeHumidity(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/mechanical/Force.java b/src/main/java/com/synerset/unitility/unitsystem/mechanical/Force.java index a3c7d38..4695159 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/mechanical/Force.java +++ b/src/main/java/com/synerset/unitility/unitsystem/mechanical/Force.java @@ -5,13 +5,13 @@ import java.util.Objects; -public final class Force implements PhysicalQuantity { +public class Force implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private Force(double value, Unit unit) { + public Force(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/mechanical/Momentum.java b/src/main/java/com/synerset/unitility/unitsystem/mechanical/Momentum.java index 3af35d3..cb367bb 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/mechanical/Momentum.java +++ b/src/main/java/com/synerset/unitility/unitsystem/mechanical/Momentum.java @@ -5,13 +5,13 @@ import java.util.Objects; -public final class Momentum implements PhysicalQuantity { +public class Momentum implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private Momentum(double value, Unit unit) { + public Momentum(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/mechanical/Torque.java b/src/main/java/com/synerset/unitility/unitsystem/mechanical/Torque.java index 4d7d7f7..8fcc7b0 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/mechanical/Torque.java +++ b/src/main/java/com/synerset/unitility/unitsystem/mechanical/Torque.java @@ -5,14 +5,14 @@ import java.util.Objects; -public final class Torque implements PhysicalQuantity { +public class Torque implements PhysicalQuantity { public static final Torque PHYSICAL_MIN_LIMIT = Torque.ofNewtonMeters(0); private final double value; private final double baseValue; private final Unit unit; - private Torque(double value, Unit unit) { + public Torque(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Density.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Density.java index 45c8c51..71f0879 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Density.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Density.java @@ -5,13 +5,13 @@ import java.util.Objects; -public final class Density implements PhysicalQuantity { +public class Density implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private Density(double value, Unit unit) { + public Density(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosity.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosity.java index c2f1013..1dfafc0 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosity.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/DynamicViscosity.java @@ -5,13 +5,13 @@ import java.util.Objects; -public final class DynamicViscosity implements PhysicalQuantity { +public class DynamicViscosity implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private DynamicViscosity(double value, Unit unit) { + public DynamicViscosity(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Energy.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Energy.java index 3025b9b..f7091b4 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Energy.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Energy.java @@ -5,13 +5,13 @@ import java.util.Objects; -public final class Energy implements PhysicalQuantity { +public class Energy implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private Energy(double value, Unit unit) { + public Energy(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosity.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosity.java index f23f860..a1749a4 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosity.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/KinematicViscosity.java @@ -5,13 +5,13 @@ import java.util.Objects; -public final class KinematicViscosity implements PhysicalQuantity { +public class KinematicViscosity implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private KinematicViscosity(double value, Unit unit) { + public KinematicViscosity(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Power.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Power.java index 0a346fd..879c3c8 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Power.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Power.java @@ -5,12 +5,12 @@ import java.util.Objects; -public final class Power implements PhysicalQuantity { +public class Power implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private Power(double value, Unit unit) { + public Power(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Pressure.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Pressure.java index 76e5aa9..81f38ea 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Pressure.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Pressure.java @@ -5,7 +5,7 @@ import java.util.Objects; -public final class Pressure implements PhysicalQuantity { +public class Pressure implements PhysicalQuantity { public static final Pressure STANDARD_ATMOSPHERE = Pressure.ofPascal(101_325); public static final Pressure TECHNICAL_ATMOSPHERE = Pressure.ofPascal(98_067); @@ -13,7 +13,7 @@ public final class Pressure implements PhysicalQuantity { private final double baseValue; private final Unit unit; - private Pressure(double value, Unit unit) { + public Pressure(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpy.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpy.java index e8b8689..2217b82 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpy.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificEnthalpy.java @@ -5,12 +5,12 @@ import java.util.Objects; -public final class SpecificEnthalpy implements PhysicalQuantity { +public class SpecificEnthalpy implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private SpecificEnthalpy(double value, Unit unit) { + public SpecificEnthalpy(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeat.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeat.java index ab23521..5a8c11d 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeat.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/SpecificHeat.java @@ -5,12 +5,12 @@ import java.util.Objects; -public final class SpecificHeat implements PhysicalQuantity { +public class SpecificHeat implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private SpecificHeat(double value, Unit unit) { + public SpecificHeat(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Temperature.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Temperature.java index 614ede3..341be45 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Temperature.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/Temperature.java @@ -6,14 +6,14 @@ import java.util.Objects; -public final class Temperature implements PhysicalQuantity { +public class Temperature implements PhysicalQuantity { public static final Temperature PHYSICAL_MIN_LIMIT = Temperature.ofKelvins(0); private final double value; private final double baseValue; private final Unit unit; - private Temperature(double value, Unit unit) { + public Temperature(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivity.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivity.java index c1ebcd7..b9b3e6f 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivity.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalConductivity.java @@ -5,12 +5,12 @@ import java.util.Objects; -public final class ThermalConductivity implements PhysicalQuantity { +public class ThermalConductivity implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private ThermalConductivity(double value, Unit unit) { + public ThermalConductivity(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivity.java b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivity.java index 4f4d2a9..8e14fb1 100644 --- a/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivity.java +++ b/src/main/java/com/synerset/unitility/unitsystem/thermodynamic/ThermalDiffusivity.java @@ -5,13 +5,13 @@ import java.util.Objects; -public final class ThermalDiffusivity implements PhysicalQuantity { +public class ThermalDiffusivity implements PhysicalQuantity { private final double value; private final double baseValue; private final Unit unit; - private ThermalDiffusivity(double value, Unit unit) { + public ThermalDiffusivity(double value, Unit unit) { this.value = value; this.unit = unit; this.baseValue = unit.toValueInBaseUnit(value); diff --git a/src/test/java/com/synerset/unitility/unitsystem/common/AngleTest.java b/src/test/java/com/synerset/unitility/unitsystem/common/AngleTest.java index cc72350..d1fd229 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/common/AngleTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/common/AngleTest.java @@ -24,7 +24,6 @@ void shouldProperlyConvertFromDegreeToRadian() { Angle expectedRadian = Angle.of(Math.PI/4, AngleUnits.RADIANS); assertThat(actualInRadians).isEqualTo(expectedRadian); assertThat(actualRadiansVal).isEqualTo(actualInRadians.getValue()); - assertThat(actualRadiansVal).isEqualTo(actualInRadians.getValue()); assertThat(actualInDegrees.getValue()).isEqualTo(actualInDegreesVal); } diff --git a/src/test/java/com/synerset/unitility/unitsystem/utils/ValueFormatterTest.java b/src/test/java/com/synerset/unitility/unitsystem/utils/ValueFormatterTest.java index ded99da..e471bcc 100644 --- a/src/test/java/com/synerset/unitility/unitsystem/utils/ValueFormatterTest.java +++ b/src/test/java/com/synerset/unitility/unitsystem/utils/ValueFormatterTest.java @@ -40,4 +40,6 @@ static Stream testDoubleSeed() { ); } + + } \ No newline at end of file