Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

<properties>
<!-- MODULES VERSION -->
<project.version>2.11.0</project.version>
<project.version>2.11.1</project.version>

<!-- Maven Properties -->
<maven.compiler.source>17</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
package com.synerset.unitility.unitsystem.common;

import com.synerset.unitility.unitsystem.CalculableQuantity;
import com.synerset.unitility.unitsystem.PhysicalQuantity;

import java.util.Objects;

public class Thickness implements CalculableQuantity<DistanceUnit, Thickness> {

public static final Thickness PHYSICAL_MIN_LIMIT = Thickness.ofMeters(0);
private final double value;
private final double baseValue;
private final DistanceUnit unitType;

public Thickness(double value, DistanceUnit unitType) {
this.value = value;
if (unitType == null) {
unitType = DistanceUnits.METER;
}
this.unitType = unitType;
this.baseValue = unitType.toValueInBaseUnit(value);
}

// Static factory methods
public static Thickness of(double value, DistanceUnit unit) {
return new Thickness(value, unit);
}

public static Thickness of(double value, String unitSymbol) {
DistanceUnit resolvedUnit = DistanceUnits.fromSymbol(unitSymbol);
return new Thickness(value, resolvedUnit);
}

public static Thickness ofMeters(double value) {
return new Thickness(value, DistanceUnits.METER);
}

public static Thickness ofCentimeters(double value) {
return new Thickness(value, DistanceUnits.CENTIMETER);
}

public static Thickness ofMillimeters(double value) {
return new Thickness(value, DistanceUnits.MILLIMETER);
}

public static Thickness ofKilometers(double value) {
return new Thickness(value, DistanceUnits.KILOMETER);
}

public static Thickness ofMiles(double value) {
return new Thickness(value, DistanceUnits.MILE);
}

public static Thickness ofNauticalMiles(double value) {
return new Thickness(value, DistanceUnits.NAUTICAL_MILE);
}

public static Thickness ofFeet(double value) {
return new Thickness(value, DistanceUnits.FEET);
}

public static Thickness ofInches(double value) {
return new Thickness(value, DistanceUnits.INCH);
}

@Override
public double getValue() {
return value;
}

@Override
public double getBaseValue() {
return baseValue;
}

@Override
public DistanceUnit getUnit() {
return unitType;
}

@Override
public Thickness toBaseUnit() {
double valueInBaseUnit = unitType.toValueInBaseUnit(value);
return of(valueInBaseUnit, unitType.getBaseUnit());
}

@Override
public Thickness toUnit(DistanceUnit targetUnit) {
double valueInMeters = unitType.toValueInBaseUnit(value);
double valueInTargetUnit = targetUnit.fromValueInBaseUnit(valueInMeters);
return Thickness.of(valueInTargetUnit, targetUnit);
}

@Override
public Thickness toUnit(String targetUnit) {
DistanceUnit resolvedUnit = DistanceUnits.fromSymbol(targetUnit);
return toUnit(resolvedUnit);
}

@Override
public Thickness withValue(double value) {
return Thickness.of(value, unitType);
}

// Convert to target unit
public Thickness toMeter() {
return toUnit(DistanceUnits.METER);
}

public Thickness toCentimeter() {
return toUnit(DistanceUnits.CENTIMETER);
}

public Thickness toMillimeter() {
return toUnit(DistanceUnits.MILLIMETER);
}

public Thickness toKilometer() {
return toUnit(DistanceUnits.KILOMETER);
}

public Thickness toMile() {
return toUnit(DistanceUnits.MILE);
}

public Thickness toNauticalMile() {
return toUnit(DistanceUnits.NAUTICAL_MILE);
}

public Thickness toFeet() {
return toUnit(DistanceUnits.FEET);
}

public Thickness toInch() {
return toUnit(DistanceUnits.INCH);
}

// Get value in target unit
public double getInMeters() {
return getInUnit(DistanceUnits.METER);
}

public double getInCentimeters() {
return getInUnit(DistanceUnits.CENTIMETER);
}

public double getInMillimeters() {
return getInUnit(DistanceUnits.MILLIMETER);
}

public double getInKilometers() {
return getInUnit(DistanceUnits.KILOMETER);
}

public double getInMiles() {
return getInUnit(DistanceUnits.MILE);
}

public double getInNauticalMiles() {
return getInUnit(DistanceUnits.NAUTICAL_MILE);
}

public double getInFeet() {
return getInUnit(DistanceUnits.FEET);
}

public double getInInches() {
return getInUnit(DistanceUnits.INCH);
}

public static Thickness of(PhysicalQuantity<? extends DistanceUnit> distanceType) {
return Thickness.of(distanceType.getValue(), distanceType.getUnit());
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Thickness inputQuantity = (Thickness) o;
return Double.compare(inputQuantity.toBaseUnit().getValue(), baseValue) == 0 && Objects.equals(unitType.getBaseUnit(), inputQuantity.getUnit().getBaseUnit());
}

@Override
public int hashCode() {
return Objects.hash(baseValue, unitType.getBaseUnit());
}

@Override
public String toString() {
return "Thickness{" + value + " " + unitType.getSymbol() + '}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public static Velocity ofFeetPerSecond(double value) {
return new Velocity(value, VelocityUnits.FEET_PER_SECOND);
}

public static Velocity ofFeetPerMinute(double value) {
return new Velocity(value, VelocityUnits.FEET_PER_MINUTE);
}

public static Velocity ofMilesPerHour(double value) {
return new Velocity(value, VelocityUnits.MILES_PER_HOUR);
}
Expand Down Expand Up @@ -121,6 +125,10 @@ public Velocity toFeetPerSecond() {
return toUnit(VelocityUnits.FEET_PER_SECOND);
}

public Velocity toFeetPerMinute() {
return toUnit(VelocityUnits.FEET_PER_MINUTE);
}

public Velocity toMilesPerHour() {
return toUnit(VelocityUnits.MILES_PER_HOUR);
}
Expand Down Expand Up @@ -154,6 +162,10 @@ public double getInFeetPerSeconds() {
return getInUnit(VelocityUnits.FEET_PER_SECOND);
}

public double getInFeetPerMinutes() {
return getInUnit(VelocityUnits.FEET_PER_MINUTE);
}

public double getInMilesPerHours() {
return getInUnit(VelocityUnits.MILES_PER_HOUR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum VelocityUnits implements VelocityUnit {
KILOMETER_PER_HOUR("km/h", val -> val / 3.6, val -> val * 3.6),
INCH_PER_SECOND("in/s", val -> val * 0.0254, val -> val / 0.0254),
FEET_PER_SECOND("ft/s", val -> val * 0.3048, val -> val / 0.3048),
FEET_PER_MINUTE("ft/min", val -> val * 0.00508, val -> val / 0.00508),
MILES_PER_HOUR("mph", val -> val * 0.44704, val -> val / 0.44704),
KNOT("kn", val -> val * 0.514444444444444, val -> val / 0.514444444444444),
MACH("Mach", val -> val * 340.29, val -> val / 340.29);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static Volume ofGallonsUK(double value) {
}

public static Volume ofCubicFeet(double value) { // New method
return new Volume(value, VolumeUnits.CUBIC_FEET);
return new Volume(value, VolumeUnits.CUBIC_FOOT);
}

@Override
Expand Down Expand Up @@ -154,7 +154,7 @@ public Volume toGallonUK() {
}

public Volume toCubicFeet() { // New method
return toUnit(VolumeUnits.CUBIC_FEET);
return toUnit(VolumeUnits.CUBIC_FOOT);
}

// Get value in target unit
Expand Down Expand Up @@ -199,7 +199,7 @@ public double getInGallonsUK() {
}

public double getInCubicFeet() { // New method
return getInUnit(VolumeUnits.CUBIC_FEET);
return getInUnit(VolumeUnits.CUBIC_FOOT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public enum VolumeUnits implements VolumeUnit {
CUBIC_METER("m³", val -> val, val -> val),
CUBIC_CENTIMETER("cm³", val -> val * 0.000001, val -> val * 1000000.0),
CUBIC_DECIMETER("dm³", val -> val * 0.001, val -> val * 1000.0),
CUBIC_FEET("ft³", val -> val * 0.0283168466, val -> val / 0.0283168466),
CUBIC_FOOT("ft³", val -> val * 0.0283168466, val -> val / 0.0283168466),
LITRE("l", val -> val * 0.001, val -> val * 1000.0),
HECTOLITRE("hl", val -> val * 0.1, val -> val * 10.0),
MILLILITRE("ml", val -> val * 0.000001, val -> val * 1000000.0),
Expand Down
Loading