Denis Thiessen
2 years ago
commit
f0f3da45c5
226 changed files with 4851 additions and 0 deletions
-
4.gitignore
-
28pom.xml
-
49src/main/java/dev/controlmaster/TestMain.java
-
6src/main/java/dev/controlmaster/base/Constants.java
-
85src/main/java/dev/controlmaster/base/UnitConverter.java
-
39src/main/java/dev/controlmaster/models/UnitModel.java
-
14src/main/java/dev/controlmaster/models/unitparser/IUnitParser.java
-
21src/main/java/dev/controlmaster/models/unitparser/UnitParsingProvider.java
-
203src/main/java/dev/controlmaster/models/unitparser/UnitParsingReferences.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/angles/DegreeAngleUnitParser.java
-
38src/main/java/dev/controlmaster/models/unitparser/parser/angles/RadiantAngleUnitParser.java
-
39src/main/java/dev/controlmaster/models/unitparser/parser/areas/HectareUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/areas/SquareMeterUnitParser.java
-
53src/main/java/dev/controlmaster/models/unitparser/parser/colors/CmykUnitParser.java
-
46src/main/java/dev/controlmaster/models/unitparser/parser/colors/HexUnitParser.java
-
49src/main/java/dev/controlmaster/models/unitparser/parser/colors/HslUnitParser.java
-
52src/main/java/dev/controlmaster/models/unitparser/parser/colors/HsvUnitParser.java
-
50src/main/java/dev/controlmaster/models/unitparser/parser/colors/RgbUnitParser.java
-
24src/main/java/dev/controlmaster/models/unitparser/parser/datastorage/BitUnitParser.java
-
39src/main/java/dev/controlmaster/models/unitparser/parser/datastorage/ByteUnitParser.java
-
39src/main/java/dev/controlmaster/models/unitparser/parser/datastorage/GigabyteUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/datastorage/KilobyteUnitParser.java
-
39src/main/java/dev/controlmaster/models/unitparser/parser/datastorage/MegabyteUnitParser.java
-
38src/main/java/dev/controlmaster/models/unitparser/parser/datastorage/TerabyteUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/fuelconsumption/LitersPer100KilometerUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/fuelconsumption/MilesPerImperialGallonUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/fuelconsumption/MilesPerUSGallonUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/lengths/FootUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/lengths/InchUnitParser.java
-
39src/main/java/dev/controlmaster/models/unitparser/parser/lengths/KilometerUnitParser.java
-
39src/main/java/dev/controlmaster/models/unitparser/parser/lengths/MeterUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/lengths/MileUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/lengths/MillimeterUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/lengths/YardUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/temparatures/CelsiusUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/temparatures/FahrenheitUnitParser.java
-
39src/main/java/dev/controlmaster/models/unitparser/parser/temparatures/KelvinUnitParser.java
-
39src/main/java/dev/controlmaster/models/unitparser/parser/temparatures/RankineUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/temparatures/RomerUnitParser.java
-
38src/main/java/dev/controlmaster/models/unitparser/parser/time/HourUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/time/MillisecondUnitParser.java
-
38src/main/java/dev/controlmaster/models/unitparser/parser/time/MinuteUnitParser.java
-
39src/main/java/dev/controlmaster/models/unitparser/parser/time/SecondUnitParser.java
-
38src/main/java/dev/controlmaster/models/unitparser/parser/volume/FluidOunceUnitParser.java
-
38src/main/java/dev/controlmaster/models/unitparser/parser/volume/ImperialGallonUnitParser.java
-
38src/main/java/dev/controlmaster/models/unitparser/parser/volume/LiterUnitParser.java
-
38src/main/java/dev/controlmaster/models/unitparser/parser/volume/MilliliterUnitParser.java
-
38src/main/java/dev/controlmaster/models/unitparser/parser/volume/USGallonUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/websize/EmUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/websize/PixelUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/weights/GramUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/weights/KilogramUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/weights/OunceUnitParser.java
-
40src/main/java/dev/controlmaster/models/unitparser/parser/weights/PoundUnitParser.java
-
39src/main/java/dev/controlmaster/models/unitparser/parser/weights/TonUnitParser.java
-
65src/main/java/dev/controlmaster/models/unitparser/unitvalueobjects/CmykValue.java
-
51src/main/java/dev/controlmaster/models/unitparser/unitvalueobjects/HslValue.java
-
52src/main/java/dev/controlmaster/models/unitparser/unitvalueobjects/HsvValue.java
-
51src/main/java/dev/controlmaster/models/unitparser/unitvalueobjects/RgbValue.java
-
51src/main/java/dev/controlmaster/units/BaseUnit.java
-
7src/main/java/dev/controlmaster/units/IUnit.java
-
5src/main/java/dev/controlmaster/units/Unit.java
-
34src/main/java/dev/controlmaster/units/angles/MilesPerImperialGallonUnit.java
-
35src/main/java/dev/controlmaster/units/angles/RadiantAngleUnit.java
-
34src/main/java/dev/controlmaster/units/areas/HectareUnit.java
-
33src/main/java/dev/controlmaster/units/areas/SquareMeterUnit.java
-
59src/main/java/dev/controlmaster/units/colors/CmykColorUnit.java
-
41src/main/java/dev/controlmaster/units/colors/HexColorUnit.java
-
94src/main/java/dev/controlmaster/units/colors/HslColorUnit.java
-
93src/main/java/dev/controlmaster/units/colors/HsvColorUnit.java
-
153src/main/java/dev/controlmaster/units/colors/RgbColorUnit.java
-
34src/main/java/dev/controlmaster/units/datastorage/BitUnit.java
-
35src/main/java/dev/controlmaster/units/datastorage/ByteUnit.java
-
34src/main/java/dev/controlmaster/units/datastorage/GigabyteUnit.java
-
56src/main/java/dev/controlmaster/units/datastorage/KilobyteUnit.java
-
35src/main/java/dev/controlmaster/units/datastorage/MegabyteUnit.java
-
36src/main/java/dev/controlmaster/units/datastorage/TerabyteUnit.java
-
39src/main/java/dev/controlmaster/units/fuelconsumption/LitersPer100KilometerUnit.java
-
35src/main/java/dev/controlmaster/units/fuelconsumption/MilesPerImperialGallonUnit.java
-
35src/main/java/dev/controlmaster/units/fuelconsumption/MilesPerUSGallonUnit.java
-
35src/main/java/dev/controlmaster/units/lengths/ByteUnit.java
-
35src/main/java/dev/controlmaster/units/lengths/FootUnit.java
-
33src/main/java/dev/controlmaster/units/lengths/InchUnit.java
-
35src/main/java/dev/controlmaster/units/lengths/KilometerUnit.java
-
94src/main/java/dev/controlmaster/units/lengths/MeterUnit.java
-
33src/main/java/dev/controlmaster/units/lengths/MileUnit.java
-
33src/main/java/dev/controlmaster/units/lengths/MillimeterUnit.java
-
34src/main/java/dev/controlmaster/units/lengths/YardUnit.java
-
33src/main/java/dev/controlmaster/units/temparatures/CelsiusUnit.java
-
33src/main/java/dev/controlmaster/units/temparatures/FahrenheitUnit.java
-
51src/main/java/dev/controlmaster/units/temparatures/KelvinUnit.java
-
33src/main/java/dev/controlmaster/units/temparatures/RankineUnit.java
-
33src/main/java/dev/controlmaster/units/temparatures/RomerUnit.java
-
34src/main/java/dev/controlmaster/units/time/HourUnit.java
-
34src/main/java/dev/controlmaster/units/time/MillisecondUnit.java
-
34src/main/java/dev/controlmaster/units/time/MinuteUnit.java
-
45src/main/java/dev/controlmaster/units/time/SecondUnit.java
-
33src/main/java/dev/controlmaster/units/volume/FluidOunceUnit.java
-
33src/main/java/dev/controlmaster/units/volume/ImperialGallonUnit.java
-
49src/main/java/dev/controlmaster/units/volume/LiterUnit.java
@ -0,0 +1,4 @@ |
|||
/bin/ |
|||
/.settings |
|||
.project |
|||
.classpath |
@ -0,0 +1,28 @@ |
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
<groupId>conversion_api</groupId> |
|||
<artifactId>conversion_api</artifactId> |
|||
<version>0.0.1-SNAPSHOT</version> |
|||
<name>ConvertMaster</name> |
|||
|
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>com.sun.jersey</groupId> |
|||
<artifactId>jersey-server</artifactId> |
|||
<version>1.19.4</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.sun.jersey</groupId> |
|||
<artifactId>jersey-core</artifactId> |
|||
<version>1.19.4</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.fasterxml.jackson.core</groupId> |
|||
<artifactId>jackson-databind</artifactId> |
|||
<version>2.10.0</version> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
</project> |
@ -0,0 +1,49 @@ |
|||
package dev.controlmaster; |
|||
|
|||
import dev.controlmaster.base.UnitConverter; |
|||
import dev.controlmaster.units.areas.HectareUnit; |
|||
import dev.controlmaster.units.colors.CmykColorUnit; |
|||
import dev.controlmaster.units.colors.HslColorUnit; |
|||
import dev.controlmaster.units.colors.HsvColorUnit; |
|||
|
|||
public class TestMain |
|||
{ |
|||
|
|||
public static void main(String[] args) |
|||
{ |
|||
String testJson = "{\r\n" + |
|||
" \"type\": \"rgb\",\r\n" + |
|||
" \"value\": {\r\n" + |
|||
" \"red\": 32,\r\n" + |
|||
" \"green\": 125,\r\n" + |
|||
" \"blue\": 65\r\n" + |
|||
" }\r\n" + |
|||
"}"; |
|||
|
|||
String testJson2 = "{\r\n" + |
|||
" \"type\": \"hex\",\r\n" + |
|||
" \"value\": \"#16AEF6\"\r\n" + |
|||
"}"; |
|||
|
|||
String testJson3 = "{\r\n" + |
|||
" \"type\": \"hsl\",\r\n" + |
|||
" \"value\": {\r\n" + |
|||
" \"hue\": 135.0,\r\n" + |
|||
" \"saturation\": 0.65,\r\n" + |
|||
" \"lightness\": 0.43\r\n" + |
|||
" }\r\n" + |
|||
"}"; |
|||
|
|||
String testJson4 = "{\r\n" + |
|||
" \"type\": \"squaremeter\",\r\n" + |
|||
" \"value\": 2.0\r\n" + |
|||
"}"; |
|||
|
|||
System.out.println(UnitConverter.convertToUnit(testJson, HslColorUnit.class)); |
|||
System.out.println(UnitConverter.convertToUnit(testJson2, CmykColorUnit.class)); |
|||
System.out.println(UnitConverter.convertToUnit(testJson3, HsvColorUnit.class)); |
|||
System.out.println(UnitConverter.convertToUnit(testJson4, HectareUnit.class)); |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,6 @@ |
|||
package dev.controlmaster.base; |
|||
|
|||
public class Constants |
|||
{ |
|||
public static final double PI = 3.14159; |
|||
} |
@ -0,0 +1,85 @@ |
|||
package dev.controlmaster.base; |
|||
|
|||
import com.fasterxml.jackson.core.JsonProcessingException; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.IUnit; |
|||
|
|||
public class UnitConverter |
|||
{ |
|||
|
|||
private final static ObjectMapper MAPPER = new ObjectMapper(); |
|||
|
|||
public static UnitModel convertToUnitModel(String jsonString) |
|||
{ |
|||
UnitModel model = null; |
|||
|
|||
try |
|||
{ |
|||
model = MAPPER.readValue(jsonString, UnitModel.class); |
|||
} |
|||
catch (JsonProcessingException e) |
|||
{ |
|||
e.printStackTrace(); |
|||
} |
|||
|
|||
|
|||
return model; |
|||
} |
|||
|
|||
public static String convertToJsonString(UnitModel model) |
|||
{ |
|||
String jsonString = null; |
|||
|
|||
try |
|||
{ |
|||
jsonString = MAPPER.writeValueAsString(model); |
|||
} |
|||
catch (JsonProcessingException e) |
|||
{ |
|||
e.printStackTrace(); |
|||
} |
|||
|
|||
return jsonString; |
|||
} |
|||
|
|||
|
|||
public static IUnit convertToUnit(UnitModel model) |
|||
{ |
|||
UnitParsingReferences parsingReference = UnitParsingReferences.getReferenceByType(model.getUnitType()); |
|||
IUnitParser parser = parsingReference.getParser(); |
|||
|
|||
return parser.parseUnitModel(model); |
|||
} |
|||
|
|||
|
|||
public static UnitModel convertToUnitModel(IUnit unit) |
|||
{ |
|||
UnitParsingReferences parsingReference = UnitParsingReferences.getReferenceByType(unit.getUnitType()); |
|||
IUnitParser parser = parsingReference.getParser(); |
|||
|
|||
return parser.parseUnits(unit); |
|||
} |
|||
|
|||
public static String convertToUnit(String inputJson, Class<?> converterClass) |
|||
{ |
|||
UnitModel model = UnitConverter.convertToUnitModel(inputJson); |
|||
IUnit unit = UnitConverter.convertToUnit(model); |
|||
BaseUnit baseUnit = unit.convertToBaseUnit(); |
|||
IUnit convertedUnit = baseUnit.convertToUnit(converterClass); |
|||
UnitModel convertedModel = UnitConverter.convertToUnitModel(convertedUnit); |
|||
|
|||
return UnitConverter.convertToJsonString(convertedModel); |
|||
} |
|||
|
|||
|
|||
public static String convertToUnit(String inputJson, String conversionType) |
|||
{ |
|||
UnitParsingReferences unitReference = UnitParsingReferences.getReferenceByType(conversionType); |
|||
return convertToUnit(inputJson, unitReference.getUnitValueObject()); |
|||
} |
|||
} |
@ -0,0 +1,39 @@ |
|||
package dev.controlmaster.models; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
|
|||
public class UnitModel |
|||
{ |
|||
|
|||
@JsonProperty("type") |
|||
private String unitType; |
|||
|
|||
@JsonProperty("value") |
|||
private Object unitValue; |
|||
|
|||
public UnitModel() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public String getUnitType() |
|||
{ |
|||
return unitType; |
|||
} |
|||
|
|||
public void setUnitType(String unitType) |
|||
{ |
|||
this.unitType = unitType; |
|||
} |
|||
|
|||
public Object getUnitValue() |
|||
{ |
|||
return unitValue; |
|||
} |
|||
|
|||
public void setUnitValue(Object unitValue) |
|||
{ |
|||
this.unitValue = unitValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,14 @@ |
|||
package dev.controlmaster.models.unitparser; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.units.IUnit; |
|||
|
|||
|
|||
public interface IUnitParser |
|||
{ |
|||
|
|||
IUnit parseUnitModel(UnitModel model); |
|||
|
|||
UnitModel parseUnits(IUnit unit); |
|||
|
|||
} |
@ -0,0 +1,21 @@ |
|||
package dev.controlmaster.models.unitparser; |
|||
|
|||
import java.util.List; |
|||
|
|||
public class UnitParsingProvider |
|||
{ |
|||
public static IUnitParser provideUnitParser(String unitType) |
|||
{ |
|||
List<UnitParsingReferences> references = UnitParsingReferences.getAllReferences(); |
|||
|
|||
for(UnitParsingReferences reference : references) |
|||
{ |
|||
if(reference.getTypeName().equals(unitType)) |
|||
{ |
|||
return reference.getParser(); |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
@ -0,0 +1,203 @@ |
|||
package dev.controlmaster.models.unitparser; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
|
|||
import dev.controlmaster.models.unitparser.parser.angles.DegreeAngleUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.angles.RadiantAngleUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.areas.HectareUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.areas.SquareMeterUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.colors.CmykUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.colors.HexUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.colors.HslUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.colors.HsvUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.colors.RgbUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.datastorage.BitUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.datastorage.ByteUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.datastorage.GigabyteUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.datastorage.KilobyteUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.datastorage.MegabyteUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.datastorage.TerabyteUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.fuelconsumption.LitersPer100KilometerUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.fuelconsumption.MilesPerImperialGallonUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.fuelconsumption.MilesPerUSGallonUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.lengths.FootUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.lengths.InchUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.lengths.KilometerUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.lengths.MeterUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.lengths.MileUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.lengths.MillimeterUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.lengths.YardUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.temparatures.CelsiusUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.temparatures.FahrenheitUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.temparatures.KelvinUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.temparatures.RankineUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.temparatures.RomerUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.time.HourUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.time.MillisecondUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.time.MinuteUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.time.SecondUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.volume.FluidOunceUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.volume.ImperialGallonUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.volume.LiterUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.volume.MilliliterUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.volume.USGallonUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.websize.EmUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.websize.PixelUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.weights.GramUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.weights.KilogramUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.weights.OunceUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.weights.PoundUnitParser; |
|||
import dev.controlmaster.models.unitparser.parser.weights.TonUnitParser; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.angles.MilesPerImperialGallonUnit; |
|||
import dev.controlmaster.units.angles.RadiantAngleUnit; |
|||
import dev.controlmaster.units.areas.HectareUnit; |
|||
import dev.controlmaster.units.areas.SquareMeterUnit; |
|||
import dev.controlmaster.units.colors.CmykColorUnit; |
|||
import dev.controlmaster.units.colors.HexColorUnit; |
|||
import dev.controlmaster.units.colors.HslColorUnit; |
|||
import dev.controlmaster.units.colors.HsvColorUnit; |
|||
import dev.controlmaster.units.colors.RgbColorUnit; |
|||
import dev.controlmaster.units.datastorage.BitUnit; |
|||
import dev.controlmaster.units.datastorage.ByteUnit; |
|||
import dev.controlmaster.units.datastorage.KilobyteUnit; |
|||
import dev.controlmaster.units.datastorage.MegabyteUnit; |
|||
import dev.controlmaster.units.datastorage.TerabyteUnit; |
|||
import dev.controlmaster.units.fuelconsumption.LitersPer100KilometerUnit; |
|||
import dev.controlmaster.units.fuelconsumption.MilesPerUSGallonUnit; |
|||
import dev.controlmaster.units.lengths.FootUnit; |
|||
import dev.controlmaster.units.lengths.InchUnit; |
|||
import dev.controlmaster.units.lengths.KilometerUnit; |
|||
import dev.controlmaster.units.lengths.MeterUnit; |
|||
import dev.controlmaster.units.lengths.MileUnit; |
|||
import dev.controlmaster.units.lengths.MillimeterUnit; |
|||
import dev.controlmaster.units.lengths.YardUnit; |
|||
import dev.controlmaster.units.temparatures.CelsiusUnit; |
|||
import dev.controlmaster.units.temparatures.FahrenheitUnit; |
|||
import dev.controlmaster.units.temparatures.KelvinUnit; |
|||
import dev.controlmaster.units.temparatures.RankineUnit; |
|||
import dev.controlmaster.units.temparatures.RomerUnit; |
|||
import dev.controlmaster.units.time.HourUnit; |
|||
import dev.controlmaster.units.time.MillisecondUnit; |
|||
import dev.controlmaster.units.time.MinuteUnit; |
|||
import dev.controlmaster.units.time.SecondUnit; |
|||
import dev.controlmaster.units.volume.FluidOunceUnit; |
|||
import dev.controlmaster.units.volume.ImperialGallonUnit; |
|||
import dev.controlmaster.units.volume.LiterUnit; |
|||
import dev.controlmaster.units.volume.MilliliterUnit; |
|||
import dev.controlmaster.units.volume.USGallonUnit; |
|||
import dev.controlmaster.units.websize.EmUnit; |
|||
import dev.controlmaster.units.websize.PixelUnit; |
|||
import dev.controlmaster.units.weights.KilogramUnit; |
|||
import dev.controlmaster.units.weights.OunceUnit; |
|||
import dev.controlmaster.units.weights.PoundUnit; |
|||
import dev.controlmaster.units.weights.TonUnit; |
|||
|
|||
|
|||
public enum UnitParsingReferences |
|||
{ |
|||
HEX("hex", new HexUnitParser(), HexColorUnit.class), |
|||
RGB("rgb", new RgbUnitParser(), RgbColorUnit.class), |
|||
HSL("hsl", new HslUnitParser(), HslColorUnit.class), |
|||
HSV("hsv", new HsvUnitParser(), HsvColorUnit.class), |
|||
CMYK("cmyk", new CmykUnitParser(), CmykColorUnit.class), |
|||
METER("meter", new MeterUnitParser(), MeterUnit.class), |
|||
MILLIMETER("millimeter", new MillimeterUnitParser(), MillimeterUnit.class), |
|||
MILE("mile", new MileUnitParser(), MileUnit.class), |
|||
YARD("yard", new YardUnitParser(), YardUnit.class), |
|||
KILOMETER("kilometer", new KilometerUnitParser(), KilometerUnit.class), |
|||
FOOT("foot", new FootUnitParser(), FootUnit.class), |
|||
INCH("inch", new InchUnitParser(), InchUnit.class), |
|||
GRAM("gram", new GramUnitParser(), EmUnit.class), |
|||
KILOGRAM("kilogram", new KilogramUnitParser(), KilogramUnit.class), |
|||
OUNCE("ounce", new OunceUnitParser(), OunceUnit.class), |
|||
POUND("pound", new PoundUnitParser(), PoundUnit.class), |
|||
TON("ton", new TonUnitParser(), TonUnit.class), |
|||
CELSIUS("celsius", new CelsiusUnitParser(), CelsiusUnit.class), |
|||
FAHRENHEIT("fahrenheit", new FahrenheitUnitParser(), FahrenheitUnit.class), |
|||
RANKINE("rankine", new RankineUnitParser(), RankineUnit.class), |
|||
ROMER("romer", new RomerUnitParser(), RomerUnit.class), |
|||
KELVIN("kelvin", new KelvinUnitParser(), KelvinUnit.class), |
|||
MILLISECOND("millisecond", new MillisecondUnitParser(), MillisecondUnit.class), |
|||
SECOND("second", new SecondUnitParser(), SecondUnit.class), |
|||
MINUTE("minute", new MinuteUnitParser(), MinuteUnit.class), |
|||
HOUR("hour", new HourUnitParser(), HourUnit.class), |
|||
DEGREE("degree", new DegreeAngleUnitParser(), MilesPerImperialGallonUnit.class), |
|||
RADIANT("radiant", new RadiantAngleUnitParser(), RadiantAngleUnit.class), |
|||
LITER("liter", new LiterUnitParser(), LiterUnit.class), |
|||
MILLILITER("milliliter", new MilliliterUnitParser(), MilliliterUnit.class), |
|||
USGALLON("usgallon", new USGallonUnitParser(), USGallonUnit.class), |
|||
IMPERIALGALLON("imperialgallon", new ImperialGallonUnitParser(), ImperialGallonUnit.class), |
|||
FLUIDOUNCE("fluidounce", new FluidOunceUnitParser(), FluidOunceUnit.class), |
|||
LITERSPER100KILOMETER( |
|||
"litersper100kilometer", |
|||
new LitersPer100KilometerUnitParser(), |
|||
LitersPer100KilometerUnit.class), |
|||
MILESPERUSGALLON( |
|||
"milesperusgallon", |
|||
new MilesPerUSGallonUnitParser(), |
|||
MilesPerUSGallonUnit.class), |
|||
MILESPERIMPERIALGALLON( |
|||
"milesperimperialgallon", |
|||
new MilesPerImperialGallonUnitParser(), |
|||
MilesPerImperialGallonUnit.class), |
|||
SQUAREMETER("squaremeter", new SquareMeterUnitParser(), SquareMeterUnit.class), |
|||
HECTARE("hectare", new HectareUnitParser(), HectareUnit.class), |
|||
EM("em", new EmUnitParser(), EmUnit.class), |
|||
PIXEL("pixel", new PixelUnitParser(), PixelUnit.class), |
|||
BIT("bit", new BitUnitParser(), BitUnit.class), |
|||
BYTE("byte", new ByteUnitParser(), ByteUnit.class), |
|||
KILOBYTE("kilobyte", new KilobyteUnitParser(), KilobyteUnit.class), |
|||
MEGABYTE("megabyte", new MegabyteUnitParser(), MegabyteUnit.class), |
|||
GIGABYTE("gigabyte", new GigabyteUnitParser(), HectareUnit.class), |
|||
TERABYTE("terabyte", new TerabyteUnitParser(), TerabyteUnit.class); |
|||
|
|||
private String typeName; |
|||
private IUnitParser parser; |
|||
private Class<? extends IUnit> unitValueObject; |
|||
|
|||
private UnitParsingReferences(String typeName, IUnitParser parser, |
|||
Class<? extends IUnit> unitValueObject) |
|||
{ |
|||
this.typeName = typeName; |
|||
this.parser = parser; |
|||
this.unitValueObject = unitValueObject; |
|||
} |
|||
|
|||
public static List<UnitParsingReferences> getAllReferences() |
|||
{ |
|||
return Arrays.asList(values()); |
|||
} |
|||
|
|||
public static UnitParsingReferences getReferenceByType(String type) |
|||
{ |
|||
UnitParsingReferences unitReference = null; |
|||
|
|||
for (UnitParsingReferences reference : values()) |
|||
{ |
|||
if (reference.getTypeName().equals(type)) |
|||
{ |
|||
return reference; |
|||
} |
|||
} |
|||
|
|||
return unitReference; |
|||
} |
|||
|
|||
public String getTypeName() |
|||
{ |
|||
return typeName; |
|||
} |
|||
|
|||
public IUnitParser getParser() |
|||
{ |
|||
return parser; |
|||
} |
|||
|
|||
public Class<? extends IUnit> getUnitValueObject() |
|||
{ |
|||
return unitValueObject; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.angles; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.angles.MilesPerImperialGallonUnit; |
|||
|
|||
public class DegreeAngleUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
MilesPerImperialGallonUnit degreeUnit = new MilesPerImperialGallonUnit(unitValue); |
|||
return degreeUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof MilesPerImperialGallonUnit) |
|||
{ |
|||
MilesPerImperialGallonUnit degreeUnit = (MilesPerImperialGallonUnit)unit; |
|||
UnitModel degreeModel = new UnitModel(); |
|||
degreeModel.setUnitType(UnitParsingReferences.DEGREE.getTypeName()); |
|||
degreeModel.setUnitValue(degreeUnit.getDegreeValue()); |
|||
return degreeModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,38 @@ |
|||
package dev.controlmaster.models.unitparser.parser.angles; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.angles.RadiantAngleUnit; |
|||
|
|||
public class RadiantAngleUnitParser implements IUnitParser |
|||
{ |
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
RadiantAngleUnit radiantUnit = new RadiantAngleUnit(unitValue); |
|||
return radiantUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof RadiantAngleUnit) |
|||
{ |
|||
RadiantAngleUnit radiantUnit = (RadiantAngleUnit)unit; |
|||
UnitModel radiantModel = new UnitModel(); |
|||
radiantModel.setUnitType(UnitParsingReferences.RADIANT.getTypeName()); |
|||
radiantModel.setUnitValue(radiantUnit.getRadiantValue()); |
|||
return radiantModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
@ -0,0 +1,39 @@ |
|||
package dev.controlmaster.models.unitparser.parser.areas; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.areas.HectareUnit; |
|||
|
|||
public class HectareUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
HectareUnit hectareUnit = new HectareUnit(unitValue); |
|||
return hectareUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof HectareUnit) |
|||
{ |
|||
HectareUnit hectareUnit = (HectareUnit)unit; |
|||
UnitModel hectareModel = new UnitModel(); |
|||
hectareModel.setUnitType(UnitParsingReferences.HECTARE.getTypeName()); |
|||
hectareModel.setUnitValue(hectareUnit.getHectareValue()); |
|||
return hectareModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.areas; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.areas.SquareMeterUnit; |
|||
|
|||
|
|||
public class SquareMeterUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if (model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double) model.getUnitValue(); |
|||
SquareMeterUnit squareMeterUnit = new SquareMeterUnit(unitValue); |
|||
return squareMeterUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof SquareMeterUnit) |
|||
{ |
|||
SquareMeterUnit squareMeterUnit = (SquareMeterUnit) unit; |
|||
UnitModel squareMeterModel = new UnitModel(); |
|||
squareMeterModel.setUnitType(UnitParsingReferences.SQUAREMETER.getTypeName()); |
|||
squareMeterModel.setUnitValue(squareMeterUnit.getSquareMeterValue()); |
|||
return squareMeterModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,53 @@ |
|||
package dev.controlmaster.models.unitparser.parser.colors; |
|||
|
|||
import java.util.LinkedHashMap; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.models.unitparser.unitvalueobjects.CmykValue; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.colors.CmykColorUnit; |
|||
|
|||
|
|||
public class CmykUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if (model.getUnitValue() instanceof LinkedHashMap) |
|||
{ |
|||
LinkedHashMap<String, Double> unitMap = (LinkedHashMap<String, Double>) model |
|||
.getUnitValue(); |
|||
CmykColorUnit cmykUnit = new CmykColorUnit(unitMap.get("cyan"), unitMap.get("magenta"), |
|||
unitMap.get("yellow"), unitMap.get("black")); |
|||
return cmykUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof CmykColorUnit) |
|||
{ |
|||
CmykColorUnit cmykUnit = (CmykColorUnit) unit; |
|||
UnitModel cmykModel = new UnitModel(); |
|||
|
|||
CmykValue cmykValue = new CmykValue(); |
|||
cmykValue.setCyanValue(cmykUnit.getCyanValue()); |
|||
cmykValue.setMagentaValue(cmykUnit.getMagentaValue()); |
|||
cmykValue.setYellowValue(cmykUnit.getYellowValue()); |
|||
cmykValue.setBlackKeyValue(cmykUnit.getBlackKeyValue()); |
|||
|
|||
cmykModel.setUnitType(UnitParsingReferences.CMYK.getTypeName()); |
|||
cmykModel.setUnitValue(cmykValue); |
|||
return cmykModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,46 @@ |
|||
package dev.controlmaster.models.unitparser.parser.colors; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.colors.HexColorUnit; |
|||
|
|||
|
|||
public class HexUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
public HexUnitParser() |
|||
{ |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public HexColorUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof String) |
|||
{ |
|||
String unitValue = (String)model.getUnitValue(); |
|||
HexColorUnit hexUnit = new HexColorUnit(unitValue); |
|||
return hexUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof HexColorUnit) |
|||
{ |
|||
HexColorUnit hexUnit = (HexColorUnit)unit; |
|||
UnitModel hexModel = new UnitModel(); |
|||
hexModel.setUnitType(UnitParsingReferences.HEX.getTypeName()); |
|||
hexModel.setUnitValue(hexUnit.getUnitValue()); |
|||
return hexModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,49 @@ |
|||
package dev.controlmaster.models.unitparser.parser.colors; |
|||
|
|||
import java.util.LinkedHashMap; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.models.unitparser.unitvalueobjects.HslValue; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.colors.HslColorUnit; |
|||
|
|||
public class HslUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof LinkedHashMap) |
|||
{ |
|||
LinkedHashMap<String, Double> unitMap = (LinkedHashMap<String, Double>) model.getUnitValue(); |
|||
HslColorUnit hslUnit = new HslColorUnit(unitMap.get("hue"), unitMap.get("saturation"), unitMap.get("lightness")); |
|||
return hslUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof HslColorUnit) |
|||
{ |
|||
HslColorUnit hslUnit = (HslColorUnit)unit; |
|||
UnitModel hslModel = new UnitModel(); |
|||
|
|||
HslValue hslValue = new HslValue(); |
|||
hslValue.setHueValue(hslUnit.getHue()); |
|||
hslValue.setSaturationValue(hslUnit.getSaturation()); |
|||
hslValue.setLightnessValue(hslUnit.getLightness()); |
|||
|
|||
hslModel.setUnitType(UnitParsingReferences.HSL.getTypeName()); |
|||
hslModel.setUnitValue(hslValue); |
|||
return hslModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,52 @@ |
|||
package dev.controlmaster.models.unitparser.parser.colors; |
|||
|
|||
import java.util.LinkedHashMap; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.models.unitparser.unitvalueobjects.HsvValue; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.colors.HsvColorUnit; |
|||
|
|||
|
|||
public class HsvUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if (model.getUnitValue() instanceof LinkedHashMap) |
|||
{ |
|||
LinkedHashMap<String, Double> unitMap = (LinkedHashMap<String, Double>) model |
|||
.getUnitValue(); |
|||
HsvColorUnit hsvUnit = new HsvColorUnit(unitMap.get("hue"), unitMap.get("saturation"), |
|||
unitMap.get("value")); |
|||
return hsvUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof HsvColorUnit) |
|||
{ |
|||
HsvColorUnit hsvUnit = (HsvColorUnit) unit; |
|||
UnitModel hsvModel = new UnitModel(); |
|||
|
|||
HsvValue hsvValue = new HsvValue(); |
|||
hsvValue.setHueValue(hsvUnit.getHueValue()); |
|||
hsvValue.setSaturationValue(hsvUnit.getSaturationValue()); |
|||
hsvValue.setHsvValue(hsvUnit.getHsvValue()); |
|||
|
|||
hsvModel.setUnitType(UnitParsingReferences.HSV.getTypeName()); |
|||
hsvModel.setUnitValue(hsvValue); |
|||
return hsvModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,50 @@ |
|||
package dev.controlmaster.models.unitparser.parser.colors; |
|||
|
|||
import java.util.LinkedHashMap; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.models.unitparser.unitvalueobjects.RgbValue; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.colors.RgbColorUnit; |
|||
|
|||
public class RgbUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public RgbColorUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof LinkedHashMap) |
|||
{ |
|||
LinkedHashMap<String, Integer> unitMap = (LinkedHashMap<String, Integer>) model.getUnitValue(); |
|||
RgbColorUnit hexUnit = new RgbColorUnit(unitMap.get("red"), unitMap.get("green"), unitMap.get("blue")); |
|||
return hexUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
|
|||
if (unit instanceof RgbColorUnit) |
|||
{ |
|||
RgbColorUnit rgbUnit = (RgbColorUnit)unit; |
|||
UnitModel rgbModel = new UnitModel(); |
|||
|
|||
RgbValue rgbValue = new RgbValue(); |
|||
rgbValue.setRedValue(rgbUnit.getRedValue()); |
|||
rgbValue.setGreenValue(rgbUnit.getGreenValue()); |
|||
rgbValue.setBlueValue(rgbUnit.getBlueValue()); |
|||
|
|||
rgbModel.setUnitType(UnitParsingReferences.RGB.getTypeName()); |
|||
rgbModel.setUnitValue(rgbValue); |
|||
return rgbModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,24 @@ |
|||
package dev.controlmaster.models.unitparser.parser.datastorage; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.units.IUnit; |
|||
|
|||
public class BitUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
// TODO Auto-generated method stub |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
// TODO Auto-generated method stub |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,39 @@ |
|||
package dev.controlmaster.models.unitparser.parser.datastorage; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.datastorage.ByteUnit; |
|||
|
|||
public class ByteUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
ByteUnit byteUnit = new ByteUnit(unitValue); |
|||
return byteUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof ByteUnit) |
|||
{ |
|||
ByteUnit byteUnit = (ByteUnit)unit; |
|||
UnitModel byteModel = new UnitModel(); |
|||
byteModel.setUnitType(UnitParsingReferences.BYTE.getTypeName()); |
|||
byteModel.setUnitValue(byteUnit.getByteValue()); |
|||
return byteModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,39 @@ |
|||
package dev.controlmaster.models.unitparser.parser.datastorage; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.areas.HectareUnit; |
|||
|
|||
public class GigabyteUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
HectareUnit gigabyteUnit = new HectareUnit(unitValue); |
|||
return gigabyteUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof HectareUnit) |
|||
{ |
|||
HectareUnit gigabyteUnit = (HectareUnit)unit; |
|||
UnitModel gigabyteModel = new UnitModel(); |
|||
gigabyteModel.setUnitType(UnitParsingReferences.GIGABYTE.getTypeName()); |
|||
gigabyteModel.setUnitValue(gigabyteUnit.getHectareValue()); |
|||
return gigabyteModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.datastorage; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.datastorage.KilobyteUnit; |
|||
|
|||
|
|||
public class KilobyteUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if (model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double) model.getUnitValue(); |
|||
KilobyteUnit kilobyteUnit = new KilobyteUnit(unitValue); |
|||
return kilobyteUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof KilobyteUnit) |
|||
{ |
|||
KilobyteUnit kilobyteUnit = (KilobyteUnit) unit; |
|||
UnitModel kilobyteModel = new UnitModel(); |
|||
kilobyteModel.setUnitType(UnitParsingReferences.KILOBYTE.getTypeName()); |
|||
kilobyteModel.setUnitValue(kilobyteUnit.getKilobyteValue()); |
|||
return kilobyteModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,39 @@ |
|||
package dev.controlmaster.models.unitparser.parser.datastorage; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.datastorage.MegabyteUnit; |
|||
|
|||
public class MegabyteUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
MegabyteUnit megabyteUnit = new MegabyteUnit(unitValue); |
|||
return megabyteUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof MegabyteUnit) |
|||
{ |
|||
MegabyteUnit megabyteUnit = (MegabyteUnit)unit; |
|||
UnitModel megabyteModel = new UnitModel(); |
|||
megabyteModel.setUnitType(UnitParsingReferences.MEGABYTE.getTypeName()); |
|||
megabyteModel.setUnitValue(megabyteUnit.getMegabyteValue()); |
|||
return megabyteModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,38 @@ |
|||
package dev.controlmaster.models.unitparser.parser.datastorage; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.datastorage.TerabyteUnit; |
|||
|
|||
public class TerabyteUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
TerabyteUnit terabyteUnit = new TerabyteUnit(unitValue); |
|||
return terabyteUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof TerabyteUnit) |
|||
{ |
|||
TerabyteUnit terabyteUnit = (TerabyteUnit)unit; |
|||
UnitModel terabyteModel = new UnitModel(); |
|||
terabyteModel.setUnitType(UnitParsingReferences.TERABYTE.getTypeName()); |
|||
terabyteModel.setUnitValue(terabyteUnit.getTerabyteValue()); |
|||
return terabyteModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.fuelconsumption; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.fuelconsumption.LitersPer100KilometerUnit; |
|||
|
|||
public class LitersPer100KilometerUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
LitersPer100KilometerUnit litersPer100KilometerUnit = new LitersPer100KilometerUnit(unitValue); |
|||
return litersPer100KilometerUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof LitersPer100KilometerUnit) |
|||
{ |
|||
LitersPer100KilometerUnit litersPer100KilometerUnit = (LitersPer100KilometerUnit)unit; |
|||
UnitModel litersPer100KilometerModel = new UnitModel(); |
|||
litersPer100KilometerModel.setUnitType(UnitParsingReferences.LITERSPER100KILOMETER.getTypeName()); |
|||
litersPer100KilometerModel.setUnitValue(litersPer100KilometerUnit.getLitersPerKilometerValue()); |
|||
return litersPer100KilometerModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.fuelconsumption; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.angles.MilesPerImperialGallonUnit; |
|||
|
|||
public class MilesPerImperialGallonUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
MilesPerImperialGallonUnit milesPerImperialGallonUnit = new MilesPerImperialGallonUnit(unitValue); |
|||
return milesPerImperialGallonUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof MilesPerImperialGallonUnit) |
|||
{ |
|||
MilesPerImperialGallonUnit milesPerImperialGallonUnit = (MilesPerImperialGallonUnit)unit; |
|||
UnitModel milesPerImperialGallonModel = new UnitModel(); |
|||
milesPerImperialGallonModel.setUnitType(UnitParsingReferences.MILESPERIMPERIALGALLON.getTypeName()); |
|||
milesPerImperialGallonModel.setUnitValue(milesPerImperialGallonUnit.getDegreeValue()); |
|||
return milesPerImperialGallonModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.fuelconsumption; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.fuelconsumption.MilesPerUSGallonUnit; |
|||
|
|||
public class MilesPerUSGallonUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
MilesPerUSGallonUnit milesPerUSGallonUnit = new MilesPerUSGallonUnit(unitValue); |
|||
return milesPerUSGallonUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof MilesPerUSGallonUnit) |
|||
{ |
|||
MilesPerUSGallonUnit milesPerUSGallonUnit = (MilesPerUSGallonUnit)unit; |
|||
UnitModel milesPerUSGallonModel = new UnitModel(); |
|||
milesPerUSGallonModel.setUnitType(UnitParsingReferences.MILESPERUSGALLON.getTypeName()); |
|||
milesPerUSGallonModel.setUnitValue(milesPerUSGallonUnit.getMilesPerUSGallonValue()); |
|||
return milesPerUSGallonModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.lengths; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.lengths.FootUnit; |
|||
|
|||
public class FootUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
FootUnit centimeterUnit = new FootUnit(unitValue); |
|||
return centimeterUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof FootUnit) |
|||
{ |
|||
FootUnit footUnit = (FootUnit)unit; |
|||
UnitModel footModel = new UnitModel(); |
|||
footModel.setUnitType(UnitParsingReferences.FOOT.getTypeName()); |
|||
footModel.setUnitValue(footUnit.getFootValue()); |
|||
return footModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.lengths; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.lengths.InchUnit; |
|||
|
|||
public class InchUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
InchUnit inchUnit = new InchUnit(unitValue); |
|||
return inchUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof InchUnit) |
|||
{ |
|||
InchUnit inchUnit = (InchUnit)unit; |
|||
UnitModel inchModel = new UnitModel(); |
|||
inchModel.setUnitType(UnitParsingReferences.INCH.getTypeName()); |
|||
inchModel.setUnitValue(inchUnit.getInchValue()); |
|||
return inchModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,39 @@ |
|||
package dev.controlmaster.models.unitparser.parser.lengths; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.lengths.KilometerUnit; |
|||
|
|||
public class KilometerUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
KilometerUnit inchUnit = new KilometerUnit(unitValue); |
|||
return inchUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof KilometerUnit) |
|||
{ |
|||
KilometerUnit kilometerUnit = (KilometerUnit)unit; |
|||
UnitModel kilometerModel = new UnitModel(); |
|||
kilometerModel.setUnitType(UnitParsingReferences.KILOMETER.getTypeName()); |
|||
kilometerModel.setUnitValue(kilometerUnit.getKilometerValue()); |
|||
return kilometerModel; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,39 @@ |
|||
package dev.controlmaster.models.unitparser.parser.lengths; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.lengths.MeterUnit; |
|||
|
|||
public class MeterUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
MeterUnit meterUnit = new MeterUnit(unitValue); |
|||
return meterUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof MeterUnit) |
|||
{ |
|||
MeterUnit meterUnit = (MeterUnit)unit; |
|||
UnitModel meterModel = new UnitModel(); |
|||
meterModel.setUnitType(UnitParsingReferences.METER.getTypeName()); |
|||
meterModel.setUnitValue(meterUnit.getMeterValue()); |
|||
return meterModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.lengths; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.lengths.MileUnit; |
|||
|
|||
public class MileUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
MileUnit mileUnit = new MileUnit(unitValue); |
|||
return mileUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof MileUnit) |
|||
{ |
|||
MileUnit mileUnit = (MileUnit)unit; |
|||
UnitModel mileModel = new UnitModel(); |
|||
mileModel.setUnitType(UnitParsingReferences.MILE.getTypeName()); |
|||
mileModel.setUnitValue(mileUnit.getMileValue()); |
|||
return mileModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.lengths; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.lengths.MillimeterUnit; |
|||
|
|||
public class MillimeterUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
MillimeterUnit inchUnit = new MillimeterUnit(unitValue); |
|||
return inchUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof MillimeterUnit) |
|||
{ |
|||
MillimeterUnit millimeterUnit = (MillimeterUnit)unit; |
|||
UnitModel millimeterModel = new UnitModel(); |
|||
millimeterModel.setUnitType(UnitParsingReferences.MILLIMETER.getTypeName()); |
|||
millimeterModel.setUnitValue(millimeterUnit.getMillimeterValue()); |
|||
return millimeterModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.lengths; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.lengths.YardUnit; |
|||
|
|||
public class YardUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
YardUnit yardUnit = new YardUnit(unitValue); |
|||
return yardUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof YardUnit) |
|||
{ |
|||
YardUnit yardUnit = (YardUnit)unit; |
|||
UnitModel yardModel = new UnitModel(); |
|||
yardModel.setUnitType(UnitParsingReferences.YARD.getTypeName()); |
|||
yardModel.setUnitValue(yardUnit.getYardValue()); |
|||
return yardModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.temparatures; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.temparatures.CelsiusUnit; |
|||
|
|||
public class CelsiusUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
CelsiusUnit celsiusUnit = new CelsiusUnit(unitValue); |
|||
return celsiusUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof CelsiusUnit) |
|||
{ |
|||
CelsiusUnit celsiusUnit = (CelsiusUnit)unit; |
|||
UnitModel celsiusModel = new UnitModel(); |
|||
celsiusModel.setUnitType(UnitParsingReferences.CELSIUS.getTypeName()); |
|||
celsiusModel.setUnitValue(celsiusUnit.getCelsiusValue()); |
|||
return celsiusModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.temparatures; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.temparatures.FahrenheitUnit; |
|||
|
|||
public class FahrenheitUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
FahrenheitUnit fahrenheitUnit = new FahrenheitUnit(unitValue); |
|||
return fahrenheitUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof FahrenheitUnit) |
|||
{ |
|||
FahrenheitUnit fahrenheitUnit = (FahrenheitUnit)unit; |
|||
UnitModel fahrenheitModel = new UnitModel(); |
|||
fahrenheitModel.setUnitType(UnitParsingReferences.FAHRENHEIT.getTypeName()); |
|||
fahrenheitModel.setUnitValue(fahrenheitUnit.getFahrenheitValue()); |
|||
return fahrenheitModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,39 @@ |
|||
package dev.controlmaster.models.unitparser.parser.temparatures; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.temparatures.KelvinUnit; |
|||
|
|||
public class KelvinUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
KelvinUnit kelvinUnit = new KelvinUnit(unitValue); |
|||
return kelvinUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof KelvinUnit) |
|||
{ |
|||
KelvinUnit kelvinUnit = (KelvinUnit)unit; |
|||
UnitModel kelvinModel = new UnitModel(); |
|||
kelvinModel.setUnitType(UnitParsingReferences.KELVIN.getTypeName()); |
|||
kelvinModel.setUnitValue(kelvinUnit.getKelvinValue()); |
|||
return kelvinModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,39 @@ |
|||
package dev.controlmaster.models.unitparser.parser.temparatures; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.temparatures.RankineUnit; |
|||
|
|||
public class RankineUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
RankineUnit rankineUnit = new RankineUnit(unitValue); |
|||
return rankineUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof RankineUnit) |
|||
{ |
|||
RankineUnit rankineUnit = (RankineUnit)unit; |
|||
UnitModel rankineModel = new UnitModel(); |
|||
rankineModel.setUnitType(UnitParsingReferences.RANKINE.getTypeName()); |
|||
rankineModel.setUnitValue(rankineUnit.getRankineValue()); |
|||
return rankineModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.temparatures; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.temparatures.RankineUnit; |
|||
import dev.controlmaster.units.temparatures.RomerUnit; |
|||
|
|||
public class RomerUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
RomerUnit romerUnit = new RomerUnit(unitValue); |
|||
return romerUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof RomerUnit) |
|||
{ |
|||
RomerUnit romerUnit = (RomerUnit)unit; |
|||
UnitModel romerModel = new UnitModel(); |
|||
romerModel.setUnitType(UnitParsingReferences.ROMER.getTypeName()); |
|||
romerModel.setUnitValue(romerUnit.getRomerValue()); |
|||
return romerModel; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,38 @@ |
|||
package dev.controlmaster.models.unitparser.parser.time; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.time.HourUnit; |
|||
|
|||
public class HourUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
HourUnit hourUnit = new HourUnit(unitValue); |
|||
return hourUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof HourUnit) |
|||
{ |
|||
HourUnit hourUnit = (HourUnit)unit; |
|||
UnitModel hourModel = new UnitModel(); |
|||
hourModel.setUnitType(UnitParsingReferences.HOUR.getTypeName()); |
|||
hourModel.setUnitValue(hourUnit.getHourValue()); |
|||
return hourModel; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.time; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.lengths.MillimeterUnit; |
|||
import dev.controlmaster.units.time.MillisecondUnit; |
|||
|
|||
|
|||
public class MillisecondUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if (model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double) model.getUnitValue(); |
|||
MillimeterUnit millisecondUnit = new MillimeterUnit(unitValue); |
|||
return millisecondUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof MillisecondUnit) |
|||
{ |
|||
MillisecondUnit millisecondUnit = (MillisecondUnit)unit; |
|||
UnitModel millisecondModel = new UnitModel(); |
|||
millisecondModel.setUnitType(UnitParsingReferences.MILLISECOND.getTypeName()); |
|||
millisecondModel.setUnitValue(millisecondUnit.getMillisecondValue()); |
|||
return millisecondModel; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,38 @@ |
|||
package dev.controlmaster.models.unitparser.parser.time; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.time.MinuteUnit; |
|||
|
|||
public class MinuteUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
MinuteUnit minuteUnit = new MinuteUnit(unitValue); |
|||
return minuteUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof MinuteUnit) |
|||
{ |
|||
MinuteUnit minuteUnit = (MinuteUnit)unit; |
|||
UnitModel minuteModel = new UnitModel(); |
|||
minuteModel.setUnitType(UnitParsingReferences.MINUTE.getTypeName()); |
|||
minuteModel.setUnitValue(minuteUnit.getMinuteValue()); |
|||
return minuteModel; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,39 @@ |
|||
package dev.controlmaster.models.unitparser.parser.time; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.time.SecondUnit; |
|||
|
|||
public class SecondUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
SecondUnit secondUnit = new SecondUnit(unitValue); |
|||
return secondUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof SecondUnit) |
|||
{ |
|||
SecondUnit secondUnit = (SecondUnit)unit; |
|||
UnitModel secondModel = new UnitModel(); |
|||
secondModel.setUnitType(UnitParsingReferences.SECOND.getTypeName()); |
|||
secondModel.setUnitValue(secondUnit.getSecondValue()); |
|||
return secondModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,38 @@ |
|||
package dev.controlmaster.models.unitparser.parser.volume; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.volume.FluidOunceUnit; |
|||
|
|||
public class FluidOunceUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
FluidOunceUnit fluidOunceUnit = new FluidOunceUnit(unitValue); |
|||
return fluidOunceUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof FluidOunceUnit) |
|||
{ |
|||
FluidOunceUnit fluidOunceUnit = (FluidOunceUnit)unit; |
|||
UnitModel fluidOunceModel = new UnitModel(); |
|||
fluidOunceModel.setUnitType(UnitParsingReferences.FLUIDOUNCE.getTypeName()); |
|||
fluidOunceModel.setUnitValue(fluidOunceUnit.getFluidOunceValue()); |
|||
return fluidOunceModel; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,38 @@ |
|||
package dev.controlmaster.models.unitparser.parser.volume; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.volume.ImperialGallonUnit; |
|||
|
|||
public class ImperialGallonUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
ImperialGallonUnit imperialGallonUnit = new ImperialGallonUnit(unitValue); |
|||
return imperialGallonUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof ImperialGallonUnit) |
|||
{ |
|||
ImperialGallonUnit imperialGallonUnit = (ImperialGallonUnit)unit; |
|||
UnitModel imperialGallonModel = new UnitModel(); |
|||
imperialGallonModel.setUnitType(UnitParsingReferences.IMPERIALGALLON.getTypeName()); |
|||
imperialGallonModel.setUnitValue(imperialGallonUnit.getImperialGallonValue()); |
|||
return imperialGallonModel; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,38 @@ |
|||
package dev.controlmaster.models.unitparser.parser.volume; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.volume.LiterUnit; |
|||
|
|||
public class LiterUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
LiterUnit literUnit = new LiterUnit(unitValue); |
|||
return literUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof LiterUnit) |
|||
{ |
|||
LiterUnit literUnit = (LiterUnit)unit; |
|||
UnitModel literModel = new UnitModel(); |
|||
literModel.setUnitType(UnitParsingReferences.LITER.getTypeName()); |
|||
literModel.setUnitValue(literUnit.getLiterValue()); |
|||
return literModel; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,38 @@ |
|||
package dev.controlmaster.models.unitparser.parser.volume; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.volume.MilliliterUnit; |
|||
|
|||
public class MilliliterUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
MilliliterUnit milliliterUnit = new MilliliterUnit(unitValue); |
|||
return milliliterUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof MilliliterUnit) |
|||
{ |
|||
MilliliterUnit hourUnit = (MilliliterUnit)unit; |
|||
UnitModel milliliterModel = new UnitModel(); |
|||
milliliterModel.setUnitType(UnitParsingReferences.MILLILITER.getTypeName()); |
|||
milliliterModel.setUnitValue(hourUnit.getMilliliterValue()); |
|||
return milliliterModel; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,38 @@ |
|||
package dev.controlmaster.models.unitparser.parser.volume; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.volume.USGallonUnit; |
|||
|
|||
public class USGallonUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
USGallonUnit usGallonUnit = new USGallonUnit(unitValue); |
|||
return usGallonUnit; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof USGallonUnit) |
|||
{ |
|||
USGallonUnit usGallonUnit = (USGallonUnit)unit; |
|||
UnitModel usGallonModel = new UnitModel(); |
|||
usGallonModel.setUnitType(UnitParsingReferences.USGALLON.getTypeName()); |
|||
usGallonModel.setUnitValue(usGallonUnit.getGallonValue()); |
|||
return usGallonModel; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.websize; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.websize.EmUnit; |
|||
|
|||
public class EmUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
EmUnit emUnit = new EmUnit(unitValue); |
|||
return emUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof EmUnit) |
|||
{ |
|||
EmUnit emUnit = (EmUnit)unit; |
|||
UnitModel emModel = new UnitModel(); |
|||
emModel.setUnitType(UnitParsingReferences.EM.getTypeName()); |
|||
emModel.setUnitValue(emUnit.getEmValue()); |
|||
return emModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.websize; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.websize.PixelUnit; |
|||
|
|||
public class PixelUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Integer) |
|||
{ |
|||
Integer unitValue = (Integer)model.getUnitValue(); |
|||
PixelUnit pixelUnit = new PixelUnit(unitValue); |
|||
return pixelUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof PixelUnit) |
|||
{ |
|||
PixelUnit pixelUnit = (PixelUnit)unit; |
|||
UnitModel pixelModel = new UnitModel(); |
|||
pixelModel.setUnitType(UnitParsingReferences.PIXEL.getTypeName()); |
|||
pixelModel.setUnitValue(pixelUnit.getPixelValue()); |
|||
return pixelModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.weights; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.weights.EmUnit; |
|||
|
|||
public class GramUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
EmUnit gramUnit = new EmUnit(unitValue); |
|||
return gramUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof EmUnit) |
|||
{ |
|||
EmUnit meterUnit = (EmUnit)unit; |
|||
UnitModel gramModel = new UnitModel(); |
|||
gramModel.setUnitType(UnitParsingReferences.GRAM.getTypeName()); |
|||
gramModel.setUnitValue(meterUnit.getGramValue()); |
|||
return gramModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.weights; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.weights.KilogramUnit; |
|||
|
|||
public class KilogramUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
KilogramUnit kilogramUnit = new KilogramUnit(unitValue); |
|||
return kilogramUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof KilogramUnit) |
|||
{ |
|||
KilogramUnit kilogramUnit = (KilogramUnit)unit; |
|||
UnitModel kilogramModel = new UnitModel(); |
|||
kilogramModel.setUnitType(UnitParsingReferences.KILOGRAM.getTypeName()); |
|||
kilogramModel.setUnitValue(kilogramUnit.getKilogramValue()); |
|||
return kilogramModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.weights; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.weights.OunceUnit; |
|||
|
|||
public class OunceUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
OunceUnit ounceUnit = new OunceUnit(unitValue); |
|||
return ounceUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof OunceUnit) |
|||
{ |
|||
OunceUnit ounceUnit = (OunceUnit)unit; |
|||
UnitModel ounceModel = new UnitModel(); |
|||
ounceModel.setUnitType(UnitParsingReferences.OUNCE.getTypeName()); |
|||
ounceModel.setUnitValue(ounceUnit.getOunceValue()); |
|||
return ounceModel; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package dev.controlmaster.models.unitparser.parser.weights; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.lengths.MeterUnit; |
|||
import dev.controlmaster.units.weights.PoundUnit; |
|||
|
|||
public class PoundUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
PoundUnit poundUnit = new PoundUnit(unitValue); |
|||
return poundUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof PoundUnit) |
|||
{ |
|||
PoundUnit poundUnit = (PoundUnit)unit; |
|||
UnitModel poundModel = new UnitModel(); |
|||
poundModel.setUnitType(UnitParsingReferences.POUND.getTypeName()); |
|||
poundModel.setUnitValue(poundUnit.getPoundValue()); |
|||
return poundModel; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,39 @@ |
|||
package dev.controlmaster.models.unitparser.parser.weights; |
|||
|
|||
import dev.controlmaster.models.UnitModel; |
|||
import dev.controlmaster.models.unitparser.IUnitParser; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.IUnit; |
|||
import dev.controlmaster.units.weights.TonUnit; |
|||
|
|||
public class TonUnitParser implements IUnitParser |
|||
{ |
|||
|
|||
@Override |
|||
public IUnit parseUnitModel(UnitModel model) |
|||
{ |
|||
if(model.getUnitValue() instanceof Double) |
|||
{ |
|||
Double unitValue = (Double)model.getUnitValue(); |
|||
TonUnit tonUnit = new TonUnit(unitValue); |
|||
return tonUnit; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UnitModel parseUnits(IUnit unit) |
|||
{ |
|||
if (unit instanceof TonUnit) |
|||
{ |
|||
TonUnit tonUnit = (TonUnit)unit; |
|||
UnitModel tonModel = new UnitModel(); |
|||
tonModel.setUnitType(UnitParsingReferences.TON.getTypeName()); |
|||
tonModel.setUnitValue(tonUnit.getTonValue()); |
|||
return tonModel; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,65 @@ |
|||
package dev.controlmaster.models.unitparser.unitvalueobjects; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
|
|||
public class CmykValue |
|||
{ |
|||
@JsonProperty("cyan") |
|||
private double cyanValue; |
|||
|
|||
@JsonProperty("magenta") |
|||
private double magentaValue; |
|||
|
|||
@JsonProperty("yellow") |
|||
private double yellowValue; |
|||
|
|||
@JsonProperty("blackKey") |
|||
private double blackKeyValue; |
|||
|
|||
public CmykValue() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public double getCyanValue() |
|||
{ |
|||
return cyanValue; |
|||
} |
|||
|
|||
public void setCyanValue(double cyanValue) |
|||
{ |
|||
this.cyanValue = cyanValue; |
|||
} |
|||
|
|||
public double getMagentaValue() |
|||
{ |
|||
return magentaValue; |
|||
} |
|||
|
|||
public void setMagentaValue(double magentaValue) |
|||
{ |
|||
this.magentaValue = magentaValue; |
|||
} |
|||
|
|||
public double getYellowValue() |
|||
{ |
|||
return yellowValue; |
|||
} |
|||
|
|||
public void setYellowValue(double yellowValue) |
|||
{ |
|||
this.yellowValue = yellowValue; |
|||
} |
|||
|
|||
public double getBlackKeyValue() |
|||
{ |
|||
return blackKeyValue; |
|||
} |
|||
|
|||
public void setBlackKeyValue(double blackKeyValue) |
|||
{ |
|||
this.blackKeyValue = blackKeyValue; |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,51 @@ |
|||
package dev.controlmaster.models.unitparser.unitvalueobjects; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
|
|||
public class HslValue |
|||
{ |
|||
@JsonProperty("hue") |
|||
private double hueValue; |
|||
|
|||
@JsonProperty("saturation") |
|||
private double saturationValue; |
|||
|
|||
@JsonProperty("lightness") |
|||
private double lightnessValue; |
|||
|
|||
public HslValue() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public double getHueValue() |
|||
{ |
|||
return hueValue; |
|||
} |
|||
|
|||
public void setHueValue(double hueValue) |
|||
{ |
|||
this.hueValue = hueValue; |
|||
} |
|||
|
|||
public double getSaturationValue() |
|||
{ |
|||
return saturationValue; |
|||
} |
|||
|
|||
public void setSaturationValue(double saturationValue) |
|||
{ |
|||
this.saturationValue = saturationValue; |
|||
} |
|||
|
|||
public double getLightnessValue() |
|||
{ |
|||
return lightnessValue; |
|||
} |
|||
|
|||
public void setLightnessValue(double lightnessValue) |
|||
{ |
|||
this.lightnessValue = lightnessValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,52 @@ |
|||
package dev.controlmaster.models.unitparser.unitvalueobjects; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
|
|||
|
|||
public class HsvValue |
|||
{ |
|||
@JsonProperty("hue") |
|||
private double hueValue; |
|||
|
|||
@JsonProperty("saturation") |
|||
private double saturationValue; |
|||
|
|||
@JsonProperty("value") |
|||
private double hsvValue; |
|||
|
|||
public HsvValue() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public double getHueValue() |
|||
{ |
|||
return hueValue; |
|||
} |
|||
|
|||
public void setHueValue(double hueValue) |
|||
{ |
|||
this.hueValue = hueValue; |
|||
} |
|||
|
|||
public double getSaturationValue() |
|||
{ |
|||
return saturationValue; |
|||
} |
|||
|
|||
public void setSaturationValue(double saturationValue) |
|||
{ |
|||
this.saturationValue = saturationValue; |
|||
} |
|||
|
|||
public double getHsvValue() |
|||
{ |
|||
return hsvValue; |
|||
} |
|||
|
|||
public void setHsvValue(double hsvValue) |
|||
{ |
|||
this.hsvValue = hsvValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,51 @@ |
|||
package dev.controlmaster.models.unitparser.unitvalueobjects; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
|
|||
public class RgbValue |
|||
{ |
|||
@JsonProperty("red") |
|||
private int redValue; |
|||
|
|||
@JsonProperty("green") |
|||
private int greenValue; |
|||
|
|||
@JsonProperty("blue") |
|||
private int blueValue; |
|||
|
|||
public RgbValue() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public int getRedValue() |
|||
{ |
|||
return redValue; |
|||
} |
|||
|
|||
public void setRedValue(int redValue) |
|||
{ |
|||
this.redValue = redValue; |
|||
} |
|||
|
|||
public int getGreenValue() |
|||
{ |
|||
return greenValue; |
|||
} |
|||
|
|||
public void setGreenValue(int greenValue) |
|||
{ |
|||
this.greenValue = greenValue; |
|||
} |
|||
|
|||
public int getBlueValue() |
|||
{ |
|||
return blueValue; |
|||
} |
|||
|
|||
public void setBlueValue(int blueValue) |
|||
{ |
|||
this.blueValue = blueValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,51 @@ |
|||
package dev.controlmaster.units; |
|||
|
|||
import java.lang.reflect.InvocationTargetException; |
|||
import java.lang.reflect.Method; |
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
|
|||
public abstract class BaseUnit implements IUnit |
|||
{ |
|||
private String extendedClassName; |
|||
protected List<Class<?>> unitsInGroup; |
|||
|
|||
public BaseUnit(String className, Class<?>...classes) |
|||
{ |
|||
this.unitsInGroup = Arrays.asList(classes); |
|||
this.extendedClassName = className; |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return this; |
|||
} |
|||
|
|||
|
|||
public IUnit convertToUnit(Class<?> targetClass) |
|||
{ |
|||
if (this.unitsInGroup.contains(targetClass)) |
|||
{ |
|||
Method conversionMethod = null; |
|||
try |
|||
{ |
|||
if (targetClass.getSimpleName().equals(this.extendedClassName)) |
|||
{ |
|||
return this; |
|||
} |
|||
|
|||
conversionMethod = this.getClass() |
|||
.getDeclaredMethod("convertTo" + targetClass.getSimpleName()); |
|||
return (IUnit) conversionMethod.invoke(this); |
|||
} |
|||
catch (NoSuchMethodException | SecurityException | IllegalAccessException |
|||
| IllegalArgumentException | InvocationTargetException e) |
|||
{ |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
@ -0,0 +1,7 @@ |
|||
package dev.controlmaster.units; |
|||
|
|||
public interface IUnit |
|||
{ |
|||
String getUnitType(); |
|||
BaseUnit convertToBaseUnit(); |
|||
} |
@ -0,0 +1,5 @@ |
|||
package dev.controlmaster.units; |
|||
|
|||
public abstract class Unit implements IUnit |
|||
{ |
|||
} |
@ -0,0 +1,34 @@ |
|||
package dev.controlmaster.units.angles; |
|||
|
|||
import dev.controlmaster.base.Constants; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
|
|||
|
|||
public class MilesPerImperialGallonUnit extends BaseUnit |
|||
{ |
|||
private double degreeValue; |
|||
|
|||
public MilesPerImperialGallonUnit(double value) |
|||
{ |
|||
super(MilesPerImperialGallonUnit.class.getSimpleName(), MilesPerImperialGallonUnit.class, RadiantAngleUnit.class); |
|||
this.degreeValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.DEGREE.getTypeName(); |
|||
} |
|||
|
|||
public RadiantAngleUnit convertToRadiantAngleUnit() |
|||
{ |
|||
return new RadiantAngleUnit((degreeValue * Constants.PI) / 180.0); |
|||
} |
|||
|
|||
public double getDegreeValue() |
|||
{ |
|||
return degreeValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,35 @@ |
|||
package dev.controlmaster.units.angles; |
|||
|
|||
import dev.controlmaster.base.Constants; |
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class RadiantAngleUnit extends Unit |
|||
{ |
|||
private double radiantValue; |
|||
|
|||
public RadiantAngleUnit(double value) |
|||
{ |
|||
this.radiantValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.RADIANT.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new MilesPerImperialGallonUnit((radiantValue * 180.0) / Constants.PI); |
|||
} |
|||
|
|||
public double getRadiantValue() |
|||
{ |
|||
return radiantValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,34 @@ |
|||
package dev.controlmaster.units.areas; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class HectareUnit extends Unit |
|||
{ |
|||
private double hectareValue; |
|||
|
|||
public HectareUnit(double value) |
|||
{ |
|||
this.hectareValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.HECTARE.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new SquareMeterUnit(hectareValue * 10000.0); |
|||
} |
|||
|
|||
public double getHectareValue() |
|||
{ |
|||
return hectareValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,33 @@ |
|||
package dev.controlmaster.units.areas; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
|
|||
|
|||
public class SquareMeterUnit extends BaseUnit |
|||
{ |
|||
private double squareMeterValue; |
|||
|
|||
public SquareMeterUnit(double value) |
|||
{ |
|||
super(SquareMeterUnit.class.getSimpleName(), SquareMeterUnit.class, HectareUnit.class); |
|||
this.squareMeterValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.SQUAREMETER.getTypeName(); |
|||
} |
|||
|
|||
public HectareUnit convertToHectareUnit() |
|||
{ |
|||
return new HectareUnit(squareMeterValue / 10000.0); |
|||
} |
|||
|
|||
public double getSquareMeterValue() |
|||
{ |
|||
return squareMeterValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,59 @@ |
|||
package dev.controlmaster.units.colors; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class CmykColorUnit extends Unit |
|||
{ |
|||
private double cyanValue; |
|||
private double magentaValue; |
|||
private double yellowValue; |
|||
private double blackKeyValue; |
|||
|
|||
public CmykColorUnit(double cyan, double magenta, double yellow, double black) |
|||
{ |
|||
this.cyanValue = cyan; |
|||
this.magentaValue = magenta; |
|||
this.yellowValue = yellow; |
|||
this.blackKeyValue = black; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.CMYK.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
int redValue = new Double(255.0 * (1.0 - cyanValue) * (1.0 - blackKeyValue)).intValue(); |
|||
int greenValue = new Double(255.0 * (1.0 - magentaValue) * (1.0 - blackKeyValue)).intValue(); |
|||
int blueValue = new Double(255.0 * (1.0 - yellowValue) * (1.0 - blackKeyValue)).intValue(); |
|||
|
|||
return new RgbColorUnit(redValue, greenValue, blueValue); |
|||
} |
|||
|
|||
public double getCyanValue() |
|||
{ |
|||
return cyanValue; |
|||
} |
|||
|
|||
public double getMagentaValue() |
|||
{ |
|||
return magentaValue; |
|||
} |
|||
|
|||
public double getYellowValue() |
|||
{ |
|||
return yellowValue; |
|||
} |
|||
|
|||
public double getBlackKeyValue() |
|||
{ |
|||
return blackKeyValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,41 @@ |
|||
package dev.controlmaster.units.colors; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
public class HexColorUnit extends Unit |
|||
{ |
|||
private String hexValue; |
|||
|
|||
public HexColorUnit(String hexValue) |
|||
{ |
|||
super(); |
|||
this.hexValue = hexValue; |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
String simpleHexValue = hexValue.substring(1, hexValue.length()); |
|||
|
|||
int redValue = Integer.parseInt(simpleHexValue.substring(0, 2), 16); |
|||
int greenValue = Integer.parseInt(simpleHexValue.substring(2, 4), 16); |
|||
int blueValue = Integer.parseInt(simpleHexValue.substring(4, 6), 16); |
|||
|
|||
return new RgbColorUnit(redValue, greenValue, blueValue); |
|||
} |
|||
|
|||
public String getUnitValue() |
|||
{ |
|||
return this.hexValue; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.HEX.getTypeName(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,94 @@ |
|||
package dev.controlmaster.units.colors; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class HslColorUnit extends Unit |
|||
{ |
|||
|
|||
private double hue; |
|||
private double saturation; |
|||
private double lightness; |
|||
|
|||
public HslColorUnit(double hue, double saturation, double lightness) |
|||
{ |
|||
this.hue = hue; |
|||
this.saturation = saturation; |
|||
this.lightness = lightness; |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
double cValue = (1 - Math.abs(2 * this.lightness - 1)) * this.saturation; |
|||
double xValue = cValue * (1 - Math.abs((this.hue / 60) % 2 - 1)); |
|||
double mValue = this.lightness - (cValue / 2); |
|||
|
|||
double redMirrorValue = 0, greenMirrorValue = 0, blueMirrorValue = 0; |
|||
|
|||
if (this.hue < 60) |
|||
{ |
|||
redMirrorValue = cValue; |
|||
greenMirrorValue = xValue; |
|||
blueMirrorValue = 0; |
|||
} |
|||
else if (this.hue >= 60 && this.hue < 120) |
|||
{ |
|||
redMirrorValue = xValue; |
|||
greenMirrorValue = cValue; |
|||
blueMirrorValue = 0; |
|||
} |
|||
else if (this.hue >= 120 && this.hue < 180) |
|||
{ |
|||
redMirrorValue = 0; |
|||
greenMirrorValue = cValue; |
|||
blueMirrorValue = xValue; |
|||
} |
|||
else if (this.hue >= 180 && this.hue < 240) |
|||
{ |
|||
redMirrorValue = 0; |
|||
greenMirrorValue = xValue; |
|||
blueMirrorValue = cValue; |
|||
} |
|||
else if (this.hue >= 240 && this.hue < 300) |
|||
{ |
|||
redMirrorValue = xValue; |
|||
greenMirrorValue = 0; |
|||
blueMirrorValue = cValue; |
|||
} |
|||
else if (this.hue >= 300 && this.hue < 360) |
|||
{ |
|||
redMirrorValue = cValue; |
|||
greenMirrorValue = 0; |
|||
blueMirrorValue = xValue; |
|||
} |
|||
|
|||
return new RgbColorUnit((new Double((redMirrorValue + mValue) * 255)).intValue(), |
|||
(new Double((greenMirrorValue + mValue) * 255)).intValue(), |
|||
(new Double((blueMirrorValue + mValue) * 255)).intValue()); |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.HSL.getTypeName(); |
|||
} |
|||
|
|||
public double getHue() |
|||
{ |
|||
return hue; |
|||
} |
|||
|
|||
public double getSaturation() |
|||
{ |
|||
return saturation; |
|||
} |
|||
|
|||
public double getLightness() |
|||
{ |
|||
return lightness; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,93 @@ |
|||
package dev.controlmaster.units.colors; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class HsvColorUnit extends Unit |
|||
{ |
|||
private double hueValue; |
|||
private double saturationValue; |
|||
private double hsvValue; |
|||
|
|||
public HsvColorUnit(double hueValue, double saturationValue, double value) |
|||
{ |
|||
this.hueValue = hueValue; |
|||
this.saturationValue = saturationValue; |
|||
this.hsvValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.HSV.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
double cValue = this.hsvValue * this.saturationValue; |
|||
double xValue = cValue * (1 - Math.abs(((this.hueValue / 60.0) % 2) - 1)); |
|||
double mValue = this.hsvValue - cValue; |
|||
|
|||
double redMirrorValue = 0, greenMirrorValue = 0, blueMirrorValue = 0; |
|||
|
|||
if (this.hueValue < 60) |
|||
{ |
|||
redMirrorValue = cValue; |
|||
greenMirrorValue = xValue; |
|||
blueMirrorValue = 0; |
|||
} |
|||
else if (this.hueValue >= 60 && this.hueValue < 120) |
|||
{ |
|||
redMirrorValue = xValue; |
|||
greenMirrorValue = cValue; |
|||
blueMirrorValue = 0; |
|||
} |
|||
else if (this.hueValue >= 120 && this.hueValue < 180) |
|||
{ |
|||
redMirrorValue = 0; |
|||
greenMirrorValue = cValue; |
|||
blueMirrorValue = xValue; |
|||
} |
|||
else if (this.hueValue >= 180 && this.hueValue < 240) |
|||
{ |
|||
redMirrorValue = 0; |
|||
greenMirrorValue = xValue; |
|||
blueMirrorValue = cValue; |
|||
} |
|||
else if (this.hueValue >= 240 && this.hueValue < 300) |
|||
{ |
|||
redMirrorValue = xValue; |
|||
greenMirrorValue = 0; |
|||
blueMirrorValue = cValue; |
|||
} |
|||
else if (this.hueValue >= 300 && this.hueValue < 360) |
|||
{ |
|||
redMirrorValue = cValue; |
|||
greenMirrorValue = 0; |
|||
blueMirrorValue = xValue; |
|||
} |
|||
|
|||
return new RgbColorUnit((new Double((redMirrorValue + mValue) * 255)).intValue(), |
|||
(new Double((greenMirrorValue + mValue) * 255)).intValue(), |
|||
(new Double((blueMirrorValue + mValue) * 255)).intValue()); |
|||
} |
|||
|
|||
public double getHueValue() |
|||
{ |
|||
return hueValue; |
|||
} |
|||
|
|||
public double getSaturationValue() |
|||
{ |
|||
return saturationValue; |
|||
} |
|||
|
|||
public double getHsvValue() |
|||
{ |
|||
return hsvValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,153 @@ |
|||
package dev.controlmaster.units.colors; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
|
|||
|
|||
public class RgbColorUnit extends BaseUnit |
|||
{ |
|||
|
|||
private int redValue; |
|||
private int greenValue; |
|||
private int blueValue; |
|||
|
|||
public RgbColorUnit(int redValue, int greenValue, int blueValue) |
|||
{ |
|||
super(RgbColorUnit.class.getSimpleName(), HexColorUnit.class, RgbColorUnit.class, |
|||
HslColorUnit.class, HsvColorUnit.class, CmykColorUnit.class); |
|||
this.redValue = redValue; |
|||
this.greenValue = greenValue; |
|||
this.blueValue = blueValue; |
|||
|
|||
} |
|||
|
|||
public int getRedValue() |
|||
{ |
|||
return redValue; |
|||
} |
|||
|
|||
public int getGreenValue() |
|||
{ |
|||
return greenValue; |
|||
} |
|||
|
|||
public int getBlueValue() |
|||
{ |
|||
return blueValue; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.RGB.getTypeName(); |
|||
} |
|||
|
|||
public HexColorUnit convertToHexColorUnit() |
|||
{ |
|||
StringBuilder hexValueBuilder = new StringBuilder(); |
|||
hexValueBuilder.append("#"); |
|||
String redHexValue = Integer.toHexString(redValue); |
|||
String greenHexValue = Integer.toHexString(greenValue); |
|||
String blueHexValue = Integer.toHexString(blueValue); |
|||
hexValueBuilder.append(redHexValue); |
|||
hexValueBuilder.append(greenHexValue); |
|||
hexValueBuilder.append(blueHexValue); |
|||
|
|||
return new HexColorUnit(hexValueBuilder.toString()); |
|||
} |
|||
|
|||
public HslColorUnit convertToHslColorUnit() |
|||
{ |
|||
double redMirrorValue = this.redValue / 255.0; |
|||
double greenMirrorValue = this.greenValue / 255.0; |
|||
double blueMirrorValue = this.blueValue / 255.0; |
|||
|
|||
double tmpCMax = Math.max(redMirrorValue, greenMirrorValue); |
|||
double cMax = Math.max(tmpCMax, blueMirrorValue); |
|||
|
|||
double tmpCMin = Math.min(redMirrorValue, greenMirrorValue); |
|||
double cMin = Math.min(tmpCMin, blueMirrorValue); |
|||
|
|||
double delta = cMax - cMin; |
|||
|
|||
double hueValue = 0; |
|||
|
|||
if (cMax == redMirrorValue && delta != 0) |
|||
{ |
|||
hueValue = 60 * (((greenMirrorValue - blueMirrorValue) / delta) % 6); |
|||
} |
|||
else if (cMax == greenMirrorValue && delta != 0) |
|||
{ |
|||
hueValue = 60 * (((blueMirrorValue - redMirrorValue) / delta) + 2); |
|||
} |
|||
else if (cMax == blueMirrorValue && delta != 0) |
|||
{ |
|||
hueValue = 60 * (((redMirrorValue - greenMirrorValue) / delta) + 4); |
|||
} |
|||
|
|||
double lightnessValue = (cMax + cMin) / 2; |
|||
|
|||
double saturationValue = 0; |
|||
|
|||
if (delta != 0) |
|||
{ |
|||
saturationValue = (delta / (1 - Math.abs(2 * lightnessValue - 1))); |
|||
} |
|||
|
|||
return new HslColorUnit(hueValue, saturationValue, lightnessValue); |
|||
} |
|||
|
|||
public HsvColorUnit convertToHsvColorUnit() |
|||
{ |
|||
double redMirrorValue = this.redValue / 255.0; |
|||
double greenMirrorValue = this.greenValue / 255.0; |
|||
double blueMirrorValue = this.blueValue / 255.0; |
|||
|
|||
double tmpCMax = Math.max(redMirrorValue, greenMirrorValue); |
|||
double cMax = Math.max(tmpCMax, blueMirrorValue); |
|||
|
|||
double tmpCMin = Math.min(redMirrorValue, greenMirrorValue); |
|||
double cMin = Math.min(tmpCMin, blueMirrorValue); |
|||
|
|||
double hueValue = 0; |
|||
double delta = cMax - cMin; |
|||
|
|||
if (cMax == redMirrorValue && delta != 0) |
|||
{ |
|||
hueValue = 60 * (((greenMirrorValue - blueMirrorValue) / delta) % 6); |
|||
} |
|||
else if (cMax == greenMirrorValue && delta != 0) |
|||
{ |
|||
hueValue = 60 * (((blueMirrorValue - redMirrorValue) / delta) + 2); |
|||
} |
|||
else if (cMax == blueMirrorValue && delta != 0) |
|||
{ |
|||
hueValue = 60 * (((redMirrorValue - greenMirrorValue) / delta) + 4); |
|||
} |
|||
|
|||
double saturationValue = 0; |
|||
|
|||
if (cMax != 0) |
|||
{ |
|||
saturationValue = (delta / cMax); |
|||
} |
|||
|
|||
return new HsvColorUnit(hueValue, saturationValue, cMax); |
|||
} |
|||
|
|||
public CmykColorUnit convertToCmykColorUnit() |
|||
{ |
|||
double redMirrorValue = redValue / 255.0; |
|||
double greenMirrorValue = greenValue / 255.0; |
|||
double blueMirrorValue = blueValue / 255.0; |
|||
|
|||
double tmpBlackKeyValue = Math.max(redMirrorValue, greenMirrorValue); |
|||
double blackKeyValue = 1.0 - Math.max(tmpBlackKeyValue, blueMirrorValue); |
|||
|
|||
double cyanValue = (1.0 - redMirrorValue - blackKeyValue) / (1.0 - blackKeyValue); |
|||
double magentaValue = (1.0 - greenMirrorValue - blackKeyValue) / (1.0 - blackKeyValue); |
|||
double yellowValue = (1.0 - blueMirrorValue - blackKeyValue) / (1.0 - blackKeyValue); |
|||
|
|||
return new CmykColorUnit(cyanValue, magentaValue, yellowValue, blackKeyValue); |
|||
} |
|||
} |
@ -0,0 +1,34 @@ |
|||
package dev.controlmaster.units.datastorage; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
public class BitUnit extends Unit |
|||
{ |
|||
|
|||
private int bitValue; |
|||
|
|||
public BitUnit(int value) |
|||
{ |
|||
this.bitValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.BIT.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new KilobyteUnit(bitValue / 8000); |
|||
} |
|||
|
|||
public int getBitValue() |
|||
{ |
|||
return bitValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,35 @@ |
|||
package dev.controlmaster.units.datastorage; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class ByteUnit extends Unit |
|||
{ |
|||
|
|||
private double byteValue; |
|||
|
|||
public ByteUnit(double value) |
|||
{ |
|||
this.byteValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.BYTE.getTypeName(); |
|||
} |
|||
|
|||
public double getByteValue() |
|||
{ |
|||
return byteValue; |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new KilobyteUnit(byteValue / 1000); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,34 @@ |
|||
package dev.controlmaster.units.datastorage; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class GigabyteUnit extends Unit |
|||
{ |
|||
private double gigabyteValue; |
|||
|
|||
public GigabyteUnit(double value) |
|||
{ |
|||
this.gigabyteValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.GIGABYTE.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new KilobyteUnit(gigabyteValue * 1000000); |
|||
} |
|||
|
|||
public double getGigabyteValue() |
|||
{ |
|||
return gigabyteValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,56 @@ |
|||
package dev.controlmaster.units.datastorage; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
|
|||
|
|||
public class KilobyteUnit extends BaseUnit |
|||
{ |
|||
|
|||
private double kilobyteValue; |
|||
|
|||
public KilobyteUnit(double value) |
|||
{ |
|||
super(KilobyteUnit.class.getSimpleName(), BitUnit.class, ByteUnit.class, KilobyteUnit.class, |
|||
MegabyteUnit.class, GigabyteUnit.class, TerabyteUnit.class); |
|||
|
|||
this.kilobyteValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.KILOBYTE.getTypeName(); |
|||
} |
|||
|
|||
public double getKilobyteValue() |
|||
{ |
|||
return kilobyteValue; |
|||
} |
|||
|
|||
public BitUnit convertToBitUnit() |
|||
{ |
|||
return new BitUnit((int) (kilobyteValue * 8000)); |
|||
} |
|||
|
|||
public ByteUnit convertToByteUnit() |
|||
{ |
|||
return new ByteUnit(kilobyteValue * 1000); |
|||
} |
|||
|
|||
public MegabyteUnit convertToMegabyteUnit() |
|||
{ |
|||
return new MegabyteUnit(kilobyteValue / 1000); |
|||
} |
|||
|
|||
public GigabyteUnit convertToGigabyteUnit() |
|||
{ |
|||
return new GigabyteUnit(kilobyteValue / 1000000); |
|||
} |
|||
|
|||
public TerabyteUnit convertToTerabyteUnit() |
|||
{ |
|||
return new TerabyteUnit(kilobyteValue / 1000000000); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,35 @@ |
|||
package dev.controlmaster.units.datastorage; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class MegabyteUnit extends Unit |
|||
{ |
|||
|
|||
private double megabyteValue; |
|||
|
|||
public MegabyteUnit(double value) |
|||
{ |
|||
this.megabyteValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.MEGABYTE.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new KilobyteUnit(megabyteValue * 1000); |
|||
} |
|||
|
|||
public double getMegabyteValue() |
|||
{ |
|||
return megabyteValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,36 @@ |
|||
package dev.controlmaster.units.datastorage; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
public class TerabyteUnit extends Unit |
|||
{ |
|||
|
|||
private double terabyteValue; |
|||
|
|||
public TerabyteUnit(double value) |
|||
{ |
|||
this.terabyteValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.TERABYTE.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new KilobyteUnit(terabyteValue * 1000000000); |
|||
} |
|||
|
|||
public double getTerabyteValue() |
|||
{ |
|||
return terabyteValue; |
|||
} |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,39 @@ |
|||
package dev.controlmaster.units.fuelconsumption; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
|
|||
|
|||
public class LitersPer100KilometerUnit extends BaseUnit |
|||
{ |
|||
private double litersPerKilometerValue; |
|||
|
|||
public LitersPer100KilometerUnit(double value) |
|||
{ |
|||
super(LitersPer100KilometerUnit.class.getSimpleName(), LitersPer100KilometerUnit.class, |
|||
MilesPerImperialGallonUnit.class, MilesPerUSGallonUnit.class); |
|||
this.litersPerKilometerValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.LITERSPER100KILOMETER.getTypeName(); |
|||
} |
|||
|
|||
public double getLitersPerKilometerValue() |
|||
{ |
|||
return litersPerKilometerValue; |
|||
} |
|||
|
|||
public MilesPerImperialGallonUnit convertToMilesPerImperialGallonUnit() |
|||
{ |
|||
return new MilesPerImperialGallonUnit(litersPerKilometerValue * 282.48); |
|||
} |
|||
|
|||
public MilesPerUSGallonUnit convertToMilesPerUSGallonUnit() |
|||
{ |
|||
return new MilesPerUSGallonUnit(litersPerKilometerValue * 235.214); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,35 @@ |
|||
package dev.controlmaster.units.fuelconsumption; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class MilesPerImperialGallonUnit extends Unit |
|||
{ |
|||
|
|||
private double milesPerImperialGallonValue; |
|||
|
|||
public MilesPerImperialGallonUnit(double value) |
|||
{ |
|||
this.milesPerImperialGallonValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.MILESPERIMPERIALGALLON.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new LitersPer100KilometerUnit(milesPerImperialGallonValue * 282.48); |
|||
} |
|||
|
|||
public double getMilesPerImperialGallonValue() |
|||
{ |
|||
return milesPerImperialGallonValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,35 @@ |
|||
package dev.controlmaster.units.fuelconsumption; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class MilesPerUSGallonUnit extends Unit |
|||
{ |
|||
|
|||
private double milesPerUSGallonValue; |
|||
|
|||
public MilesPerUSGallonUnit(double value) |
|||
{ |
|||
this.milesPerUSGallonValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.MILESPERUSGALLON.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new LitersPer100KilometerUnit(milesPerUSGallonValue * 235.214); |
|||
} |
|||
|
|||
public double getMilesPerUSGallonValue() |
|||
{ |
|||
return milesPerUSGallonValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,35 @@ |
|||
package dev.controlmaster.units.lengths; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
public class ByteUnit extends Unit |
|||
{ |
|||
private double centimeterValue; |
|||
|
|||
public ByteUnit(double value) |
|||
{ |
|||
this.centimeterValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.BYTE.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new MeterUnit(centimeterValue / 100.0); |
|||
} |
|||
|
|||
public double getCentimeterValue() |
|||
{ |
|||
return centimeterValue; |
|||
} |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,35 @@ |
|||
package dev.controlmaster.units.lengths; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class FootUnit extends Unit |
|||
{ |
|||
|
|||
private double unitValue; |
|||
|
|||
public FootUnit(double value) |
|||
{ |
|||
this.unitValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.FOOT.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new MeterUnit(this.unitValue / 3.2808); |
|||
} |
|||
|
|||
public double getFootValue() |
|||
{ |
|||
return unitValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,33 @@ |
|||
package dev.controlmaster.units.lengths; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class InchUnit extends Unit |
|||
{ |
|||
private double unitValue; |
|||
|
|||
public InchUnit(double value) |
|||
{ |
|||
this.unitValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.INCH.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new MeterUnit(this.unitValue * 0.0254); |
|||
} |
|||
|
|||
public double getInchValue() |
|||
{ |
|||
return unitValue; |
|||
} |
|||
} |
@ -0,0 +1,35 @@ |
|||
package dev.controlmaster.units.lengths; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class KilometerUnit extends Unit |
|||
{ |
|||
|
|||
private double unitValue; |
|||
|
|||
public KilometerUnit(double value) |
|||
{ |
|||
this.unitValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.KILOMETER.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new MeterUnit(this.unitValue * 1000); |
|||
} |
|||
|
|||
public double getKilometerValue() |
|||
{ |
|||
return unitValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,94 @@ |
|||
package dev.controlmaster.units.lengths; |
|||
|
|||
import java.lang.reflect.InvocationTargetException; |
|||
import java.lang.reflect.Method; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.IUnit; |
|||
|
|||
|
|||
public class MeterUnit extends BaseUnit |
|||
{ |
|||
private double meterValue; |
|||
|
|||
public MeterUnit(double value) |
|||
{ |
|||
super(MeterUnit.class.getSimpleName(), MeterUnit.class, ByteUnit.class, MillimeterUnit.class, FootUnit.class, InchUnit.class, KilometerUnit.class, MileUnit.class, YardUnit.class); |
|||
this.meterValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.METER.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public IUnit convertToUnit(Class<?> targetClass) |
|||
{ |
|||
if (this.unitsInGroup.contains(targetClass)) |
|||
{ |
|||
Method conversionMethod = null; |
|||
try |
|||
{ |
|||
if (targetClass.getSimpleName().equals("MeterUnit")) |
|||
{ |
|||
return this; |
|||
} |
|||
|
|||
conversionMethod = this.getClass() |
|||
.getDeclaredMethod("convertTo" + targetClass.getSimpleName()); |
|||
return (IUnit) conversionMethod.invoke(this); |
|||
} |
|||
catch (NoSuchMethodException | SecurityException | IllegalAccessException |
|||
| IllegalArgumentException | InvocationTargetException e) |
|||
{ |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
public double getMeterValue() |
|||
{ |
|||
return meterValue; |
|||
} |
|||
|
|||
private ByteUnit convertToCentimeterUnit() |
|||
{ |
|||
return new ByteUnit(meterValue * 100.0); |
|||
} |
|||
|
|||
private MillimeterUnit convertToMillimeterUnit() |
|||
{ |
|||
return new MillimeterUnit(meterValue * 1000.0); |
|||
} |
|||
|
|||
private KilometerUnit convertToKilometerUnit() |
|||
{ |
|||
return new KilometerUnit(meterValue / 1000.0); |
|||
} |
|||
|
|||
private FootUnit convertToFootUnit() |
|||
{ |
|||
return new FootUnit(meterValue * 3.2808); |
|||
} |
|||
|
|||
private InchUnit convertToInchUnit() |
|||
{ |
|||
return new InchUnit(meterValue * 39.37); |
|||
} |
|||
|
|||
private MileUnit convertToMileUnit() |
|||
{ |
|||
return new MileUnit(meterValue / 1609.344); |
|||
} |
|||
|
|||
private YardUnit convertToYardUnit() |
|||
{ |
|||
return new YardUnit(meterValue * 1.093613); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,33 @@ |
|||
package dev.controlmaster.units.lengths; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
public class MileUnit extends Unit |
|||
{ |
|||
private double unitValue; |
|||
|
|||
public MileUnit(double value) |
|||
{ |
|||
this.unitValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.MILE.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new MeterUnit(this.unitValue * 1609.344); |
|||
} |
|||
|
|||
public double getMileValue() |
|||
{ |
|||
return unitValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,33 @@ |
|||
package dev.controlmaster.units.lengths; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
public class MillimeterUnit extends Unit |
|||
{ |
|||
private double unitValue; |
|||
|
|||
public MillimeterUnit(double value) |
|||
{ |
|||
this.unitValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.MILLIMETER.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new MeterUnit(this.unitValue / 1000.0); |
|||
} |
|||
|
|||
public double getMillimeterValue() |
|||
{ |
|||
return unitValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,34 @@ |
|||
package dev.controlmaster.units.lengths; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class YardUnit extends Unit |
|||
{ |
|||
private double unitValue; |
|||
|
|||
public YardUnit(double value) |
|||
{ |
|||
this.unitValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.YARD.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new MeterUnit(this.unitValue / 1.0936); |
|||
} |
|||
|
|||
public double getYardValue() |
|||
{ |
|||
return unitValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,33 @@ |
|||
package dev.controlmaster.units.temparatures; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
public class CelsiusUnit extends Unit |
|||
{ |
|||
private double celsiusValue; |
|||
|
|||
public CelsiusUnit(double value) |
|||
{ |
|||
this.celsiusValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.CELSIUS.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new KelvinUnit(celsiusValue + 273.15); |
|||
} |
|||
|
|||
public double getCelsiusValue() |
|||
{ |
|||
return celsiusValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,33 @@ |
|||
package dev.controlmaster.units.temparatures; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
public class FahrenheitUnit extends Unit |
|||
{ |
|||
private double fahrenheitValue; |
|||
|
|||
public FahrenheitUnit(double value) |
|||
{ |
|||
this.fahrenheitValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.FAHRENHEIT.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new KelvinUnit(((fahrenheitValue - 32.0) / 1.8) + 273.15); |
|||
} |
|||
|
|||
public double getFahrenheitValue() |
|||
{ |
|||
return fahrenheitValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,51 @@ |
|||
package dev.controlmaster.units.temparatures; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
|
|||
|
|||
public class KelvinUnit extends BaseUnit |
|||
{ |
|||
|
|||
private double kelvinValue; |
|||
|
|||
public KelvinUnit(double value) |
|||
{ |
|||
super(KelvinUnit.class.getSimpleName(), KelvinUnit.class, CelsiusUnit.class, |
|||
FahrenheitUnit.class, RankineUnit.class, RomerUnit.class); |
|||
|
|||
this.kelvinValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.KELVIN.getTypeName(); |
|||
} |
|||
|
|||
public double getKelvinValue() |
|||
{ |
|||
return kelvinValue; |
|||
} |
|||
|
|||
public CelsiusUnit convertToCelsiusUnit() |
|||
{ |
|||
return new CelsiusUnit(kelvinValue - 273.15); |
|||
} |
|||
|
|||
public FahrenheitUnit convertToFahrenheitUnit() |
|||
{ |
|||
return new FahrenheitUnit((kelvinValue * 1.8) - 459.67); |
|||
} |
|||
|
|||
public RankineUnit convertToRankineUnit() |
|||
{ |
|||
return new RankineUnit(kelvinValue * 1.8); |
|||
} |
|||
|
|||
public RomerUnit convertToRomerUnit() |
|||
{ |
|||
return new RomerUnit(((kelvinValue - 273.15) * 0.525) + 7.5); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,33 @@ |
|||
package dev.controlmaster.units.temparatures; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class RankineUnit extends Unit |
|||
{ |
|||
private double rankineValue; |
|||
|
|||
public RankineUnit(double value) |
|||
{ |
|||
this.rankineValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.RANKINE.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new KelvinUnit(rankineValue / 1.8); |
|||
} |
|||
|
|||
public double getRankineValue() |
|||
{ |
|||
return rankineValue; |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
package dev.controlmaster.units.temparatures; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
public class RomerUnit extends Unit |
|||
{ |
|||
private double romerValue; |
|||
|
|||
public RomerUnit(double value) |
|||
{ |
|||
this.romerValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.ROMER.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new KelvinUnit(((romerValue - 7.5) / 0.525) + 273.15); |
|||
} |
|||
|
|||
public double getRomerValue() |
|||
{ |
|||
return romerValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,34 @@ |
|||
package dev.controlmaster.units.time; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class HourUnit extends Unit |
|||
{ |
|||
private double hourValue; |
|||
|
|||
public HourUnit(double value) |
|||
{ |
|||
this.hourValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.HOUR.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new SecondUnit(hourValue * 3600.0); |
|||
} |
|||
|
|||
public double getHourValue() |
|||
{ |
|||
return hourValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,34 @@ |
|||
package dev.controlmaster.units.time; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
public class MillisecondUnit extends Unit |
|||
{ |
|||
|
|||
private double millisecondValue; |
|||
|
|||
public MillisecondUnit(double value) |
|||
{ |
|||
this.millisecondValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.MILLISECOND.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new SecondUnit(millisecondValue / 1000.0); |
|||
} |
|||
|
|||
public double getMillisecondValue() |
|||
{ |
|||
return millisecondValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,34 @@ |
|||
package dev.controlmaster.units.time; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
|
|||
public class MinuteUnit extends Unit |
|||
{ |
|||
private double minuteValue; |
|||
|
|||
public MinuteUnit(double value) |
|||
{ |
|||
this.minuteValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.MINUTE.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new SecondUnit(minuteValue * 60.0); |
|||
} |
|||
|
|||
public double getMinuteValue() |
|||
{ |
|||
return minuteValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,45 @@ |
|||
package dev.controlmaster.units.time; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
|
|||
|
|||
public class SecondUnit extends BaseUnit |
|||
{ |
|||
|
|||
private double secondValue; |
|||
|
|||
public SecondUnit(double value) |
|||
{ |
|||
super(SecondUnit.class.getSimpleName(), MillisecondUnit.class, SecondUnit.class, |
|||
MinuteUnit.class, HourUnit.class); |
|||
this.secondValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.SECOND.getTypeName(); |
|||
} |
|||
|
|||
public MinuteUnit convertToMinuteUnit() |
|||
{ |
|||
return new MinuteUnit(secondValue / 60.0); |
|||
} |
|||
|
|||
public HourUnit convertToHourUnit() |
|||
{ |
|||
return new HourUnit(secondValue / 3600.0); |
|||
} |
|||
|
|||
public MillisecondUnit convertToMillisecondUnit() |
|||
{ |
|||
return new MillisecondUnit(secondValue * 1000.0); |
|||
} |
|||
|
|||
public double getSecondValue() |
|||
{ |
|||
return secondValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,33 @@ |
|||
package dev.controlmaster.units.volume; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
public class FluidOunceUnit extends Unit |
|||
{ |
|||
private double fluidOunceValue; |
|||
|
|||
public FluidOunceUnit(double value) |
|||
{ |
|||
this.fluidOunceValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.FLUIDOUNCE.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new LiterUnit(fluidOunceValue * 0.0284131); |
|||
} |
|||
|
|||
public double getFluidOunceValue() |
|||
{ |
|||
return fluidOunceValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,33 @@ |
|||
package dev.controlmaster.units.volume; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
import dev.controlmaster.units.Unit; |
|||
|
|||
public class ImperialGallonUnit extends Unit |
|||
{ |
|||
private double imperialGallonValue; |
|||
|
|||
public ImperialGallonUnit(double value) |
|||
{ |
|||
this.imperialGallonValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.IMPERIALGALLON.getTypeName(); |
|||
} |
|||
|
|||
@Override |
|||
public BaseUnit convertToBaseUnit() |
|||
{ |
|||
return new LiterUnit(imperialGallonValue * 4.5461); |
|||
} |
|||
|
|||
public double getImperialGallonValue() |
|||
{ |
|||
return imperialGallonValue; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,49 @@ |
|||
package dev.controlmaster.units.volume; |
|||
|
|||
import dev.controlmaster.models.unitparser.UnitParsingReferences; |
|||
import dev.controlmaster.units.BaseUnit; |
|||
|
|||
|
|||
public class LiterUnit extends BaseUnit |
|||
{ |
|||
private double literValue; |
|||
|
|||
public LiterUnit(double value) |
|||
{ |
|||
super(LiterUnit.class.getSimpleName(), LiterUnit.class, FluidOunceUnit.class, |
|||
ImperialGallonUnit.class, MilliliterUnit.class, USGallonUnit.class); |
|||
this.literValue = value; |
|||
} |
|||
|
|||
@Override |
|||
public String getUnitType() |
|||
{ |
|||
return UnitParsingReferences.LITER.getTypeName(); |
|||
} |
|||
|
|||
public MilliliterUnit convertToMilliliterUnit() |
|||
{ |
|||
return new MilliliterUnit(literValue * 1000.0); |
|||
} |
|||
|
|||
public FluidOunceUnit convertToFluidOunceUnit() |
|||
{ |
|||
return new FluidOunceUnit(literValue * 35.19503); |
|||
} |
|||
|
|||
public ImperialGallonUnit convertToImperialGallonUnit() |
|||
{ |
|||
return new ImperialGallonUnit(literValue * 0.22); |
|||
} |
|||
|
|||
public USGallonUnit convertToUSGallonUnit() |
|||
{ |
|||
return new USGallonUnit(literValue * 0.2642); |
|||
} |
|||
|
|||
public double getLiterValue() |
|||
{ |
|||
return literValue; |
|||
} |
|||
|
|||
} |
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue