diff --git a/gdxapp4d-app-calculator/pom.xml b/gdxapp4d-app-calculator/pom.xml index 2c9946ba..5239d8ea 100644 --- a/gdxapp4d-app-calculator/pom.xml +++ b/gdxapp4d-app-calculator/pom.xml @@ -29,7 +29,10 @@ <_donotcopy>(.git) <_dsannotations>* <_metatypeannotations>* - ${vrgem4.packages} + + ${tos4.packages}, + ${vrgem4.packages} + distributedrebirth.love diff --git a/gdxapp4d-app-glyphdemo/pom.xml b/gdxapp4d-app-glyphdemo/pom.xml index 9396fe57..8dff98a9 100644 --- a/gdxapp4d-app-glyphdemo/pom.xml +++ b/gdxapp4d-app-glyphdemo/pom.xml @@ -15,6 +15,12 @@ ${project.version} provided + + love.distributedrebirth.gdxapp4d + gdxapp4d-unitxc + ${project.version} + provided + @@ -29,7 +35,23 @@ <_donotcopy>(.git) <_dsannotations>* <_metatypeannotations>* - ${vrgem4.packages} + + ${tos4.packages}, + ${vrgem4.packages}, + ${unitxc.packages}, + org.apache.commons.lang3, + org.apache.commons.lang3.builder, + org.apache.commons.lang3.concurrent, + org.apache.commons.lang3.event, + org.apache.commons.lang3.exception, + org.apache.commons.lang3.math, + org.apache.commons.lang3.mutable, + org.apache.commons.lang3.reflect, + org.apache.commons.lang3.text, + org.apache.commons.lang3.text.translate, + org.apache.commons.lang3.time, + org.apache.commons.lang3.tuple + distributedrebirth.love diff --git a/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/GlyphDemoComponent.java b/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/GlyphDemoComponent.java index 8c25c61c..e14d6535 100644 --- a/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/GlyphDemoComponent.java +++ b/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/GlyphDemoComponent.java @@ -8,6 +8,7 @@ import org.osgi.service.component.annotations.Deactivate; import org.osgi.service.component.annotations.Reference; import love.distributedrebirth.gdxapp4d.app.glyphdemo.apps.DemoUnicodePlaneDeskApp; +import love.distributedrebirth.gdxapp4d.app.glyphdemo.apps.DemoUnitConverterDeskApp; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.gdxapp4d.app.glyphdemo.apps.DemoGlyphSetDeskApp; import love.distributedrebirth.gdxapp4d.app.glyphdemo.apps.DemoNumberPartDeskApp; @@ -17,6 +18,7 @@ import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4LocaleService; import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4Unicode4DService; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppLauncher; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppMenuSection; +import net.forwardfire.unitxc.UnitXCManager; @Component @BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") @@ -34,15 +36,20 @@ public class GlyphDemoComponent { @Reference private VrGem4Unicode4DService unicode4DService; + @Reference + private UnitXCManager unitManager; + private final static String I18N_BUNDLE = "love.distributedrebirth.gdxapp4d.app.glyphdemo.Messages"; private final DeskAppLauncher unicodeLauncher; private final DeskAppLauncher baseGlyphLauncher; private final DeskAppLauncher basePartLauncher; + private final DeskAppLauncher unitConverterLauncher; public GlyphDemoComponent() { - unicodeLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Demo Unicode Plane", () -> new DemoUnicodePlaneDeskApp(createBundle(), unicode4DService)); - baseGlyphLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Demo Glyph Set", () -> new DemoGlyphSetDeskApp(createBundle())); - basePartLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Demo Number Parts", () -> new DemoNumberPartDeskApp(createBundle())); + unicodeLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Unicode Plane", () -> new DemoUnicodePlaneDeskApp(createBundle(), unicode4DService)); + baseGlyphLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Glyph Set", () -> new DemoGlyphSetDeskApp(createBundle())); + basePartLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Number Parts", () -> new DemoNumberPartDeskApp(createBundle())); + unitConverterLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Unitˣᶜ Converter", () -> new DemoUnitConverterDeskApp(unitManager)); } private ResourceBundle createBundle() { @@ -55,6 +62,7 @@ public class GlyphDemoComponent { deskAppService.installDeskApp(unicodeLauncher); deskAppService.installDeskApp(baseGlyphLauncher); deskAppService.installDeskApp(basePartLauncher); + deskAppService.installDeskApp(unitConverterLauncher); } @Deactivate @@ -63,5 +71,6 @@ public class GlyphDemoComponent { deskAppService.removeDeskApp(unicodeLauncher); deskAppService.removeDeskApp(baseGlyphLauncher); deskAppService.removeDeskApp(basePartLauncher); + deskAppService.removeDeskApp(unitConverterLauncher); } } diff --git a/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/apps/DemoUnitConverterDeskApp.java b/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/apps/DemoUnitConverterDeskApp.java new file mode 100644 index 00000000..32103bae --- /dev/null +++ b/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/apps/DemoUnitConverterDeskApp.java @@ -0,0 +1,164 @@ +package love.distributedrebirth.gdxapp4d.app.glyphdemo.apps; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; + +import imgui.ImGui; +import imgui.flag.ImGuiTableFlags; +import imgui.type.ImDouble; +import imgui.type.ImInt; +import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; +import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.AbstractDeskApp; +import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppContourSection; +import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppRenderer; +import net.forwardfire.unitxc.UnitXCManager; +import net.forwardfire.unitxc.model.UnitXCGroup; +import net.forwardfire.unitxc.model.UnitXCType; + +@BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") +public class DemoUnitConverterDeskApp extends AbstractDeskApp implements DeskAppRenderer { + + private final UnitXCManager unitManager; + private final List unitTypes; + private final List unitGroups; + private final Map unitTypesFlags; + private final Map unitTypesValues; + private final String[] unitGroupNames; + private final ImDouble convertValue = new ImDouble(1234); + private final ImInt convertFromGroup = new ImInt(); + private final ImInt convertFromType = new ImInt(); + private final ImInt unitTypeLimit = new ImInt(5432); + private final List convertFromTypes; + private final long totalUnits; + private String[] convertFromTypeNames; + + public DemoUnitConverterDeskApp(UnitXCManager unitManager) { + this.unitManager = unitManager; + this.unitTypes = new ArrayList<>(); + this.unitGroups = unitManager.getConfig().getUnitGroups(); + this.unitTypesFlags = new HashMap<>(); + this.unitTypesValues = new HashMap<>(); + this.convertFromTypes = new ArrayList<>(); + + List names = new ArrayList<>(); + for (UnitXCGroup typeGroup:unitGroups) { + names.add(typeGroup.getName().getValue("und")); + } + unitGroupNames = names.toArray(new String[names.size()]); + + long ts = 0l; + for (UnitXCGroup typeGroup:unitManager.getConfig().getUnitGroups()) { + UnitXCType type = unitManager.getUnitType(typeGroup.getBaseTypeId()); + if (type == null) { + throw new IllegalStateException("No base type for: "+typeGroup.getId()+" needs: "+typeGroup.getBaseTypeId()); + } + long tc = typeGroup.getUnitTypeSize(); + ts += tc; + } + this.totalUnits = ts; + + updateConvertFromType(); + updateUnitType(); + } + + public void create() { + getContours().setTitle("Unitˣᶜ Converter"); + getContours().registrateContour(DeskAppContourSection.MAIN, this); + } + + @Override + public void render() { + ImGui.text("Total units loaded: "+totalUnits); + + // TODO: don't do update on render thread + if (ImGui.inputDouble("ConvertValue", convertValue)) { + updateUnitType(); + } + if (ImGui.combo("ConvertFromGroup", convertFromGroup, unitGroupNames)) { + updateConvertFromType(); + updateUnitType(); + } + if (ImGui.combo("ConvertFromType", convertFromType, convertFromTypeNames)) { + updateUnitType(); + } + UnitXCGroup typeGroup = unitGroups.get(convertFromGroup.get()); + if (ImGui.sliderInt("Limit of: "+typeGroup.getUnitTypeSize(), unitTypeLimit.getData(), 1000, 100000)) { + updateUnitType(); + } + + int flags = ImGuiTableFlags.ScrollX | ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersOuter | ImGuiTableFlags.BordersV | ImGuiTableFlags.Resizable; + ImGui.beginTable("unit-types", 4, flags); + ImGui.tableSetupColumn("value"); + ImGui.tableSetupColumn("id"); + ImGui.tableSetupColumn("name"); + ImGui.tableSetupColumn("flags"); + ImGui.tableHeadersRow(); + for (UnitXCType unitType:unitTypes) { + ImGui.tableNextRow(); + ImGui.tableNextColumn(); + ImGui.text(unitTypesValues.get(unitType.getId())); + ImGui.tableNextColumn(); + ImGui.text(unitType.getId()); + ImGui.tableNextColumn(); + ImGui.text(unitType.getName()); + ImGui.tableNextColumn(); + ImGui.text(unitTypesFlags.get(unitType.getId())); + ImGui.tableNextColumn(); + } + ImGui.endTable(); + } + + private void updateConvertFromType() { + convertFromTypes.clear(); + convertFromType.set(0); + int i = 0; + UnitXCGroup typeGroup = unitGroups.get(convertFromGroup.get()); + Iterator types = typeGroup.getUnitTypeIds(); + List names = new ArrayList<>(); + while (types.hasNext()) { + i++; + if (i>1000) { + break; + } + UnitXCType unitType = typeGroup.getUnitType(types.next()); + names.add(unitType.getName()); + convertFromTypes.add(unitType); + } + convertFromTypeNames = names.toArray(new String[names.size()]); + } + + private void updateUnitType() { + unitTypes.clear(); + unitTypesFlags.clear(); + unitTypesValues.clear(); + + int limitCounter = 0; + UnitXCType fromType = convertFromTypes.get(convertFromType.get()); + UnitXCGroup typeGroup = unitGroups.get(convertFromGroup.get()); + Iterator types = typeGroup.getUnitTypeIds(); + while (types.hasNext()) { + limitCounter++; + if (limitCounter>unitTypeLimit.get()) { + break; + } + UnitXCType unitType = typeGroup.getUnitType(types.next()); + unitTypes.add(unitType); + unitTypesFlags.put(unitType.getId(), StringUtils.join(unitType.getTypeFlags(), ",")); + try { + double convertRaw = convertValue.get(); + double convertOut = unitManager.getConverter().convert(convertRaw, fromType.getId(), unitType.getId()); + + unitTypesValues.put(unitType.getId(), String.valueOf(convertOut)); + } catch (IllegalArgumentException ignore) { + //java.lang.IllegalArgumentException: from and to groups are not equals: second != metre + break; // cross group jump is ~supported, but in here its is a bug somewhere and i also get; + // [libjvm.so] AccessInternal::PostRuntimeDispatch, (AccessInternal::BarrierType)2, 0ul>::oop_access_barrier(void*)+0x1 + } + } + } +} diff --git a/gdxapp4d-app-glyphdemo/src/main/resources/love/distributedrebirth/gdxapp4d/app/glyphdemo/Messages_hiero.properties b/gdxapp4d-app-glyphdemo/src/main/resources/love/distributedrebirth/gdxapp4d/app/glyphdemo/Messages_hiero.properties index e294d66c..88104cd8 100644 --- a/gdxapp4d-app-glyphdemo/src/main/resources/love/distributedrebirth/gdxapp4d/app/glyphdemo/Messages_hiero.properties +++ b/gdxapp4d-app-glyphdemo/src/main/resources/love/distributedrebirth/gdxapp4d/app/glyphdemo/Messages_hiero.properties @@ -1,11 +1,11 @@ -DemoGlyphSetDeskApp.title=Demo Glyph Set +DemoGlyphSetDeskApp.title=Glyph Set DemoGlyphSetDeskApp.showBase27=\uE219\u2005\uE362\u2005\uE0C0\u2005\uE13F\u2005\uE2F4\u2005\uE387\u2005\uE400 DemoGlyphSetDeskApp.colScript=\uE2F4\u2005\uE3A1\u2005\uE08B\u2005\uE1CB\u2005\uE2AA\u2005\uE20F DemoGlyphSetDeskApp.col10Num=\uE386\u2005\uE216\u2005\uE171\u2005\uE153\u2005\uE0C0\u2005\uE08C\u2005\uE2F4 DemoGlyphSetDeskApp.col16Num=\uE386\u2005\uE3FF\u2005\uE216\u2005\uE171\u2005\uE153\u2005\uE0C0\u2005\uE08C\u2005\uE2F4 DemoGlyphSetDeskApp.col27Num=\uE387\u2005\uE400\u2005\uE216\u2005\uE171\u2005\uE153\u2005\uE0C0\u2005\uE08C\u2005\uE2F4 -DemoNumberPartDeskApp.title=Demo Number Parts +DemoNumberPartDeskApp.title=Number Parts DemoNumberPartDeskApp.selectBase=\uE0C0\u2005\uE13F\u2005\uE2F4 DemoNumberPartDeskApp.selectName=\uE216\u2005\uE13F\u2005\uE153\u2005\uE3EC DemoNumberPartDeskApp.selectPurpose=\uE203\u2005\uE171\u2005\uE08C\u2005\uE203\u2005\uE2F4\u2005\uE3EC @@ -13,7 +13,7 @@ DemoNumberPartDeskApp.showBase10=\uE219\u2005\uE362\u2005\uE0C0\u2005\uE13F\u200 DemoNumberPartDeskApp.showBase16=\uE219\u2005\uE362\u2005\uE0C0\u2005\uE13F\u2005\uE2F4\u2005\uE386\u2005\uE3FF DemoNumberPartDeskApp.showBase27=\uE219\u2005\uE362\u2005\uE0C0\u2005\uE13F\u2005\uE2F4\u2005\uE387\u2005\uE400 -DemoUnicodePlaneDeskApp.title=Demo Unicode Plane +DemoUnicodePlaneDeskApp.title=Unicode Plane DemoUnicodePlaneDeskApp.colPlane=Unicode Plane DemoUnicodePlaneDeskApp.colText=Example DemoUnicodePlaneDeskApp.render4DPlane0=Show all in unicode4D \ No newline at end of file diff --git a/gdxapp4d-app-glyphdemo/src/main/resources/love/distributedrebirth/gdxapp4d/app/glyphdemo/Messages_nl.properties b/gdxapp4d-app-glyphdemo/src/main/resources/love/distributedrebirth/gdxapp4d/app/glyphdemo/Messages_nl.properties index 2e2f15eb..bd1906eb 100644 --- a/gdxapp4d-app-glyphdemo/src/main/resources/love/distributedrebirth/gdxapp4d/app/glyphdemo/Messages_nl.properties +++ b/gdxapp4d-app-glyphdemo/src/main/resources/love/distributedrebirth/gdxapp4d/app/glyphdemo/Messages_nl.properties @@ -1,11 +1,11 @@ -DemoGlyphSetDeskApp.title=Demo Glyph Set +DemoGlyphSetDeskApp.title=Glyph Set DemoGlyphSetDeskApp.showBase27=Toon basis27 DemoGlyphSetDeskApp.colScript=Script DemoGlyphSetDeskApp.col10Num=10Nummer DemoGlyphSetDeskApp.col16Num=16Nummer DemoGlyphSetDeskApp.col27Num=27Nummer -DemoNumberPartDeskApp.title=Demo Nummer Onderdeel +DemoNumberPartDeskApp.title=Nummer Onderdeel DemoNumberPartDeskApp.selectBase=Basis DemoNumberPartDeskApp.selectName=Naam: DemoNumberPartDeskApp.selectPurpose=Doel: @@ -13,7 +13,7 @@ DemoNumberPartDeskApp.showBase10=Toon basis10 DemoNumberPartDeskApp.showBase16=Toon basis16 DemoNumberPartDeskApp.showBase27=Toon basis27 -DemoUnicodePlaneDeskApp.title=Demo Unicode Vlak +DemoUnicodePlaneDeskApp.title=Unicode Vlak DemoUnicodePlaneDeskApp.colPlane=Unicode Vlak DemoUnicodePlaneDeskApp.colText=Voorbeeld DemoUnicodePlaneDeskApp.render4DPlane0=Toon alles in unicode4D \ No newline at end of file diff --git a/gdxapp4d-app-hewallet/pom.xml b/gdxapp4d-app-hewallet/pom.xml index 8e31564e..48555182 100644 --- a/gdxapp4d-app-hewallet/pom.xml +++ b/gdxapp4d-app-hewallet/pom.xml @@ -29,7 +29,10 @@ <_donotcopy>(.git) <_dsannotations>* <_metatypeannotations>* - ${vrgem4.packages} + + ${tos4.packages}, + ${vrgem4.packages} + distributedrebirth.love diff --git a/gdxapp4d-app-notepad/pom.xml b/gdxapp4d-app-notepad/pom.xml index 9bdf4b0f..cdc85cdb 100644 --- a/gdxapp4d-app-notepad/pom.xml +++ b/gdxapp4d-app-notepad/pom.xml @@ -29,7 +29,10 @@ <_donotcopy>(.git) <_dsannotations>* <_metatypeannotations>* - ${vrgem4.packages} + + ${tos4.packages}, + ${vrgem4.packages} + distributedrebirth.love diff --git a/gdxapp4d-app-notepad/src/main/java/love/distributedrebirth/gdxapp4d/app/notepad/NotepadDeskApp.java b/gdxapp4d-app-notepad/src/main/java/love/distributedrebirth/gdxapp4d/app/notepad/NotepadDeskApp.java index 3f16562e..7cf8cc2b 100644 --- a/gdxapp4d-app-notepad/src/main/java/love/distributedrebirth/gdxapp4d/app/notepad/NotepadDeskApp.java +++ b/gdxapp4d-app-notepad/src/main/java/love/distributedrebirth/gdxapp4d/app/notepad/NotepadDeskApp.java @@ -26,7 +26,7 @@ public class NotepadDeskApp extends AbstractDeskApp implements DeskAppRenderer { private final int[] gridRank; private final Random random; private int runCounter; - private final ImInt runSpeed = new ImInt(30); + private final ImInt runSpeed = new ImInt(10); private final static UnicodePlane[] GRID_PLANES = { UnicodePlane.BRAHMI, UnicodePlane.UGARITIC, diff --git a/gdxapp4d-app-tosamp/pom.xml b/gdxapp4d-app-tosamp/pom.xml index f88088c5..69b0de9c 100644 --- a/gdxapp4d-app-tosamp/pom.xml +++ b/gdxapp4d-app-tosamp/pom.xml @@ -29,7 +29,10 @@ <_donotcopy>(.git) <_dsannotations>* <_metatypeannotations>* - ${vrgem4.packages} + + ${tos4.packages}, + ${vrgem4.packages} + distributedrebirth.love diff --git a/gdxapp4d-boot-desktop/local-override.xml b/gdxapp4d-boot-desktop/local-override.xml index f9ea9aea..0c8722e3 100644 --- a/gdxapp4d-boot-desktop/local-override.xml +++ b/gdxapp4d-boot-desktop/local-override.xml @@ -1,9 +1,10 @@ - ../gdxapp4d-chain-sys-engine/target/chain - ../gdxapp4d-chain-sys-default/target/chain + ../gdxapp4d-chain-boot-ship-engine/target/chain + ../gdxapp4d-chain-boot-warp-sea/target/chain + ../gdxapp4d-chain-dep-osgi-lib/target/chain ../gdxapp4d-chain-dep-osgi-scr/target/chain ../gdxapp4d-chain-font-unicode4d/target/chain ../gdxapp4d-chain-default-music/target/chain @@ -14,7 +15,12 @@ ../gdxapp4d-app-notepad/target/classes ../gdxapp4d-app-glyphdemo/target/classes - ../gdxapp4d-chain-vrlib/target/chain - ../gdxapp4d-vrgem4/target/classes + ../gdxapp4d-chain-mod-vrgem4/target/chain + ../gdxapp4d-vrgem4/target/classes + + ../gdxapp4d-chain-mod-vrsys5/target/chain ../gdxapp4d-vrsys5/target/classes + + ../gdxapp4d-chain-mod-unitxc/target/chain + ../gdxapp4d-unitxc/target/classes diff --git a/gdxapp4d-boot-desktop/local-ship.xml b/gdxapp4d-boot-desktop/local-ship.xml index a1aaddf0..902c3ba2 100644 --- a/gdxapp4d-boot-desktop/local-ship.xml +++ b/gdxapp4d-boot-desktop/local-ship.xml @@ -4,9 +4,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:boot="http://warp-ship.x4o.distributedrebirth.love/xml/ns/warp-ship-boot" xsi:schemaLocation="http://wrap-ship.x4o.distributedrebirth.love/xml/ns/warp-ship-root http://warp-ship.x4o.distributedrebirth.love/xml/ns/warp-ship-root-1.0.xsd"> - - + diff --git a/gdxapp4d-chain-sys-engine/pom.xml b/gdxapp4d-chain-boot-ship-engine/pom.xml similarity index 92% rename from gdxapp4d-chain-sys-engine/pom.xml rename to gdxapp4d-chain-boot-ship-engine/pom.xml index f5ef7e7a..956e69c1 100644 --- a/gdxapp4d-chain-sys-engine/pom.xml +++ b/gdxapp4d-chain-boot-ship-engine/pom.xml @@ -5,8 +5,8 @@ gdxapp4d 0.0.1-SNAPSHOT - gdxapp4d-chain-sys-engine - GDXApp⁴ᴰ-Chain-Sys-محرك + gdxapp4d-chain-boot-ship-engine + GDXApp⁴ᴰ-Chain-Boot-Ship-محرك pom diff --git a/gdxapp4d-chain-sys-default/src/main/chain/warp-hash.xml b/gdxapp4d-chain-boot-ship-engine/src/main/chain/warp-hash.xml similarity index 100% rename from gdxapp4d-chain-sys-default/src/main/chain/warp-hash.xml rename to gdxapp4d-chain-boot-ship-engine/src/main/chain/warp-hash.xml diff --git a/gdxapp4d-chain-sys-engine/src/main/chain/warp-sea.xml b/gdxapp4d-chain-boot-ship-engine/src/main/chain/warp-sea.xml similarity index 76% rename from gdxapp4d-chain-sys-engine/src/main/chain/warp-sea.xml rename to gdxapp4d-chain-boot-ship-engine/src/main/chain/warp-sea.xml index 5be4fa7a..39c1b3cf 100644 --- a/gdxapp4d-chain-sys-engine/src/main/chain/warp-sea.xml +++ b/gdxapp4d-chain-boot-ship-engine/src/main/chain/warp-sea.xml @@ -3,12 +3,12 @@ xmlns:link="http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-link" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wrap-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-root http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-root-1.0.xsd"> - + - - + + diff --git a/gdxapp4d-chain-sys-default/pom.xml b/gdxapp4d-chain-boot-warp-sea/pom.xml similarity index 91% rename from gdxapp4d-chain-sys-default/pom.xml rename to gdxapp4d-chain-boot-warp-sea/pom.xml index 2bb1239e..159dad9e 100644 --- a/gdxapp4d-chain-sys-default/pom.xml +++ b/gdxapp4d-chain-boot-warp-sea/pom.xml @@ -5,8 +5,8 @@ gdxapp4d 0.0.1-SNAPSHOT - gdxapp4d-chain-sys-default - GDXApp⁴ᴰ-Chain-Sys-ค่าเริ่มต้น + gdxapp4d-chain-boot-warp-sea + GDXApp⁴ᴰ-Chain-Boot-Warp-ค่าเริ่มต้น pom diff --git a/gdxapp4d-chain-sys-engine/src/main/chain/warp-hash.xml b/gdxapp4d-chain-boot-warp-sea/src/main/chain/warp-hash.xml similarity index 100% rename from gdxapp4d-chain-sys-engine/src/main/chain/warp-hash.xml rename to gdxapp4d-chain-boot-warp-sea/src/main/chain/warp-hash.xml diff --git a/gdxapp4d-chain-sys-default/src/main/chain/warp-sea.xml b/gdxapp4d-chain-boot-warp-sea/src/main/chain/warp-sea.xml similarity index 60% rename from gdxapp4d-chain-sys-default/src/main/chain/warp-sea.xml rename to gdxapp4d-chain-boot-warp-sea/src/main/chain/warp-sea.xml index 67bb8bac..bd337b3e 100644 --- a/gdxapp4d-chain-sys-default/src/main/chain/warp-sea.xml +++ b/gdxapp4d-chain-boot-warp-sea/src/main/chain/warp-sea.xml @@ -3,7 +3,14 @@ xmlns:link="http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-link" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wrap-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-root http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-root-1.0.xsd"> - + + + + + + + + diff --git a/gdxapp4d-chain-dep-osgi-lib/pom.xml b/gdxapp4d-chain-dep-osgi-lib/pom.xml new file mode 100644 index 00000000..b7328ff5 --- /dev/null +++ b/gdxapp4d-chain-dep-osgi-lib/pom.xml @@ -0,0 +1,72 @@ + + 4.0.0 + + love.distributedrebirth.gdxapp4d + gdxapp4d + 0.0.1-SNAPSHOT + + gdxapp4d-chain-dep-osgi-lib + GDXApp⁴ᴰ-Chain-Dep-OSGI-LIB + pom + + + ch.qos.logback + logback-classic + + + org.apache.commons + commons-lang3 + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.3.0 + + + unpack-dependencies + package + + copy-dependencies + + + + + + maven-antrun-plugin + + + package + + + + + + + + + + + + + + + + + + + + + + + + run + + + + + + + \ No newline at end of file diff --git a/gdxapp4d-chain-dep-osgi-lib/src/main/chain/warp-hash.xml b/gdxapp4d-chain-dep-osgi-lib/src/main/chain/warp-hash.xml new file mode 100644 index 00000000..d3d6678b --- /dev/null +++ b/gdxapp4d-chain-dep-osgi-lib/src/main/chain/warp-hash.xml @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/gdxapp4d-chain-dep-osgi-lib/src/main/chain/warp-sea.xml b/gdxapp4d-chain-dep-osgi-lib/src/main/chain/warp-sea.xml new file mode 100644 index 00000000..541911df --- /dev/null +++ b/gdxapp4d-chain-dep-osgi-lib/src/main/chain/warp-sea.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/gdxapp4d-chain-dep-osgi-scr/src/main/chain/warp-sea.xml b/gdxapp4d-chain-dep-osgi-scr/src/main/chain/warp-sea.xml index d65b3510..bf111821 100644 --- a/gdxapp4d-chain-dep-osgi-scr/src/main/chain/warp-sea.xml +++ b/gdxapp4d-chain-dep-osgi-scr/src/main/chain/warp-sea.xml @@ -3,7 +3,7 @@ xmlns:link="http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-link" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wrap-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-root http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-root-1.0.xsd"> - + diff --git a/gdxapp4d-chain-mod-unitxc/pom.xml b/gdxapp4d-chain-mod-unitxc/pom.xml new file mode 100644 index 00000000..99c4daaa --- /dev/null +++ b/gdxapp4d-chain-mod-unitxc/pom.xml @@ -0,0 +1,53 @@ + + 4.0.0 + + love.distributedrebirth.gdxapp4d + gdxapp4d + 0.0.1-SNAPSHOT + + gdxapp4d-chain-mod-unitxc + pom + GDXApp⁴ᴰ-Chain-Module-Unitˣᶜ + + + love.distributedrebirth.gdxapp4d + gdxapp4d-unitxc + ${project.version} + provided + + + + + + maven-antrun-plugin + + + package + + + + + + + + + + + + + + + + + + + + + run + + + + + + + \ No newline at end of file diff --git a/gdxapp4d-chain-mod-unitxc/src/main/chain/warp-hash.xml b/gdxapp4d-chain-mod-unitxc/src/main/chain/warp-hash.xml new file mode 100644 index 00000000..56196a8a --- /dev/null +++ b/gdxapp4d-chain-mod-unitxc/src/main/chain/warp-hash.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/gdxapp4d-chain-mod-unitxc/src/main/chain/warp-sea.xml b/gdxapp4d-chain-mod-unitxc/src/main/chain/warp-sea.xml new file mode 100644 index 00000000..7f1979df --- /dev/null +++ b/gdxapp4d-chain-mod-unitxc/src/main/chain/warp-sea.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/gdxapp4d-chain-vrlib/pom.xml b/gdxapp4d-chain-mod-vrgem4/pom.xml similarity index 89% rename from gdxapp4d-chain-vrlib/pom.xml rename to gdxapp4d-chain-mod-vrgem4/pom.xml index 636cf2d1..f7fd0cbb 100644 --- a/gdxapp4d-chain-vrlib/pom.xml +++ b/gdxapp4d-chain-mod-vrgem4/pom.xml @@ -5,8 +5,8 @@ gdxapp4d 0.0.1-SNAPSHOT - gdxapp4d-chain-vrlib - GDXApp⁴ᴰ-Chain-vrLib + gdxapp4d-chain-mod-vrgem4 + GDXApp⁴ᴰ-Chain-Module-vrGEM⁴ pom @@ -15,12 +15,6 @@ ${project.version} provided - - love.distributedrebirth.gdxapp4d - gdxapp4d-vrsys5 - ${project.version} - provided - @@ -36,7 +30,6 @@ - diff --git a/gdxapp4d-chain-vrlib/src/main/chain/warp-hash.xml b/gdxapp4d-chain-mod-vrgem4/src/main/chain/warp-hash.xml similarity index 90% rename from gdxapp4d-chain-vrlib/src/main/chain/warp-hash.xml rename to gdxapp4d-chain-mod-vrgem4/src/main/chain/warp-hash.xml index f21b14b1..4c11e128 100644 --- a/gdxapp4d-chain-vrlib/src/main/chain/warp-hash.xml +++ b/gdxapp4d-chain-mod-vrgem4/src/main/chain/warp-hash.xml @@ -5,5 +5,4 @@ xsi:schemaLocation="http://wrap-core.x4o.distributedrebirth.love/xml/ns/warp-hash-root http://warp-hash.x4o.distributedrebirth.love/xml/ns/warp-hash-root-1.0.xsd"> - diff --git a/gdxapp4d-chain-vrlib/src/main/chain/warp-sea.xml b/gdxapp4d-chain-mod-vrgem4/src/main/chain/warp-sea.xml similarity index 75% rename from gdxapp4d-chain-vrlib/src/main/chain/warp-sea.xml rename to gdxapp4d-chain-mod-vrgem4/src/main/chain/warp-sea.xml index 7c2d4778..bc25cdbf 100644 --- a/gdxapp4d-chain-vrlib/src/main/chain/warp-sea.xml +++ b/gdxapp4d-chain-mod-vrgem4/src/main/chain/warp-sea.xml @@ -3,8 +3,7 @@ xmlns:link="http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-link" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wrap-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-root http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-root-1.0.xsd"> - + - diff --git a/gdxapp4d-chain-mod-vrsys5/pom.xml b/gdxapp4d-chain-mod-vrsys5/pom.xml new file mode 100644 index 00000000..9f77ab4a --- /dev/null +++ b/gdxapp4d-chain-mod-vrsys5/pom.xml @@ -0,0 +1,53 @@ + + 4.0.0 + + love.distributedrebirth.gdxapp4d + gdxapp4d + 0.0.1-SNAPSHOT + + gdxapp4d-chain-mod-vrsys5 + GDXApp⁴ᴰ-Chain-Module-vrSYS⁵ + pom + + + love.distributedrebirth.gdxapp4d + gdxapp4d-vrsys5 + ${project.version} + provided + + + + + + maven-antrun-plugin + + + package + + + + + + + + + + + + + + + + + + + + + run + + + + + + + \ No newline at end of file diff --git a/gdxapp4d-chain-mod-vrsys5/src/main/chain/warp-hash.xml b/gdxapp4d-chain-mod-vrsys5/src/main/chain/warp-hash.xml new file mode 100644 index 00000000..440706fe --- /dev/null +++ b/gdxapp4d-chain-mod-vrsys5/src/main/chain/warp-hash.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/gdxapp4d-chain-mod-vrsys5/src/main/chain/warp-sea.xml b/gdxapp4d-chain-mod-vrsys5/src/main/chain/warp-sea.xml new file mode 100644 index 00000000..a0d90e66 --- /dev/null +++ b/gdxapp4d-chain-mod-vrsys5/src/main/chain/warp-sea.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/gdxapp4d-lib-warpme/src/main/java/love/distributedrebirth/warpme/ship/WaterShip.java b/gdxapp4d-lib-warpme/src/main/java/love/distributedrebirth/warpme/ship/WaterShip.java index e47e2a4f..af008b99 100644 --- a/gdxapp4d-lib-warpme/src/main/java/love/distributedrebirth/warpme/ship/WaterShip.java +++ b/gdxapp4d-lib-warpme/src/main/java/love/distributedrebirth/warpme/ship/WaterShip.java @@ -10,7 +10,7 @@ public class WaterShip { private String name; private String engine; - private List shipOceans = new ArrayList<>(); + private List warpSeas = new ArrayList<>(); public String getName() { return name; @@ -28,17 +28,17 @@ public class WaterShip { this.engine = engine; } - public List getShipOceans() { - return shipOceans; + public List getWarpSeas() { + return warpSeas; } - public void setShipOcean(List shipOceans) { - for (WaterShipOcean shipOcean:shipOceans) { - addShipOcean(shipOcean); + public void setWarpSeas(List shipOceans) { + for (WaterShipWarp shipOcean:shipOceans) { + addWarpSea(shipOcean); } } - public void addShipOcean(WaterShipOcean shipSea) { - shipOceans.add(shipSea); + public void addWarpSea(WaterShipWarp shipSea) { + warpSeas.add(shipSea); } } diff --git a/gdxapp4d-lib-warpme/src/main/java/love/distributedrebirth/warpme/ship/WaterShipOcean.java b/gdxapp4d-lib-warpme/src/main/java/love/distributedrebirth/warpme/ship/WaterShipWarp.java similarity index 79% rename from gdxapp4d-lib-warpme/src/main/java/love/distributedrebirth/warpme/ship/WaterShipOcean.java rename to gdxapp4d-lib-warpme/src/main/java/love/distributedrebirth/warpme/ship/WaterShipWarp.java index ef383f50..703c300d 100644 --- a/gdxapp4d-lib-warpme/src/main/java/love/distributedrebirth/warpme/ship/WaterShipOcean.java +++ b/gdxapp4d-lib-warpme/src/main/java/love/distributedrebirth/warpme/ship/WaterShipWarp.java @@ -3,14 +3,14 @@ package love.distributedrebirth.warpme.ship; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; @BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") -public class WaterShipOcean { +public class WaterShipWarp { private String sea; - public WaterShipOcean() { + public WaterShipWarp() { } - public WaterShipOcean(String sea) { + public WaterShipWarp(String sea) { setSea(sea); } diff --git a/gdxapp4d-lib-warpme/src/main/resources/META-INF/warp-ship/warp-ship-lang.eld b/gdxapp4d-lib-warpme/src/main/resources/META-INF/warp-ship/warp-ship-lang.eld index 5dbab3dc..532f6631 100644 --- a/gdxapp4d-lib-warpme/src/main/resources/META-INF/warp-ship/warp-ship-lang.eld +++ b/gdxapp4d-lib-warpme/src/main/resources/META-INF/warp-ship/warp-ship-lang.eld @@ -11,10 +11,10 @@ parentClass="love.distributedrebirth.warpme.ship.WaterDevice" childClass="love.distributedrebirth.warpme.ship.WaterShip" addMethod="buildShip" getMethod="theShip" /> - + childClass="love.distributedrebirth.warpme.ship.WaterShipWarp" + addMethod="addWarpSea" getMethod="getWarpSeas" /> - + \ No newline at end of file diff --git a/gdxapp4d-lib-warpme/src/test/java/love/distributedrebirth/warpme/ship/WaterDeviceDriverTest.java b/gdxapp4d-lib-warpme/src/test/java/love/distributedrebirth/warpme/ship/WaterDeviceDriverTest.java index 99a891f0..cddf0501 100644 --- a/gdxapp4d-lib-warpme/src/test/java/love/distributedrebirth/warpme/ship/WaterDeviceDriverTest.java +++ b/gdxapp4d-lib-warpme/src/test/java/love/distributedrebirth/warpme/ship/WaterDeviceDriverTest.java @@ -19,9 +19,9 @@ public class WaterDeviceDriverTest { WaterShip ship = new WaterShip(); ship.setName("tos4-mark1"); ship.setEngine("123349858934"); - ship.addShipOcean(new WaterShipOcean("2349058490584")); - ship.addShipOcean(new WaterShipOcean("7867834823244")); - ship.addShipOcean(new WaterShipOcean("3948758927389")); + ship.addWarpSea(new WaterShipWarp("2349058490584")); + ship.addWarpSea(new WaterShipWarp("7867834823244")); + ship.addWarpSea(new WaterShipWarp("3948758927389")); device.buildShip(ship); diff --git a/gdxapp4d-tos4/pom.xml b/gdxapp4d-tos4/pom.xml index acb22d51..b4baef9c 100644 --- a/gdxapp4d-tos4/pom.xml +++ b/gdxapp4d-tos4/pom.xml @@ -73,9 +73,9 @@ <_donotcopy>(.git) org.osgi.framework,org.osgi.service.packageadmin,org.osgi.service.url,org.osgi.service.startlevel,org.osgi.util.tracker,* - love.distributedrebirth.gdxapp4d.tos4.service - love.distributedrebirth.gdxapp4d.tos4.* - *;artifactId=org.apache.felix.framework;inline=true,*;artifactId=gdxapp4d-lib-bassboonyd;inline=true + + ${tos4.packages} + love.distributedrebirth.gdxapp4d.tos4.GDXAppTos4Activator distributedrebirth.love diff --git a/gdxapp4d-tos4/src/main/java/love/distributedrebirth/gdxapp4d/tos4/GDXAppTos4Activator.java b/gdxapp4d-tos4/src/main/java/love/distributedrebirth/gdxapp4d/tos4/GDXAppTos4Activator.java index 0274339e..3a35036f 100644 --- a/gdxapp4d-tos4/src/main/java/love/distributedrebirth/gdxapp4d/tos4/GDXAppTos4Activator.java +++ b/gdxapp4d-tos4/src/main/java/love/distributedrebirth/gdxapp4d/tos4/GDXAppTos4Activator.java @@ -230,6 +230,7 @@ public class GDXAppTos4Activator implements BundleActivator { buf.append("BãßBȍőnAuthorInfoʸᴰ"); buf.append("@Ω仙⁴ ˧꜏⋇꜊꜔ ⁴ﷲΩ@"); buf.append("בְּרֵאשִׁית :o: יְסוֺד :o: יִשְׂרָאֵל"); + buf.append("⁰¹²³⁴⁵⁶⁷⁸⁹ˣᶜᴰ"); for (int c=0x0100;c<=0x0200;c++) { buf.append(""+(char)c); } diff --git a/gdxapp4d-unitxc/pom.xml b/gdxapp4d-unitxc/pom.xml new file mode 100644 index 00000000..b2a2b714 --- /dev/null +++ b/gdxapp4d-unitxc/pom.xml @@ -0,0 +1,64 @@ + + 4.0.0 + + love.distributedrebirth.gdxapp4d + gdxapp4d + 0.0.1-SNAPSHOT + + gdxapp4d-unitxc + GDXApp⁴ᴰ-Unitˣᶜ + bundle + + + love.distributedrebirth.gdxapp4d + gdxapp4d-tos4 + ${project.version} + + + org.apache.commons + commons-lang3 + + + + + + org.apache.felix + maven-bundle-plugin + true + + true + true + + <_donotcopy>(.git) + <_dsannotations>* + <_metatypeannotations>* + + ${tos4.packages}, + org.slf4j, + org.slf4j.event, + org.slf4j.helpers, + org.slf4j.spi, + org.apache.commons.lang3, + org.apache.commons.lang3.builder, + org.apache.commons.lang3.concurrent, + org.apache.commons.lang3.event, + org.apache.commons.lang3.exception, + org.apache.commons.lang3.math, + org.apache.commons.lang3.mutable, + org.apache.commons.lang3.reflect, + org.apache.commons.lang3.text, + org.apache.commons.lang3.text.translate, + org.apache.commons.lang3.time, + org.apache.commons.lang3.tuple + + + ${unitxc.packages} + + love.distributedrebirth.gdxapp4d.unitxc.UnitXrossConverterActivator + distributedrebirth.love + + + + + + \ No newline at end of file diff --git a/gdxapp4d-unitxc/src/main/java/love/distributedrebirth/gdxapp4d/unitxc/UnitXrossConverterActivator.java b/gdxapp4d-unitxc/src/main/java/love/distributedrebirth/gdxapp4d/unitxc/UnitXrossConverterActivator.java new file mode 100644 index 00000000..90ec6f47 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/love/distributedrebirth/gdxapp4d/unitxc/UnitXrossConverterActivator.java @@ -0,0 +1,35 @@ +package love.distributedrebirth.gdxapp4d.unitxc; + +import java.util.Hashtable; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; +import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxLog; +import net.forwardfire.unitxc.UnitXCFactory; +import net.forwardfire.unitxc.UnitXCManager; + +@BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") +public class UnitXrossConverterActivator implements BundleActivator { + + private UnitXCManager unitManager; + + @Override + public void stop(final BundleContext context) { + ServiceReference loggerRef = context.getServiceReference(SystemGdxLog.class); + SystemGdxLog logger = context.getService(loggerRef); + logger.debug(this, SystemGdxLog.DEACTIVATE); + unitManager = null; + } + + @Override + public void start(final BundleContext context) { + ServiceReference loggerRef = context.getServiceReference(SystemGdxLog.class); + SystemGdxLog logger = context.getService(loggerRef); + logger.debug(this, SystemGdxLog.ACTIVATE); + unitManager = UnitXCFactory.createManager(); + context.registerService(UnitXCManager.class.getName(), unitManager, new Hashtable()); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/UnitXCFactory.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/UnitXCFactory.java new file mode 100644 index 00000000..8cfce335 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/UnitXCFactory.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2014-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import net.forwardfire.unitxc.config.UnitXCConfigManager; +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.model.UnitXCConfig; +import net.forwardfire.unitxc.module.UnitXCModuleMole; +import net.forwardfire.unitxc.module.UnitXCModuleAmpere; +import net.forwardfire.unitxc.module.UnitXCModuleMetre; +import net.forwardfire.unitxc.module.UnitXCModuleCandela; +import net.forwardfire.unitxc.module.UnitXCModuleKilogram; +import net.forwardfire.unitxc.module.UnitXCModuleKelvin; +import net.forwardfire.unitxc.module.UnitXCModuleSecond; +import net.forwardfire.unitxc.module.derived.UnitXCModuleMetrePerSecondSquared; +import net.forwardfire.unitxc.module.derived.UnitXCModuleSquareMetre; +import net.forwardfire.unitxc.module.derived.UnitXCModuleKilogramPerSquareMetre; +import net.forwardfire.unitxc.module.derived.UnitXCModuleMetrePerSecondCubed; +import net.forwardfire.unitxc.module.derived.UnitXCModuleMetrePerQuarticSecond; +import net.forwardfire.unitxc.module.derived.UnitXCModuleKilogramPerCubicMetre; +import net.forwardfire.unitxc.module.derived.UnitXCModuleMolePerCubicMetre; +import net.forwardfire.unitxc.module.derived.UnitXCModuleCubicMetrePerMole; +import net.forwardfire.unitxc.module.derived.UnitXCModuleNewtonPerSecond; +import net.forwardfire.unitxc.module.derived.UnitXCModuleCubicMetrePerKilogram; +import net.forwardfire.unitxc.module.derived.UnitXCModuleMetrePerSecond; +import net.forwardfire.unitxc.module.derived.UnitXCModuleCubicMetre; +import net.forwardfire.unitxc.module.derived.UnitXCModuleCubicMetrePerSecond; +import net.forwardfire.unitxc.module.named.UnitXCModuleNewton; + +/** + * The unit cross converter factory to create the manager. + * + * @author Willem Cazander + * @version 1.0 Oct 9, 2015 + */ +public final class UnitXCFactory { + + private static final List DEFAULT_CONFIG_MODULES = Collections.unmodifiableList(Arrays.asList( + new UnitXCModuleKelvin(), + new UnitXCModuleAmpere(), + new UnitXCModuleCandela(), + new UnitXCModuleMole(), + new UnitXCModuleMetre(), + new UnitXCModuleKilogram(), + new UnitXCModuleSecond(), + + // currently ordered here + new UnitXCModuleSquareMetre(), + new UnitXCModuleCubicMetre(), + new UnitXCModuleMetrePerSecond(), + new UnitXCModuleCubicMetrePerSecond(), + new UnitXCModuleMetrePerSecondSquared(), + new UnitXCModuleMetrePerSecondCubed(), + new UnitXCModuleMetrePerQuarticSecond(), + + // named + new UnitXCModuleNewton(), + + // more derived + new UnitXCModuleKilogramPerSquareMetre(), + new UnitXCModuleKilogramPerCubicMetre(), + new UnitXCModuleCubicMetrePerKilogram(), + new UnitXCModuleMolePerCubicMetre(), + new UnitXCModuleCubicMetrePerMole(), + new UnitXCModuleNewtonPerSecond() + + )); + + + protected UnitXCFactory() { + } + + private static UnitXCConfig buildAll(UnitXCConfig config,List configInit) { + UnitXCConfigBuilder builder = new UnitXCConfigBuilder(config); + configInit.forEach(ci -> ci.configModule(builder)); + return config; + } + + public static UnitXCConfig createConfig() { + return createConfig(DEFAULT_CONFIG_MODULES); + } + + public static UnitXCConfig createConfig(List configInit) { + return buildAll(new UnitXCConfig(), configInit); + } + + public static UnitXCManager createManager() { + return createManager(createConfig()); + } + + public static UnitXCManager createManager(UnitXCConfig config) { + return new UnitXCConfigManager(config); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/UnitXCManager.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/UnitXCManager.java new file mode 100644 index 00000000..8e2eec5b --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/UnitXCManager.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc; + +import net.forwardfire.unitxc.converter.UnitXConverter; +import net.forwardfire.unitxc.model.UnitXCType; +import net.forwardfire.unitxc.model.UnitXCConfig; +import net.forwardfire.unitxc.model.UnitXCGroup; + +/** + * The unit manager which holds all units/groups and provides access to the converter. + * + * @author Willem Cazander + * @version 1.0 Oct 9, 2015 + */ +public interface UnitXCManager { + + UnitXCType getUnitType(String id); + + UnitXCGroup getUnitGroup(String id); + + boolean isUnitGroup(String id); + + UnitXConverter getConverter(); + + UnitXCConfig getConfig(); +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigManager.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigManager.java new file mode 100644 index 00000000..24073123 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigManager.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.config; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang3.Validate; + +import net.forwardfire.unitxc.UnitXCManager; +import net.forwardfire.unitxc.converter.UnitXConverter; +import net.forwardfire.unitxc.model.UnitXCType; +import net.forwardfire.unitxc.model.UnitXCConfig; +import net.forwardfire.unitxc.model.UnitXCGroup; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 17, 2015 + */ +public class UnitXCConfigManager implements UnitXCManager { + + private final UnitXCConfig config; + private final Map unitGroups; + private final UnitXConverter converter; + + public UnitXCConfigManager(UnitXCConfig config) { + this.config = Validate.notNull(config); + this.unitGroups = Collections.unmodifiableMap(createUnitGroups(config.getUnitGroups())); + this.converter = new UnitXConverter(this); + } + + private static Map createUnitGroups(Collection values) { + Map result = new HashMap<>(); + values.forEach((value) -> { + result.put(value.getId(), value); + }); + return result; + } + + @Override + public UnitXCConfig getConfig() { + return config; + } + + @Override + public UnitXCType getUnitType(String id) { + UnitXCType result = null; + for (UnitXCGroup group:unitGroups.values()) { + result = group.getUnitType(id); + if (result != null) { + break; + } + } + return result; + } + + @Override + public UnitXCGroup getUnitGroup(String id) { + return Validate.notNull(unitGroups.get(Validate.notNull(id,"Null is not a validate id.")),"No group for: "+id); + } + + @Override + public boolean isUnitGroup(String id) { + return unitGroups.containsKey(Validate.notBlank(id)); + } + + @Override + public UnitXConverter getConverter() { + return converter; + } + +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigModule.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigModule.java new file mode 100644 index 00000000..4a580db2 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigModule.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.config; + +import java.util.Arrays; + +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; + +/** + * Config module to build groups and types. + * + * @author Willem Cazander + * @version 1.0 Oct 17, 2015 + */ +public interface UnitXCConfigModule { + + void configModule(UnitXCConfigBuilder config); + + static String buildFlag(String...flag) { + StringBuilder buf = new StringBuilder(); + Arrays.asList(flag).forEach(f -> buf.append(f.toUpperCase()).append("_")); + return buf.deleteCharAt(buf.length()-1).toString(); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCBuilder.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCBuilder.java new file mode 100644 index 00000000..3f33e522 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCBuilder.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.forwardfire.unitxc.config.builder; + +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +import org.apache.commons.lang3.Validate; +import org.apache.commons.lang3.builder.Builder; + +/** + * Abstract object builder with parent builder. + * + * + * @param

The parent builder. + * @param The object to build. + * @param This builder. + * @author Willem Cazander + * @version 1.0 Oct 22, 2015 + */ +public abstract class AbstractUnitXCBuilder implements Builder

{ + + private final P parent; + private final T value; + private final BiConsumer parentBuilder; + + /** + * Creates the builder. + * @param parent The parent builder. + * @param value The object to build. + */ + public AbstractUnitXCBuilder(P parent,T value,BiConsumer parentBuilder) { + this.parent = Validate.notNull(parent); + this.value = Validate.notNull(value); + this.parentBuilder = Validate.notNull(parentBuilder); + } + + protected P getParent() { + return parent; + } + + protected T getValue() { + return value; + } + + protected abstract B getBuilder(); + + /** + * Builds the result. + * @return The result. + */ + @Override + public final P build() { + buildPreValue(getValue()); + parentBuilder.accept(getParent(), getValue()); + return getParent(); + } + + protected void buildPreValue(T value) { + } + + protected B make(Consumer mixer) { + mixer.accept(getValue()); + return getBuilder(); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCGroupBuilder.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCGroupBuilder.java new file mode 100644 index 00000000..1b735227 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCGroupBuilder.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.config.builder; + +import java.util.Arrays; +import java.util.function.BiConsumer; + +import net.forwardfire.unitxc.model.AbstractUnitXCGroup; +import net.forwardfire.unitxc.model.DefaultUnitXCGroupQuantity; +import net.forwardfire.unitxc.model.DefaultUnitXCType; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 28, 2016 + */ +abstract public class AbstractUnitXCGroupBuilder extends AbstractUnitXCBuilder { + + public AbstractUnitXCGroupBuilder(P parent, T model, BiConsumer parentBuilder) { + super(parent, model, parentBuilder); + } + + public UnitXCGroupJumpBuilder> createGroupJump(String unitGroupId) { + return new UnitXCGroupJumpBuilder<>(this,getValue(),unitGroupId,(p,v) -> p.getValue().addGroupJump(v)); + } + + public UnitXCTypeBuilder> createUnitType() { + return new UnitXCTypeBuilder<>(this,new DefaultUnitXCType(),(p,v) -> p.getValue().addUnitType(v)); + } + + public B setBaseTypeId(String baseTypeId) { + return make((v) -> v.setBaseTypeId(baseTypeId)); + } + + public B addQuantityId(String id) { + return make((v) -> v.addQuantity(new DefaultUnitXCGroupQuantity(null,"group."+v.getId()+".quantity",id))); // TODO: fix null bundle here + } + + public B addQuantityIds(String...ids) { + Arrays.asList(ids).forEach(id -> addQuantityId(id)); + return getBuilder(); + } + +// public B addDerivedFrom(String fromId) { +// return make((v) -> v.addDerivedFrom(fromId)); +// } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCTypeBuilder.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCTypeBuilder.java new file mode 100644 index 00000000..1567843a --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCTypeBuilder.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.config.builder; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.function.BiConsumer; + +import net.forwardfire.unitxc.model.DefaultUnitXCType; +import net.forwardfire.unitxc.model.UnitXCType; +import net.forwardfire.unitxc.model.step.UnitXConverterStep; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 22, 2015 + */ +public abstract class AbstractUnitXCTypeBuilder extends AbstractUnitXCBuilder { + + public AbstractUnitXCTypeBuilder(P parent,DefaultUnitXCType model,BiConsumer parentBuilder) { + super(parent, model, parentBuilder); + } + + @Override + protected final void buildPreValue(DefaultUnitXCType value) { + if (value.getNamePlural() == null) { + setNamePlurals(); + } + if (value.getAliasOfType() != null && !value.getTypeFlags().contains(UnitXCConfigBuilder.TYPE_FLAG_ALIAS)) { + value.getTypeFlags().add(UnitXCConfigBuilder.TYPE_FLAG_ALIAS); + } + buildModel(value); + } + + protected void buildModel(UnitXCType value) { + } + + public B setId(String id) { + return make((v) -> v.setId(id)); + } + + public B setName(String name) { + return make((v) -> v.setName(name)); + } + + public B setNamePlurals() { + return setNamePlural(getValue().getName()+"s"); + } + + public B setNamePlural(String name) { + return make((v) -> v.setNamePlural(name)); + } + + public B setAliasOfType(String aliasOfType) { + return make((v) -> v.setAliasOfType(aliasOfType)); + } + + public B setWebLinkWiki(String websiteLink) { + return setWebLink(UnitXCConfigBuilder.WIKI_BASE_URL+websiteLink); + } + + public B setWebLink(String websiteLink) { + return make((v) -> v.setWebLink(websiteLink)); + } + + public B addTypeFlag(String flag) { + return make((v) -> v.getTypeFlags().add(flag)); + } + + public B addTypeFlags(Collection flags) { + return make(v -> flags.forEach(flag -> v.getTypeFlags().add(flag))); + } + + public B addTypeFlags(String[] flags) { + return addTypeFlags(Arrays.asList(flags)); + } + + public UnitXConverterStepBuilder> createFromBaseConverterSteps() { + return new UnitXConverterStepBuilder<>(this,(p,v) -> p.addFromBaseConverterSteps(v),() -> "convert "+getValue().getId()); + } + + public UnitXConverterStepBuilder> createToBaseConverterSteps() { + return new UnitXConverterStepBuilder<>(this,(p,v) -> p.addToBaseConverterSteps(v),() -> "convert "+getValue().getId()); + } + + public B addFromBaseConverterStep(UnitXConverterStep unitTypeConverter) { + return make((v) -> v.getFromBaseConverterSteps().add(unitTypeConverter)); + } + + public B addFromBaseConverterSteps(List unitTypeConverters) { + return make((v) -> unitTypeConverters.forEach(c -> v.getFromBaseConverterSteps().add(c))); + } + + public B addToBaseConverterStep(UnitXConverterStep unitTypeConverter) { + return make((v) -> v.getToBaseConverterSteps().add(unitTypeConverter)); + } + + public B addToBaseConverterSteps(List unitTypeConverters) { + return make((v) -> unitTypeConverters.forEach(c -> v.getToBaseConverterSteps().add(c))); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCConfigBuilder.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCConfigBuilder.java new file mode 100644 index 00000000..e5c29c3e --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCConfigBuilder.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.config.builder; + +import java.util.Locale; +import java.util.ResourceBundle; + +import org.apache.commons.lang3.Validate; + +import net.forwardfire.unitxc.model.AbstractUnitXCGroup; +import net.forwardfire.unitxc.model.UnitXCConfig; +import net.forwardfire.unitxc.model.UnitXCGroup; +import net.forwardfire.unitxc.model.UnitXCGroupBase; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundExponent; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; +import net.forwardfire.unitxc.model.UnitXCResourceBundle; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 17, 2015 + */ +public class UnitXCConfigBuilder { + + public static final String TYPE_FLAG_IMPERIAL = "IMPERIAL"; // TODO: move to ... + public static final String TYPE_FLAG_IMPERIAL_EXTRA = "IMPERIAL_EXTRA"; + public static final String TYPE_FLAG_ALIAS = "ALIAS"; + + public static final String WIKI_BASE_URL = "https://en.wikipedia.org/wiki/"; + + private final UnitXCConfig config; + private final UnitXCResourceBundle bundle; + + public UnitXCConfigBuilder(UnitXCConfig config) { + this.config = Validate.notNull(config); + this.bundle = new UnitXCResourceBundle(); + this.initBundle(); + } + + private void initBundle() { + config.getLanguages().add(Locale.forLanguageTag("")); + for (Locale l:config.getLanguages()) { + String language = l.toLanguageTag(); + ResourceBundle b = ResourceBundle.getBundle("net.forwardfire.unitxc.UnitXCBundle", l); + //System.out.println("loading bundle language: "+language+" baseBundle: "+b.getBaseBundleName()+" size: "+b.keySet().size()); + b.keySet().forEach(k -> bundle.addData(language, k, b.getString(k))); + } + } + + protected UnitXCConfig getConfig() { + return config; + } + + public UnitXCGroupBaseBuilder createUnitGroupBase(String groupId) { + return new UnitXCGroupBaseBuilder(this, new UnitXCGroupBase(bundle,groupId), (p,v) -> p.getConfig().addUnitGroup(v)); + } + + public UnitXCGroupCompoundPairBuilder createUnitGroupCompoundPair(String groupId, String parentGroupId, String parentPerGroupId) { + return new UnitXCGroupCompoundPairBuilder(this, new UnitXCGroupCompoundPair(bundle,groupId,findGroup(parentGroupId),findGroup(parentPerGroupId)), (p,v) -> p.getConfig().addUnitGroup(v)); + } + + public UnitXCGroupCompoundExponentBuilder createUnitGroupCompoundExponent(String groupId, String parentGroupId, int exponent) { + return new UnitXCGroupCompoundExponentBuilder(this, new UnitXCGroupCompoundExponent(bundle,groupId,findGroup(parentGroupId),exponent), (p,v) -> p.getConfig().addUnitGroup(v)); + } + + public UnitXCGroupExtendBuilder extendUnitGroup(String groupId) { + UnitXCGroup group = findGroup(groupId); + return new UnitXCGroupExtendBuilder(this, AbstractUnitXCGroup.class.cast(group), (p,v) -> {}); + } + + private UnitXCGroup findGroup(String id) { + Validate.notBlank(id,"Can't search blank id."); + for (UnitXCGroup m:config.getUnitGroups()) { + if (m.getId().equals(id)) { + return m; + } + } + throw new IllegalArgumentException("Could not find: "+id); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCConfigModuleBuilder.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCConfigModuleBuilder.java new file mode 100644 index 00000000..458dfe05 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCConfigModuleBuilder.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.config.builder; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 31, 2015 + */ +public class UnitXCConfigModuleBuilder { + +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupBaseBuilder.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupBaseBuilder.java new file mode 100644 index 00000000..01a3237d --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupBaseBuilder.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.config.builder; + +import java.util.function.BiConsumer; + +import net.forwardfire.unitxc.model.UnitXCGroupBase; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 22, 2015 + */ +public class UnitXCGroupBaseBuilder extends AbstractUnitXCGroupBuilder { + + public UnitXCGroupBaseBuilder(UnitXCConfigBuilder parent, UnitXCGroupBase model, BiConsumer parentBuilder) { + super(parent, model, parentBuilder); + } + + @Override + protected UnitXCGroupBaseBuilder getBuilder() { + return this; + } + + public UnitXCTypeSIPrefixBuilder createSIUnitTypes() { + return new UnitXCTypeSIPrefixBuilder<>(this,this); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupCompoundExponentBuilder.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupCompoundExponentBuilder.java new file mode 100644 index 00000000..a73bd0e5 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupCompoundExponentBuilder.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.config.builder; + +import java.util.function.BiConsumer; + +import net.forwardfire.unitxc.model.UnitXCGroupCompoundExponent; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 26, 2015 + */ +public class UnitXCGroupCompoundExponentBuilder extends AbstractUnitXCGroupBuilder { + + public UnitXCGroupCompoundExponentBuilder(UnitXCConfigBuilder parent, UnitXCGroupCompoundExponent model, BiConsumer parentBuilder) { + super(parent, model, parentBuilder); + } + + @Override + protected UnitXCGroupCompoundExponentBuilder getBuilder() { + return this; + } + + @Override + protected void buildPreValue(UnitXCGroupCompoundExponent value) { + // TODO: move + getValue().getDerivedFrom().add(getValue().getParentGroup().getId()); + } + + + public UnitXCGroupCompoundExponentBuilder setUnitIdPostfix(String unitIdPostfix) { + return make(v -> v.setUnitIdPostfix(unitIdPostfix)); + } + + public UnitXCGroupCompoundExponentBuilder setUnitNamePrefix(String unitNamePrefix) { + return make(v -> v.setUnitNamePrefix(unitNamePrefix)); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupCompoundPairBuilder.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupCompoundPairBuilder.java new file mode 100644 index 00000000..11950224 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupCompoundPairBuilder.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.config.builder; + +import java.util.function.BiConsumer; + +import net.forwardfire.unitxc.model.UnitXCGroup; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueNamedParameter; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 26, 2015 + */ +public class UnitXCGroupCompoundPairBuilder extends AbstractUnitXCGroupBuilder { + + public UnitXCGroupCompoundPairBuilder(UnitXCConfigBuilder parent, UnitXCGroupCompoundPair model, BiConsumer parentBuilder) { + super(parent, model, parentBuilder); + } + + @Override + protected UnitXCGroupCompoundPairBuilder getBuilder() { + return this; + } + + @Override + protected void buildPreValue(UnitXCGroupCompoundPair value) { + + UnitXCGroup group = getValue().getParentGroup(); + UnitXCGroup perGroup = getValue().getParentPerGroup(); + + // TODO: do once !! + // TODO: move + getValue().getDerivedFrom().add(group.getId()); + getValue().getDerivedFrom().add(perGroup.getId()); +// +// UnitXCGroupJump toGroupJump = new UnitXCGroupJump(); +// toGroupJump.setId("to_"+group.getId()); +// toGroupJump.setUnitGroup(group); +// toGroupJump.addJumpParameter(new UnitXCGroupJumpParameter("to_"+perGroup.getId(),"",perGroup.getId())); +// +// UnitXCGroupJump perGroupJump = new UnitXCGroupJump(); +// perGroupJump.setId("to_"+group.getId()); +// perGroupJump.setUnitGroup(group); + + //getValue().getGroupJumps().add(toGroupJump); // m/s -> m + //getValue().getGroupJumps().add(perGroupJump); // m/s -> h + + //group.getGroupJumps().add(toGroupJump); // m -> m/s + //perGroup.getGroupJumps().add(perGroupJump); // s -> m/s + + // m/s -> m + createGroupJump(group.getId()) + .addJumpParameter(value.getId()+"_"+perGroup.getId(),perGroup.getId()) + .createToGroupConverterSteps() + .multiply(new UnitXConverterStepValueNamedParameter(value.getId()+"_"+perGroup.getId())) + .build() + .build(); + + // m -> m/s + getParent().extendUnitGroup(group.getId()) + .createGroupJump(value.getId()) + .addJumpParameter(value.getId()+"_"+perGroup.getId(),perGroup.getId()) + .createToGroupConverterSteps() + .divide(new UnitXConverterStepValueNamedParameter(value.getId()+"_"+perGroup.getId())) + .build() + .build(); + + + //FIXME + // m/s -> s + createGroupJump(perGroup.getId()) + .addJumpParameter(value.getId()+"_"+group.getId(),group.getId()) + .createToGroupConverterSteps() + .multiply(new UnitXConverterStepValueNamedParameter(value.getId()+"_"+group.getId())) + .build() + .build(); + + // s -> m/s + getParent().extendUnitGroup(perGroup.getId()) + .createGroupJump(value.getId()) + .addJumpParameter(value.getId()+"_"+group.getId(),group.getId()) + .createToGroupConverterSteps() + .divide(new UnitXConverterStepValueNamedParameter(value.getId()+"_"+group.getId())) + .build() + .build(); + + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupExtendBuilder.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupExtendBuilder.java new file mode 100644 index 00000000..a7e04838 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupExtendBuilder.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.config.builder; + +import java.util.function.BiConsumer; + +import net.forwardfire.unitxc.model.AbstractUnitXCGroup; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 28, 2016 + */ +public class UnitXCGroupExtendBuilder extends AbstractUnitXCGroupBuilder { + + public UnitXCGroupExtendBuilder(UnitXCConfigBuilder parent, AbstractUnitXCGroup model, BiConsumer parentBuilder) { + super(parent, model, parentBuilder); + } + + @Override + protected UnitXCGroupExtendBuilder getBuilder() { + return this; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupJumpBuilder.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupJumpBuilder.java new file mode 100644 index 00000000..a0273b49 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupJumpBuilder.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.config.builder; + + +import java.util.function.BiConsumer; + +import net.forwardfire.unitxc.model.DefaultUnitXCGroupJump; +import net.forwardfire.unitxc.model.DefaultUnitXCGroupJumpParameter; +import net.forwardfire.unitxc.model.UnitXCGroup; +import net.forwardfire.unitxc.model.UnitXCGroupJumpParameter; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Apr 1, 2016 + */ +public class UnitXCGroupJumpBuilder

extends AbstractUnitXCBuilder> { + + public UnitXCGroupJumpBuilder(P parent, UnitXCGroup forGroup, String unitGroupId,BiConsumer parentBuilder) { + super(parent, new DefaultUnitXCGroupJump(), parentBuilder); + getValue().setUnitGroupId(unitGroupId); + getValue().setId(forGroup.getId()+"_"+unitGroupId); + } + + @Override + protected UnitXCGroupJumpBuilder

getBuilder() { + return this; + } + + public UnitXCGroupJumpBuilder

setId(String id) { + return make((v) -> v.setId(id)); + } + + public UnitXCGroupJumpBuilder

addJumpParameter(String id,String unitGroupId) { + return make((v) -> v.addJumpParameter(new DefaultUnitXCGroupJumpParameter(id, unitGroupId))); + } + + public UnitXConverterStepBuilder> createToGroupConverterSteps() { + return new UnitXConverterStepBuilder<>(this,(p,v) -> getValue().getToGroupConverterSteps().addAll(v),() -> "group jump"); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCNumberTypeSetting.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCNumberTypeSetting.java new file mode 100644 index 00000000..c1f278bc --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCNumberTypeSetting.java @@ -0,0 +1,35 @@ +package net.forwardfire.unitxc.config.builder; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 28, 2015 + */ +public class UnitXCNumberTypeSetting { + + private static final char ZERO_CHAR_NORMAL = '0'; + private static final char ZERO_CHAR_SUB = '₀'; + private static final char ZERO_CHAR_SUPER = '⁰'; + + public static String toSuperScript(int value) { + return printScript(value, ZERO_CHAR_SUPER, new StringBuilder()).toString(); + } + + public static String toSubScript(int value) { + return printScript(value, ZERO_CHAR_SUB, new StringBuilder()).toString(); + } + + private static StringBuilder printScript(int value,char zeroChar,StringBuilder buf) { + String number = Integer.toString(value); + for (char c:number.toCharArray()) { + int offset = c-ZERO_CHAR_NORMAL; + int scriptChar = zeroChar+offset; + if (scriptChar==0x2072 || scriptChar==0x2073) { // TODO: rewrite to lookup table + scriptChar-=(0x2070-0x00B0); // utf-8 is iso-8859-1 compatible :( + } + buf.append((char)scriptChar); + } + return buf; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeBuilder.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeBuilder.java new file mode 100644 index 00000000..579c73d7 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeBuilder.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.config.builder; + +import java.util.function.BiConsumer; + +import net.forwardfire.unitxc.model.DefaultUnitXCType; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 23, 2015 + */ +public class UnitXCTypeBuilder

extends AbstractUnitXCTypeBuilder> { + + public UnitXCTypeBuilder(P parent,DefaultUnitXCType model, BiConsumer parentBuilder) { + super(parent,model, parentBuilder); + } + + @Override + protected UnitXCTypeBuilder

getBuilder() { + return this; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeSIPrefix.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeSIPrefix.java new file mode 100644 index 00000000..b9e131b1 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeSIPrefix.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.config.builder; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 22, 2015 + */ +public enum UnitXCTypeSIPrefix { + + YOTTA ("Y", 24), + ZETTA ("Z", 21), + EXA ("E", 18), + PETA ("P", 15), + TERA ("T", 12), + GIGA ("G", 9), + MEGA ("M", 6), + KILO ("k", 3), + HECTO ("h", 2), + DECA ("da",1), + DECI ("d", -1), + CENTI ("c", -2), + MILLI ("m", -3), + MICRO ("µ", -6, null, UnitXCTypeSIPrefix.NAME_ALIAS_MILLIMILLI), + NANO ("n", -9, null, UnitXCTypeSIPrefix.NAME_ALIAS_MILLIMICRO), + PICO ("p", -12, null, UnitXCTypeSIPrefix.NAME_ALIAS_MICROMICRO), + FEMTO ("f", -15), + ATTO ("a", -18), + ZEPTO ("z", -21), + YOCTO ("y", -24), + + EXBI ("Ei", 60, UnitXCTypeSIPrefix.TYPE_FLAG_SI_UNIT_BINARY), + PEBI ("Pi", 50, UnitXCTypeSIPrefix.TYPE_FLAG_SI_UNIT_BINARY), + TEBI ("Ti", 40, UnitXCTypeSIPrefix.TYPE_FLAG_SI_UNIT_BINARY), + GIBI ("Gi", 30, UnitXCTypeSIPrefix.TYPE_FLAG_SI_UNIT_BINARY), + MEBI ("Mi", 20, UnitXCTypeSIPrefix.TYPE_FLAG_SI_UNIT_BINARY), + KIBI ("Ki", 10, UnitXCTypeSIPrefix.TYPE_FLAG_SI_UNIT_BINARY), + + HECTOKILO ("hk", 5, UnitXCTypeSIPrefix.TYPE_FLAG_SI_UNIT_OBSOLETE), + MYRIA ("my", 4, UnitXCTypeSIPrefix.TYPE_FLAG_SI_UNIT_OBSOLETE), + ; + + public static final String TYPE_FLAG_SI_UNIT = "SI_UNIT"; + public static final String TYPE_FLAG_SI_UNIT_BIGGER = "SI_UNIT_BIGGER"; + public static final String TYPE_FLAG_SI_UNIT_BIGGEST = "SI_UNIT_BIGGEST"; + public static final String TYPE_FLAG_SI_UNIT_BINARY = "SI_UNIT_BINARY"; + public static final String TYPE_FLAG_SI_UNIT_OBSOLETE = "SI_UNIT_OBSOLETE"; + public static final String TYPE_FLAG_SI_UNIT_COMMON = "SI_UNIT_COMMON"; + + public static final String NAME_ALIAS_MILLIMILLI = "millimilli"; + public static final String NAME_ALIAS_MILLIMICRO = "millimicro"; + public static final String NAME_ALIAS_MICROMICRO = "micromicro"; + + private final String id; + private final String name; + private final int exponent; + private final List flags; + private final List nameAliases; + + private UnitXCTypeSIPrefix(String id,int exponent) { + this(id,exponent,null); + } + + private UnitXCTypeSIPrefix(String id,int exponent,String flag,String...names) { + this.id=id; + this.name = this.name().toLowerCase(); + this.exponent=exponent; + List f = new ArrayList<>(3); + f.add(TYPE_FLAG_SI_UNIT); + if (exponent > 3 || exponent < -3) { + f.add(TYPE_FLAG_SI_UNIT_BIGGER); + } + if (exponent > 12 || exponent < -12) { + f.add(TYPE_FLAG_SI_UNIT_BIGGEST); + } + if (flag != null) { + f.add(flag); + } + this.flags = Collections.unmodifiableList(f); + List n = new ArrayList<>(2); + n.addAll(Arrays.asList(names)); + this.nameAliases = Collections.unmodifiableList(n); + } + + public String getPrefixId() { + return id; + } + + public String getPrefixName() { + return name; + } + + public int getExponent() { + return exponent; + } + + public List getFlags() { + return flags; + } + + public List getNameAliases() { + return nameAliases; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeSIPrefixBuilder.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeSIPrefixBuilder.java new file mode 100644 index 00000000..f2ab47c2 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeSIPrefixBuilder.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.config.builder; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import net.forwardfire.unitxc.model.DefaultUnitXCType; +import net.forwardfire.unitxc.model.UnitXCType; +import net.forwardfire.unitxc.model.step.UnitXCConverterStepPowerOfTen; +import net.forwardfire.unitxc.model.step.UnitXConverterStepContext; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 22, 2015 + */ +public class UnitXCTypeSIPrefixBuilder

extends AbstractUnitXCTypeBuilder> { + + private final UnitXCGroupBaseBuilder builder; + private final List commonSIPrefixes; + + public UnitXCTypeSIPrefixBuilder(P parent, UnitXCGroupBaseBuilder builder) { + super(parent,new DefaultUnitXCType(), (p,v) -> {}); + this.builder = builder; + this.commonSIPrefixes = new ArrayList<>(); + } + + @Override + protected UnitXCTypeSIPrefixBuilder

getBuilder() { + return this; + } + + @Override + protected void buildModel(UnitXCType v) { + + // FIXME: if v.getAliasOfType() != null than skip copy steps + + builder.createUnitType() + .setId(v.getId()) + .setName(v.getName()) + .setNamePlural(v.getNamePlural()) + .setWebLink(v.getWebLink()) + .addTypeFlags(v.getTypeFlags()) + .addFromBaseConverterSteps(v.getFromBaseConverterSteps()) + .addToBaseConverterSteps(v.getToBaseConverterSteps()) + .build(); + + for (UnitXCTypeSIPrefix sim:UnitXCTypeSIPrefix.values()) { + List typeFlags = new ArrayList<>(); + typeFlags.addAll(v.getTypeFlags()); + typeFlags.addAll(sim.getFlags()); + if (commonSIPrefixes.contains(sim)) { + typeFlags.add(UnitXCTypeSIPrefix.TYPE_FLAG_SI_UNIT_COMMON); + } + builder.createUnitType() + .setId(sim.getPrefixId()+v.getId()) + .setName(sim.getPrefixName()+v.getName()) + .setNamePlural(sim.getPrefixName()+v.getNamePlural()) + .addTypeFlags(typeFlags) + //.addWebsiteLinks(v.getWebsiteLinks()) + .addToBaseConverterStep(new UnitXCConverterStepPowerOfTen(sim.getExponent(),false,UnitXConverterStepContext.createStepValue(),UnitXConverterStepContext.createStepValue()).buildReason("Move dot for SI")) + .addToBaseConverterSteps(v.getToBaseConverterSteps()) + .addFromBaseConverterSteps(v.getFromBaseConverterSteps()) + .addFromBaseConverterStep(new UnitXCConverterStepPowerOfTen(sim.getExponent(),true,UnitXConverterStepContext.createStepValue(),UnitXConverterStepContext.createStepValue()).buildReason("Move dot for SI")) + .build(); + + //for (String typeAlias:sim.getNameAliases()) { + // + //} + } + } + + public UnitXCTypeSIPrefixBuilder

addCommonSIPrefixes(UnitXCTypeSIPrefix[] prefixes) { + return make(t -> addCommonSIPrefixes(Arrays.asList(prefixes))); + } + + public UnitXCTypeSIPrefixBuilder

addCommonSIPrefixes(Collection prefixes) { + return make(t -> prefixes.forEach(prefix -> addCommonSIPrefix(prefix))); + } + + public UnitXCTypeSIPrefixBuilder

addCommonSIPrefix(UnitXCTypeSIPrefix prefix) { + return make((v) -> commonSIPrefixes.add(prefix)); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXConverterStepBuilder.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXConverterStepBuilder.java new file mode 100644 index 00000000..2c2c6d9b --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/UnitXConverterStepBuilder.java @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.config.builder; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.BiConsumer; +import java.util.function.Supplier; + +import org.apache.commons.lang3.Validate; +import org.apache.commons.lang3.math.Fraction; + +import net.forwardfire.unitxc.model.step.UnitXCConverterStepOperation; +import net.forwardfire.unitxc.model.step.UnitXCConverterStepOperationOperator; +import net.forwardfire.unitxc.model.step.UnitXCConverterStepPowerOfTen; +import net.forwardfire.unitxc.model.step.UnitXConverterStep; +import net.forwardfire.unitxc.model.step.UnitXConverterStepContext; +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead; +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReferenceDouble; +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReferenceDoubleFraction; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 23, 2015 + */ +public class UnitXConverterStepBuilder

> extends AbstractUnitXCBuilder,UnitXConverterStepBuilder

> { + + private final Supplier stepReason; + + public UnitXConverterStepBuilder(P parent, BiConsumer> parentBuilder, Supplier stepReason) { + super(parent, new ArrayList<>(), parentBuilder); + this.stepReason = Validate.notNull(stepReason); + } + + @Override + protected UnitXConverterStepBuilder

getBuilder() { + return this; + } + + private String createStepReason() { + return stepReason.get(); + //return "convert "+getParent().getValue().getId(); + } + + private UnitXCConverterStepOperation createStepOperation(UnitXCConverterStepOperationOperator op,UnitXConverterStepValueRead opB) { + return new UnitXCConverterStepOperation(op,UnitXConverterStepContext.createStepValue(),opB,UnitXConverterStepContext.createStepValue()); + } + + public UnitXConverterStepBuilder

offsetUp(double offset,String stepReason) { + return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.ADD,new UnitXConverterStepValueReferenceDouble(offset)))); + } + public UnitXConverterStepBuilder

offsetDown(double offset,String stepReason) { + return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.SUBTRACT,new UnitXConverterStepValueReferenceDouble(offset)))); + } + public UnitXConverterStepBuilder

offsetUp(double offset) { + return offsetUp(offset,createStepReason()); + } + public UnitXConverterStepBuilder

offsetDown(double offset) { + return offsetDown(offset,createStepReason()); + } + + + public UnitXConverterStepBuilder

multiply(Fraction fraction,String stepReason) { + return multiply(fraction.getNumerator(),fraction.getDenominator(),stepReason); + } + public UnitXConverterStepBuilder

multiply(int numerator,int denominator,String stepReason) { + return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.MULTIPLY,new UnitXConverterStepValueReferenceDoubleFraction(numerator,denominator)))); + } + public UnitXConverterStepBuilder

multiply(Fraction fraction) { + return multiply(fraction,createStepReason()); + } + public UnitXConverterStepBuilder

multiply(int numerator,int denominator) { + return multiply(numerator,denominator,createStepReason()); + } + + public UnitXConverterStepBuilder

multiply(UnitXConverterStepValueRead factor,String stepReason) { + return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.MULTIPLY,factor))); + } + public UnitXConverterStepBuilder

multiply(double factor,String stepReason) { + return multiply(new UnitXConverterStepValueReferenceDouble(factor),stepReason); + } + public UnitXConverterStepBuilder

divide(UnitXConverterStepValueRead factor,String stepReason) { + return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.DIVIDE,factor))); + } + public UnitXConverterStepBuilder

divide(double factor,String stepReason) { + return divide(new UnitXConverterStepValueReferenceDouble(factor),stepReason); + } + public UnitXConverterStepBuilder

multiply(double factor) { + return multiply(factor,createStepReason()); + } + public UnitXConverterStepBuilder

multiply(UnitXConverterStepValueRead factor) { + return multiply(factor,createStepReason()); + } + public UnitXConverterStepBuilder

divide(UnitXConverterStepValueRead factor) { + return divide(factor,createStepReason()); + } + public UnitXConverterStepBuilder

divide(double factor) { + return divide(factor,createStepReason()); + } + + public UnitXConverterStepBuilder

power(double exponent,String stepReason) { + return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.POWER,new UnitXConverterStepValueReferenceDouble(exponent)))); + } + public UnitXConverterStepBuilder

power(double exponent) { + return power(exponent,createStepReason()); + } + + + private UnitXConverterStepBuilder

powerOfTen(int exponent,boolean rev,String stepReason) { + return make(v -> v.add(new UnitXCConverterStepPowerOfTen(exponent,rev,UnitXConverterStepContext.createStepValue(),UnitXConverterStepContext.createStepValue()).buildReason(stepReason))); + } + public UnitXConverterStepBuilder

power10Up(UnitXCTypeSIPrefix exponent,String stepReason) { + return powerOfTen(exponent.getExponent(), true,stepReason); + } + public UnitXConverterStepBuilder

power10Down(UnitXCTypeSIPrefix exponent,String stepReason) { + return powerOfTen(exponent.getExponent(), false,stepReason); + } + public UnitXConverterStepBuilder

power10Up(UnitXCTypeSIPrefix exponent) { + return power10Up(exponent,createStepReason()); + } + public UnitXConverterStepBuilder

power10Down(UnitXCTypeSIPrefix exponent) { + return power10Down(exponent,createStepReason()); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/package-info.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/package-info.java new file mode 100644 index 00000000..153fb496 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/builder/package-info.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/** + * @author willemc + * + */ +package net.forwardfire.unitxc.config.builder; \ No newline at end of file diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/package-info.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/package-info.java new file mode 100644 index 00000000..9055cbde --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/config/package-info.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/** + * @author willemc + * + */ +package net.forwardfire.unitxc.config; \ No newline at end of file diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/converter/UnitXConverter.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/converter/UnitXConverter.java new file mode 100644 index 00000000..e2eecd67 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/converter/UnitXConverter.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.converter; + +import java.math.BigDecimal; +import java.util.Collections; +import java.util.Map; + +import org.apache.commons.lang3.Validate; + +import net.forwardfire.unitxc.UnitXCManager; +import net.forwardfire.unitxc.model.UnitXCType; +import net.forwardfire.unitxc.model.UnitXConverterResult; + +/** + * Converts value to value. + * + * @author Willem Cazander + * @version 1.0 Oct 8, 2015 + */ +public class UnitXConverter { + + private final UnitXCManager unitManager; + private final UnitXConverterEngine convertEngine; + + public UnitXConverter(UnitXCManager unitManager) { + this.unitManager = Validate.notNull(unitManager); + this.convertEngine = new UnitXConverterEngine(unitManager); + } + + private UnitXCType getUnitType(String id) { + return Validate.notNull(unitManager.getUnitType(id),"Could not resolve unit type for id; '"+id+"'"); + } + + public double convert(double value, String fromTypeId, String toTypeId) { + return convert(value, getUnitType(fromTypeId), getUnitType(toTypeId)); + } + + public double convert(double value, UnitXCType fromType, UnitXCType toType) { + return convertStepped(value,fromType,toType).getResultValue(); + } + + public UnitXConverterResult convertStepped(double value, String fromTypeId, String toTypeId) { + return convertStepped(value, getUnitType(fromTypeId), getUnitType(toTypeId)); + } + + public UnitXConverterResult convertStepped(double value, String fromTypeId, String toTypeId,Map parameters) { + return convertStepped(value, getUnitType(fromTypeId), getUnitType(toTypeId), parameters); + } + + public UnitXConverterResult convertStepped(double value, UnitXCType fromType, UnitXCType toType) { + return convertStepped(value, fromType, toType, Collections.emptyMap()); + } + + public UnitXConverterResult convertStepped(double value, UnitXCType fromType, UnitXCType toType, Map parameters) { + return convertStepped(BigDecimal.valueOf(value), fromType, toType, parameters); + } + + public UnitXConverterResult convertStepped(BigDecimal value, UnitXCType fromType, UnitXCType toType, Map parameters) { + return convertEngine.convertStepped(value, fromType, toType, parameters); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/converter/UnitXConverterEngine.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/converter/UnitXConverterEngine.java new file mode 100644 index 00000000..7697887a --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/converter/UnitXConverterEngine.java @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.converter; + +import java.math.BigDecimal; +import java.math.MathContext; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.Validate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.forwardfire.unitxc.UnitXCManager; +import net.forwardfire.unitxc.model.DefaultUnitXConverterResult; +import net.forwardfire.unitxc.model.DefaultUnitXConverterResultStep; +import net.forwardfire.unitxc.model.UnitXCGroup; +import net.forwardfire.unitxc.model.UnitXCGroupJump; +import net.forwardfire.unitxc.model.UnitXCGroupJumpParameter; +import net.forwardfire.unitxc.model.UnitXCType; +import net.forwardfire.unitxc.model.UnitXConverterResult; +import net.forwardfire.unitxc.model.UnitXConverterResultStep; +import net.forwardfire.unitxc.model.step.UnitXCConverterStepAutoRounding; +import net.forwardfire.unitxc.model.step.UnitXConverterStep; +import net.forwardfire.unitxc.model.step.UnitXConverterStepContext; +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead; +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReadWrite; +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReferenceDouble; + +/** + * Runs requested convert steps and builds result models. + * + * @author Willem Cazander + * @version 1.0 Oct 17, 2015 + */ +public final class UnitXConverterEngine { + + private final static Logger LOG = LoggerFactory.getLogger(UnitXConverterEngine.class); + private final UnitXCManager manager; + private final UnitXConverterStep roundingStep; + + public UnitXConverterEngine(UnitXCManager manager) { + this.manager = manager; + this.roundingStep = new UnitXCConverterStepAutoRounding(UnitXConverterStepContext.createStepValue(),UnitXConverterStepContext.createStepValue()); + } + + public UnitXConverterResult convertStepped(BigDecimal valueConvert2,UnitXCType fromType,UnitXCType toType, Map parameters) { + Validate.notNull(valueConvert2,"Can't convert null to number"); + Validate.notNull(fromType,"Can't convert from null unit type"); + Validate.notNull(toType,"Can't convert to null unit type"); + + + if (fromType.getAliasOfType() != null) { + fromType = Validate.notNull(manager.getUnitType(fromType.getAliasOfType()),"Coultn't resolve alias id: "+fromType.getAliasOfType()+" for: "+fromType.getId()); + } + if (toType.getAliasOfType() != null) { + toType = Validate.notNull(manager.getUnitType(toType.getAliasOfType()),"Coultn't resolve alias id: "+toType.getAliasOfType()+" for: "+toType.getId()); + } + + double valueConvert = valueConvert2.doubleValue(); + long startTime = System.currentTimeMillis(); + MathContext mathContext = MathContext.DECIMAL128; + UnitXConverterStepContextImpl ctx = new UnitXConverterStepContextImpl(mathContext,valueConvert); + + UnitXCGroup fromTypeGroup = fromType.getUnitGroup(); + UnitXCGroup toTypeGroup = toType.getUnitGroup(); + UnitXCGroupJump crossGroupJump = null; // List<> after multi level search + + if (!fromTypeGroup.getId().equals(toTypeGroup.getId())) { + for (UnitXCGroupJump groupJump:fromTypeGroup.getGroupJumps()) { // FIXME + if (toTypeGroup.getId().equals(groupJump.getUnitGroupId())) { + crossGroupJump = groupJump; + break; + } + } + if (crossGroupJump == null) { + throw new IllegalArgumentException("from and to groups are not equals: "+fromTypeGroup.getId()+" != "+toTypeGroup.getId()); + } + for (UnitXCGroupJumpParameter jumpPara:crossGroupJump.getJumpParameters()) { + if (!parameters.containsKey(jumpPara.getId())) { + throw new IllegalArgumentException("Missing required convert parameter: "+jumpPara.getId()); + } + UnitXConverterParameterValue convPara = parameters.get(jumpPara.getId()); + if (convPara.getValueType() == null) { + throw new IllegalArgumentException("Convert parameter has not type: "+jumpPara.getId()); + } + if (!jumpPara.getUnitGroupId().equals(convPara.getValueType().getUnitGroup().getId())) { + throw new IllegalArgumentException("Convert parameter is wrong group required: "+jumpPara.getUnitGroupId()+" got: "+convPara.getValueType().getUnitGroup().getId()); + } + boolean paraToBase = convPara.getValueType().getUnitGroup().getBaseTypeId().equals(convPara.getValueType().getId()); + double paraValue = convPara.getValue(); + if (!paraToBase) { + System.out.println("--- cont para");; + UnitXConverterResult res = convertStepped(BigDecimal.valueOf(paraValue), convPara.getValueType(), manager.getUnitType(convPara.getValueType().getUnitGroup().getBaseTypeId()), parameters); // FIXME rm parameters ? + paraValue = res.getResultValue(); + //ctx.resultSteps.addAll(res.getResultSteps()); + } + ctx.namedParameter.put(jumpPara.getId(), new UnitXConverterStepValueReferenceDouble(paraValue)); + } + } + + boolean fromTypeBase = fromTypeGroup.getBaseTypeId().equals(fromType.getId()); + if (!fromTypeBase) { + ctx.runSteps(fromType.getToBaseConverterSteps()); + } + + if (crossGroupJump != null) { + ctx.runSteps(crossGroupJump.getToGroupConverterSteps()); + } + + boolean toTypeBase = toTypeGroup.getBaseTypeId().equals(toType.getId()); + if (!toTypeBase) { + ctx.runSteps(toType.getFromBaseConverterSteps()); + } + + long convertTime = System.currentTimeMillis()-startTime; + DefaultUnitXConverterResult result = new DefaultUnitXConverterResult(); +// result.setStartValue(ctx.getStartValue()); + result.setStartTypeId(fromType.getId()); + result.setResultValue(ctx.getValue()); + result.setResultTypeId(toType.getId()); + result.setConvertTime(convertTime); + result.setResultSteps(ctx.resultSteps); + return result; + } + + class UnitXConverterStepContextImpl implements UnitXConverterStepContext { + + final MathContext mathContext; + List resultSteps = new ArrayList<>(); + Map namedVariables = new HashMap<>(); + Map namedParameter = new HashMap<>(); + + public UnitXConverterStepContextImpl(MathContext mathContext, double startValue) { + this.mathContext = Validate.notNull(mathContext); + setNamedVariable(VALUE, new UnitXConverterStepValueReferenceDouble(startValue)); + setNamedVariable(VALUE_START, new UnitXConverterStepValueReferenceDouble(startValue)); + } + + @Override + public void setNamedVariable(String name,UnitXConverterStepValueReadWrite variable) { + namedVariables.put(Validate.notBlank(name,"name is blank"),Validate.notNull(variable,"variable is null")); + } + + @Override + public UnitXConverterStepValueReadWrite getNamedVariable(String name) { + return Validate.notNull(namedVariables.get(Validate.notBlank(name,"name is blank")),"named variable not found: "+name); + } + + @Override + public UnitXConverterStepValueRead getNamedParameter(String name) { + return Validate.notNull(namedParameter.get(Validate.notBlank(name,"name is blank")),"named parameter not found: "+name); + } + + @Override + public void runSteps(List steps) { + for (UnitXConverterStep step:steps) { + runStep(step); + if (roundingStep != null) { + runStep(roundingStep); + } + } + } + + private void runStep(UnitXConverterStep step) { + + long startTime = System.currentTimeMillis(); + double valueOld = getValue(); + step.runStep(this); + long convertTime = System.currentTimeMillis()-startTime; + +// System.out.println("runStep: "+step+" res: "+step.getStepReasons()); + + DefaultUnitXConverterResultStep resultStep = new DefaultUnitXConverterResultStep(); + resultStep.setStartValue(valueOld); + resultStep.setResultValue(getValue()); + resultStep.setConvertTime(convertTime); + resultStep.setConvertStep(step); + resultSteps.add(resultStep); +// previousValue = valueOld; + } + + private Double getValue() { + return (Double)(getNamedVariable(VALUE).valueRead(this)); + } + + @Override + public MathContext getMathContext() { + return mathContext; + } + +// @Override +// public UnitXCManager getUnitManager() { +// return manager; +// } + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/converter/UnitXConverterParameterValue.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/converter/UnitXConverterParameterValue.java new file mode 100644 index 00000000..b7295ca0 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/converter/UnitXConverterParameterValue.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.converter; + +import org.apache.commons.lang3.Validate; + +import net.forwardfire.unitxc.model.UnitXCType; + +/** + * Holds the parameter value and type. + * + * @author Willem Cazander + * @version 1.0 Mar 18, 2016 + */ +public final class UnitXConverterParameterValue { + + private double value; + private UnitXCType valueType; + + public UnitXConverterParameterValue() { + } + + public UnitXConverterParameterValue(double value,UnitXCType valueType) { + setValue(value); + setValueType(Validate.notNull(valueType)); + } + + /** + * @return the value + */ + public double getValue() { + return value; + } + + /** + * @param value the value to set + */ + public void setValue(double value) { + this.value = value; + } + + /** + * @return the valueType + */ + public UnitXCType getValueType() { + return valueType; + } + + /** + * @param valueType the valueType to set + */ + public void setValueType(UnitXCType valueType) { + this.valueType = valueType; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/converter/package-info.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/converter/package-info.java new file mode 100644 index 00000000..e80f2f39 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/converter/package-info.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/** + * @author willemc + * + */ +package net.forwardfire.unitxc.converter; \ No newline at end of file diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/AbstractUnitXCGroup.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/AbstractUnitXCGroup.java new file mode 100644 index 00000000..3aa89964 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/AbstractUnitXCGroup.java @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.commons.lang3.Validate; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; + +/** + * The unit group. + * + * @author Willem Cazander + * @version 1.0 Oct 10, 2015 + */ +abstract public class AbstractUnitXCGroup implements UnitXCGroup { + + private final String id; + private final UnitXCResourceValue name; + private final UnitXCResourceValue description; + private String baseTypeId; + private final List quantities; + private final List derivedFrom; + private final List unitTypes; + private final List groupJumps; + + public AbstractUnitXCGroup(UnitXCResourceBundle bundle, String id) { + quantities = new ArrayList<>(); + derivedFrom = new ArrayList<>(); + unitTypes = new ArrayList<>(); + groupJumps = new ArrayList<>(); + this.name = new DefaultUnitXCResourceValue(bundle,"group."+id+".name"); + this.description = new DefaultUnitXCResourceValue(bundle,"group."+id+".description"); + this.id = id; + } + + public AbstractUnitXCGroup validate() { + Validate.notBlank(id,"The id is blank"); + Validate.notBlank(baseTypeId,"The baseTypeId is blank"); + return this; + } + + abstract long localUnitTypeSize(); + abstract Iterator localUnitTypeIds(); + abstract UnitXCType localUnitType(String id); + + @Override + final public long getUnitTypeSize() { + return getUnitTypes().size() + localUnitTypeSize(); + } + + @Override + final public Iterator getUnitTypeIds() { + Iterator l = localUnitTypeIds(); + List result = new ArrayList<>(); + getUnitTypes().forEach(t -> result.add(t.getId())); + Iterator g = result.iterator(); + return new Iterator() { + @Override + public boolean hasNext() { + if (l.hasNext()) { + return true; + } + return g.hasNext(); + } + @Override + public String next() { + if (l.hasNext()) { + return l.next(); + } + return g.next(); + } + }; + } + + @Override + final public UnitXCType getUnitType(String id) { + for (UnitXCType type:getUnitTypes()) { + if (type.getId().equals(id)) { + return type; + } + if (type.getName().equals(id)) { + return type; + } + } + return localUnitType(id); + } + + + + /** + * @return the id + */ + public String getId() { + return id; + } + + /** + * @return the name + */ + public UnitXCResourceValue getName() { + return name; + } + + /** + * @return the description + */ + public UnitXCResourceValue getDescription() { + return description; + } + + /** + * @return the baseTypeId + */ + public String getBaseTypeId() { + return baseTypeId; + } + + /** + * @param baseTypeId the baseTypeId to set + */ + public void setBaseTypeId(String baseTypeId) { + this.baseTypeId = baseTypeId; + } + + /** + * @return the quantities of the group. + */ + public List getQuantities() { + return quantities; + } + + public void addQuantity(UnitXCGroupQuantity quantity) { + this.quantities.add(quantity); + } + + /** + * @return the derivedFrom + */ + public List getDerivedFrom() { + return derivedFrom; + } + + /** + * @param derivedFrom the derivedFrom to add + */ + public void addDerivedFrom(String derivedFrom) { + this.derivedFrom.add(derivedFrom); + } + + /** + * @return the unit types. + */ + public List getUnitTypes() { + return unitTypes; + } + + public void addUnitType(DefaultUnitXCType type) { + Validate.notNull(type); + type.setUnitGroup(this); + type.validate(); + unitTypes.add(type); + } + + /** + * @return the groupJumps + */ + public List getGroupJumps() { + return groupJumps; + } + + /** + * @param groupJump the groupJump to add + */ + public void addGroupJump(UnitXCGroupJump groupJump) { + this.groupJumps.add(groupJump); + } + + @Override + final public String toString() { + return ReflectionToStringBuilder.toString(this); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCGroupJump.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCGroupJump.java new file mode 100644 index 00000000..6761af86 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCGroupJump.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.Validate; + +import net.forwardfire.unitxc.model.step.UnitXConverterStep; + +/** + * The unit group jump. + * + * @author Willem Cazander + * @version 1.0 Apr 1, 2016 + */ +public class DefaultUnitXCGroupJump implements UnitXCGroupJump { + + private String id; + private String unitGroupId; + private final List toGroupConverterSteps; + private final List jumpParameters; + + public DefaultUnitXCGroupJump() { + toGroupConverterSteps = new ArrayList<>(); + jumpParameters = new ArrayList<>(); + } + + public UnitXCGroupJump validate() { + Validate.notBlank(id,"The id is blank"); + Validate.notBlank(unitGroupId,"The unitGroupId is blank of: "+id); + return this; + } + + /** + * @return the id + */ + public String getId() { + return id; + } + /** + * @param id the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return the toGroupId + */ + public String getUnitGroupId() { + return unitGroupId; + } + + /** + * @param unitGroupId the unitGroupId to set + */ + public void setUnitGroupId(String unitGroupId) { + this.unitGroupId = unitGroupId; + } + + /** + * @return the toGroupConverterSteps + */ + public List getToGroupConverterSteps() { + return toGroupConverterSteps; + } + + /** + * @param toGroupConverterSteps the toGroupConverterSteps to set + */ + public void setToBaseConverterSteps(List toGroupConverterSteps) { + this.toGroupConverterSteps.clear(); + this.toGroupConverterSteps.addAll(toGroupConverterSteps); + } + + /** + * @return the jumpParameters + */ + public List getJumpParameters() { + return jumpParameters; + } + + /** + * @param jumpParameters the jumpParameters to set + */ + public void setJumpParameters(List jumpParameters) { + this.jumpParameters.clear(); + this.jumpParameters.addAll(jumpParameters); + } + + public void addJumpParameter(UnitXCGroupJumpParameter jumpParameter) { + this.jumpParameters.add(Validate.notNull(jumpParameter)); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCGroupJumpParameter.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCGroupJumpParameter.java new file mode 100644 index 00000000..b8509082 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCGroupJumpParameter.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import org.apache.commons.lang3.Validate; + +/** + * The unit group jump. + * + * @author Willem Cazander + * @version 1.0 Apr 1, 2016 + */ +public class DefaultUnitXCGroupJumpParameter implements UnitXCGroupJumpParameter { + + private String id; + private String unitGroupId; + + public DefaultUnitXCGroupJumpParameter() { + } + + public DefaultUnitXCGroupJumpParameter(String id,String unitGroupId) { + setId(id); + setUnitGroupId(unitGroupId); + } + + public DefaultUnitXCGroupJumpParameter validate() { + Validate.notBlank(id,"The id is blank"); + Validate.notBlank(unitGroupId,"The unitGroup is blank of: "+id); + return this; + } + + /** + * @return the id + */ + public String getId() { + return id; + } + /** + * @param id the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return the unitGroupId + */ + public String getUnitGroupId() { + return unitGroupId; + } + + /** + * @param unitGroupId the unitGroupId to set + */ + public void setUnitGroupId(String unitGroupId) { + this.unitGroupId = unitGroupId; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCGroupQuantity.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCGroupQuantity.java new file mode 100644 index 00000000..24fb0151 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCGroupQuantity.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +/** + * The unit group quantity. + * + * @author Willem Cazander + * @version 1.0 Oct 31, 2016 + */ +public class DefaultUnitXCGroupQuantity implements UnitXCGroupQuantity { + + private final String id; + private final UnitXCResourceValue name; + private final UnitXCResourceValue wikiLink; + + public DefaultUnitXCGroupQuantity(UnitXCResourceBundle bundle, String parentKey, String id) { + this.name = new DefaultUnitXCResourceValue(bundle,parentKey+"."+id+".name"); + this.wikiLink = new DefaultUnitXCResourceValue(bundle,parentKey+"."+id+".wikiLink"); + this.id = id; + } + + @Override + public String getId() { + return id; + } + + @Override + public UnitXCResourceValue getName() { + return name; + } + + @Override + public UnitXCResourceValue getWikiLink() { + return wikiLink; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCResourceValue.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCResourceValue.java new file mode 100644 index 00000000..5f93b10a --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCResourceValue.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.List; + +/** + * The resource value wrapper holder + * + * @author Willem Cazander + * @version 1.0 Oct 31, 2016 + */ +public class DefaultUnitXCResourceValue implements UnitXCResourceValue { + + private final UnitXCResourceBundle bundle; + private final String bundleKey; + + public DefaultUnitXCResourceValue(UnitXCResourceBundle bundle, String bundleKey) { + super(); + this.bundle = bundle; + this.bundleKey = bundleKey; + } + + @Override + public String getBundleKey() { + return bundleKey; + } + + @Override + public List getLanguages() { + return bundle.getValueLanguages(getBundleKey()); + } + + @Override + public String getValue(String language) { + return bundle.getValue(language, getBundleKey()); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCType.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCType.java new file mode 100644 index 00000000..75119aa1 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCType.java @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.Validate; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; + +import net.forwardfire.unitxc.model.step.UnitXConverterStep; + +/** + * The unit type. + * + * @author Willem Cazander + * @version 1.0 Oct 10, 2015 + */ +public class DefaultUnitXCType implements UnitXCType { + + private String id; + private String name; + private String namePlural; + private String aliasOfType; + private UnitXCGroup unitGroup; + private String weblink; + private final List toBaseConverterSteps; + private final List fromBaseConverterSteps; + private final List typeFlags; + + public DefaultUnitXCType() { + typeFlags = new ArrayList<>(); + toBaseConverterSteps = new ArrayList<>(); + fromBaseConverterSteps = new ArrayList<>(); + } + + public UnitXCType validate() { + Validate.notBlank(id,"The id is blank"); + Validate.notBlank(name,"The name is blank of: "+id); + //Validate.notBlank(namePlural,"The namePlural is blank of: "+id); + Validate.notNull(unitGroup,"The unitGroup is null of: "+id); + return this; + } + + /** + * @return the id + */ + @Override + public String getId() { + return id; + } + /** + * @param id the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return the name + */ + @Override + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the namePlural + */ + @Override + public String getNamePlural() { + return namePlural; + } + + /** + * @param namePlural the namePlural to set + */ + public void setNamePlural(String namePlural) { + this.namePlural = namePlural; + } + + /** + * @return the aliasOfType + */ + @Override + public String getAliasOfType() { + return aliasOfType; + } + + /** + * @param aliasOfType the aliasOfType to set + */ + public void setAliasOfType(String aliasOfType) { + this.aliasOfType = aliasOfType; + } + + /** + * @return the unitGroup + */ + @Override + public UnitXCGroup getUnitGroup() { + return unitGroup; + } + + /** + * @param unitGroup the unitGroup to set + */ + public void setUnitGroup(UnitXCGroup unitGroup) { + this.unitGroup = unitGroup; + } + + /** + * @return the toBaseConverterSteps + */ + @Override + public List getToBaseConverterSteps() { + return toBaseConverterSteps; + } + + /** + * @param toBaseConverterSteps the toBaseConverterSteps to set + */ + public void setToBaseConverterSteps(List toBaseConverterSteps) { + this.toBaseConverterSteps.clear(); + this.toBaseConverterSteps.addAll(toBaseConverterSteps); + } + + /** + * @return the fromBaseConverterSteps + */ + @Override + public List getFromBaseConverterSteps() { + return fromBaseConverterSteps; + } + + /** + * @param fromBaseConverterSteps the fromBaseConverterSteps to set + */ + public void setFromBaseConverterSteps(List fromBaseConverterSteps) { + this.fromBaseConverterSteps.clear(); + this.fromBaseConverterSteps.addAll(fromBaseConverterSteps); + } + + /** + * @return the typeFlags + */ + @Override + public List getTypeFlags() { + return typeFlags; + } + + /** + * @param typeFlags the typeFlags to set + */ + public void setTypeFlags(List typeFlags) { + this.typeFlags.clear(); + this.typeFlags.addAll(typeFlags); + } + + /** + * @return the weblink + */ + @Override + public String getWebLink() { + return weblink; + } + + /** + * @param webLink the webLink to set + */ + public void setWebLink(String weblink) { + this.weblink = weblink; + } + + @Override + public String toString() { + return ReflectionToStringBuilder.toString(this); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXConverterResult.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXConverterResult.java new file mode 100644 index 00000000..c3b0bf9e --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXConverterResult.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.List; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; + +/** + * Holds the convert result and meta steps how we got there. + * + * @author Willem Cazander + * @version 1.0 Oct 17, 2015 + */ +public class DefaultUnitXConverterResult implements UnitXConverterResult { + + private Double startValue; + private List resultSteps; + private Double resultValue; + private Long convertTime; + private String startTypeId; + private String resultTypeId; + + /** + * @return the startValue + */ + public Double getStartValue() { + return startValue; + } + + /** + * @param startValue the startValue to set + */ + public void setStartValue(Double startValue) { + this.startValue = startValue; + } + + /** + * @return the resultSteps + */ + public List getResultSteps() { + return resultSteps; + } + + /** + * @param resultSteps the resultSteps to set + */ + public void setResultSteps(List resultSteps) { + this.resultSteps = resultSteps; + } + + /** + * @return the resultValue + */ + public Double getResultValue() { + return resultValue; + } + + /** + * @param resultValue the resultValue to set + */ + public void setResultValue(Double resultValue) { + this.resultValue = resultValue; + } + + /** + * @return the convertTime + */ + public Long getConvertTime() { + return convertTime; + } + + /** + * @param convertTime the convertTime to set + */ + public void setConvertTime(Long convertTime) { + this.convertTime = convertTime; + } + + /** + * @return the startTypeId + */ + public String getStartTypeId() { + return startTypeId; + } + + /** + * @param startTypeId the startTypeId to set + */ + public void setStartTypeId(String startTypeId) { + this.startTypeId = startTypeId; + } + + /** + * @return the resultTypeId + */ + public String getResultTypeId() { + return resultTypeId; + } + + /** + * @param resultTypeId the resultTypeId to set + */ + public void setResultTypeId(String resultTypeId) { + this.resultTypeId = resultTypeId; + } + + @Override + public String toString() { + return ReflectionToStringBuilder.toString(this); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXConverterResultStep.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXConverterResultStep.java new file mode 100644 index 00000000..e917f87a --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXConverterResultStep.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; + +import net.forwardfire.unitxc.model.step.UnitXConverterStep; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 17, 2015 + */ +public class DefaultUnitXConverterResultStep implements UnitXConverterResultStep { + + private Double startValue; + private Double resultValue; + private Long convertTime; + private UnitXConverterStep convertStep; + + /** + * @return the startValue + */ + public Double getStartValue() { + return startValue; + } + + /** + * @param startValue the startValue to set + */ + public void setStartValue(Double startValue) { + this.startValue = startValue; + } + + /** + * @return the resultValue + */ + public Double getResultValue() { + return resultValue; + } + + /** + * @param resultValue the resultValue to set + */ + public void setResultValue(Double resultValue) { + this.resultValue = resultValue; + } + + /** + * @return the convertTime + */ + public Long getConvertTime() { + return convertTime; + } + + /** + * @param convertTime the convertTime to set + */ + public void setConvertTime(Long convertTime) { + this.convertTime = convertTime; + } + + /** + * @return the convertStep + */ + public UnitXConverterStep getConvertStep() { + return convertStep; + } + + /** + * @param convertStep the convertStep to set + */ + public void setConvertStep(UnitXConverterStep convertStep) { + this.convertStep = convertStep; + } + + @Override + public String toString() { + return ReflectionToStringBuilder.toString(this); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCConfig.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCConfig.java new file mode 100644 index 00000000..7950f6d7 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCConfig.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import org.apache.commons.lang3.Validate; + +/** + * The unit config. + * + * @author Willem Cazander + * @version 1.0 Oct 17, 2015 + */ +public class UnitXCConfig { + + private UnitXCRounding rounding; + private final List unitGroups; + private final List languages; + + public UnitXCConfig() { + unitGroups = new ArrayList<>(); + languages = new ArrayList<>(); + } + + /** + * @return the rounding + */ + public UnitXCRounding getRounding() { + return rounding; + } + + /** + * @param rounding the rounding to set + */ + public void setRounding(UnitXCRounding rounding) { + this.rounding = rounding; + } + + /** + * @return the unit groups. + */ + public List getUnitGroups() { + return unitGroups; + } + + public void addUnitGroup(AbstractUnitXCGroup group) { + Validate.notNull(group); + group.validate(); + unitGroups.add(group); + } + + public List getLanguages() { + return languages; + } + + public void addLanguage(Locale language) { + languages.add(Validate.notNull(language)); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroup.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroup.java new file mode 100644 index 00000000..57334c18 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroup.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.Iterator; +import java.util.List; + +/** + * The unit group. + * + * @author Willem Cazander + * @version 1.0 Oct 10, 2015 + */ +public interface UnitXCGroup { + + /** + * @return the id + */ + String getId(); + + /** + * @return the name + */ + UnitXCResourceValue getName(); + + /** + * @return the description + */ + UnitXCResourceValue getDescription(); + + /** + * @return the baseTypeId + */ + String getBaseTypeId(); + + /** + * @return the quantities of the group. + */ + List getQuantities(); + + /** + * @return the derivedFrom + */ + List getDerivedFrom(); + + /** + * @return the groupJumps + */ + List getGroupJumps(); + + /** + * @return the totalUnitTypes + */ + long getUnitTypeSize(); + + Iterator getUnitTypeIds(); + + UnitXCType getUnitType(String id); +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupBase.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupBase.java new file mode 100644 index 00000000..c8f79ffb --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupBase.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.Collections; +import java.util.Iterator; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 28, 2016 + */ +public class UnitXCGroupBase extends AbstractUnitXCGroup { + + public UnitXCGroupBase(UnitXCResourceBundle bundle, String id) { + super(bundle, id); + } + + @Override + public long localUnitTypeSize() { + return 0L; + } + + @Override + public Iterator localUnitTypeIds() { + return Collections.emptyIterator(); + } + + @Override + public UnitXCType localUnitType(String id) { + return null; + } + +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupCompoundExponent.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupCompoundExponent.java new file mode 100644 index 00000000..bb83cb73 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupCompoundExponent.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.Iterator; + +import org.apache.commons.lang3.Validate; + +import net.forwardfire.unitxc.config.builder.UnitXCTypeBuilder; +import net.forwardfire.unitxc.model.step.UnitXCConverterStepReference; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 28, 2016 + */ +public class UnitXCGroupCompoundExponent extends AbstractUnitXCGroup { + + private final UnitXCGroup parentGroup; + private final int exponent; + private String unitIdPostfix; + private String unitNamePrefix; + + public UnitXCGroupCompoundExponent(UnitXCResourceBundle bundle, String id,UnitXCGroup parentGroup,int exponent) { + super(bundle, id); + this.parentGroup = Validate.notNull(parentGroup); + this.exponent = exponent; + Validate.isTrue(exponent > 1); + } + + @Override + public long localUnitTypeSize() { + return getParentGroup().getUnitTypeSize(); + } + + @Override + public Iterator localUnitTypeIds() { + Iterator g = getParentGroup().getUnitTypeIds(); + return new Iterator() { + @Override + public boolean hasNext() { + return g.hasNext(); + } + @Override + public String next() { + return g.next()+unitIdPostfix; + } + }; + } + + @Override + public UnitXCType localUnitType(String id) { + if (!id.endsWith(unitIdPostfix)) { + return null; + } + String idRaw = id.substring(0, id.length()-unitIdPostfix.length()); + UnitXCGroup group = getParentGroup(); + UnitXCType unitType = group.getUnitType(idRaw); + if (unitType == null) { + return null; + } + + DefaultUnitXCType result = new DefaultUnitXCType(); + UnitXCTypeBuilder typeBuilder = new UnitXCTypeBuilder<>(this,result,(p,v) -> {}); + typeBuilder + .setId(unitType.getId()+unitIdPostfix) + .setName(unitNamePrefix+unitType.getName()) + .addTypeFlags(unitType.getTypeFlags()); + + for (int i=0;i localUnitTypeIds() { + Iterator groupIt = getParentGroup().getUnitTypeIds(); + return new Iterator() { + + String groupId2; + Iterator perGroupIt; + + @Override + public boolean hasNext() { + if (perGroupIt!=null && perGroupIt.hasNext()) { + return true; + } + if (groupIt.hasNext()) { + groupId2 = groupIt.next(); + perGroupIt = getParentPerGroup().getUnitTypeIds(); + return true; + } + return false; + } + + @Override + public String next() { + return groupId2+PER_ID+perGroupIt.next(); + } + }; + } + + @Override + public UnitXCType localUnitType(String id) { +// if (!id.contains(PER_ID)) { +// return null; +// } + + String[] units = id.split(PER_ID); + if (units.length < 2) { + return null; + } +// System.out.println("checking pair: "+id); + for (int i=1;i typeBuilder = new UnitXCTypeBuilder<>(this,result,(p,v) -> {}); + typeBuilder + .setId(id) + .setName(unitType.getName()+PER_NAME+perUnitType.getName()) + .addTypeFlags(unitType.getTypeFlags()) + .addTypeFlags(perUnitType.getTypeFlags()); + + typeBuilder.addToBaseConverterStep(new UnitXCConverterStepReference(unitType,true)); + typeBuilder.addToBaseConverterStep(new UnitXCConverterStepReference(perUnitType,false)); + typeBuilder.addFromBaseConverterStep(new UnitXCConverterStepReference(perUnitType,true)); + typeBuilder.addFromBaseConverterStep(new UnitXCConverterStepReference(unitType,false)); + typeBuilder.build(); + result.setUnitGroup(this); + return result; + } + + /** + * @return the parentGroup + */ + public UnitXCGroup getParentGroup() { + return parentGroup; + } + + /** + * @return the parentPerGroup + */ + public UnitXCGroup getParentPerGroup() { + return parentPerGroup; + } +} + diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupJump.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupJump.java new file mode 100644 index 00000000..00f10774 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupJump.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.List; + +import net.forwardfire.unitxc.model.step.UnitXConverterStep; + +/** + * The unit group jump. + * + * @author Willem Cazander + * @version 1.0 Apr 1, 2016 + */ +public interface UnitXCGroupJump { + + UnitXCGroupJump validate(); + + /** + * @return the id + */ + String getId(); + + /** + * @return the toGroupId + */ + String getUnitGroupId(); + + /** + * @return the toGroupConverterSteps + */ + List getToGroupConverterSteps(); + + /** + * @return the jumpParameters + */ + List getJumpParameters(); +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupJumpParameter.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupJumpParameter.java new file mode 100644 index 00000000..8e9bdb02 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupJumpParameter.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +/** + * The unit group jump. + * + * @author Willem Cazander + * @version 1.0 Apr 1, 2016 + */ +public interface UnitXCGroupJumpParameter { + + UnitXCGroupJumpParameter validate(); + + /** + * @return the id + */ + String getId(); + + /** + * @return the unitGroupId + */ + String getUnitGroupId(); +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupQuantity.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupQuantity.java new file mode 100644 index 00000000..79b940c9 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupQuantity.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +/** + * The unit group quantity. + * + * @author Willem Cazander + * @version 1.0 Oct 31, 2016 + */ +public interface UnitXCGroupQuantity { + + /** + * @return the id + */ + String getId(); + + /** + * @return the name + */ + UnitXCResourceValue getName(); + + /** + * @return the wikilink + */ + UnitXCResourceValue getWikiLink(); +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupSource.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupSource.java new file mode 100644 index 00000000..7e9f42ae --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupSource.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.Iterator; +import java.util.List; + +/** + * The unit group source. + * + * @author Willem Cazander + * @version 1.0 Dec 4, 2016 + */ +public interface UnitXCGroupSource { + + /** + * @return the derivedFrom + */ + List getDerivedFrom(); + + /** + * @return the totalUnitTypes + */ + long getUnitTypeSize(); + + Iterator getUnitTypeIds(); + + UnitXCType getUnitType(String id); +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCModule.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCModule.java new file mode 100644 index 00000000..fac2719e --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCModule.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.List; + +/** + * The resource value wrapper + * + * @author Willem Cazander + * @version 1.0 Oct 31, 2016 + */ +public @interface UnitXCModule { + + String groupId(); + + String[] dependencies(); + +// public @interface UnitXCModuleDependency { +// String groupId(); +// } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCResourceBundle.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCResourceBundle.java new file mode 100644 index 00000000..1c06aed2 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCResourceBundle.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.Validate; + +/** + * The resource value wrapper + * + * @author Willem Cazander + * @version 1.0 Oct 31, 2016 + */ +public class UnitXCResourceBundle { + + private Map> data = new HashMap<>(); + + // FIXME: not public or interface or x + public void addData(String language,String key,String value) { + Map ld = data.get(language); + if (ld == null) { + ld = new HashMap<>(); + data.put(language, ld); + } + ld.put(key, value); + } + + public List getLanguages() { + return new ArrayList<>(data.keySet()); + } + + public List getValueLanguages(String key) { + List result = new ArrayList<>(); + data.forEach((k,v) -> { + if (v.containsKey(key)) { + result.add(k); + } + }); + return result; + } + + public String getValue(String lang,String key) { + if (lang.isEmpty()) { + lang = "und"; // undefined + } + return Validate.notNull(Validate.notNull(data.get(lang),"Could not find langauge: "+lang).get(key),"Could not find key: "+key); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCResourceValue.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCResourceValue.java new file mode 100644 index 00000000..17b999d4 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCResourceValue.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.List; + +/** + * The resource value wrapper + * + * @author Willem Cazander + * @version 1.0 Oct 31, 2016 + */ +public interface UnitXCResourceValue { + + /** + * @return the bundle key. + */ + String getBundleKey(); + + List getLanguages(); + + String getValue(String language); +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCRounding.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCRounding.java new file mode 100644 index 00000000..50e1400b --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCRounding.java @@ -0,0 +1,14 @@ +package net.forwardfire.unitxc.model; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Mar 23, 2016 + */ +public enum UnitXCRounding { + + OFF, + PRE_STEP; + /* PER_CONVERT */ +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCType.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCType.java new file mode 100644 index 00000000..fabcbb82 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXCType.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.List; + +import net.forwardfire.unitxc.model.step.UnitXConverterStep; + +/** + * The unit type. + * + * @author Willem Cazander + * @version 1.0 Oct 10, 2015 + */ +public interface UnitXCType { + + /** + * @return the id + */ + String getId(); + + + /** + * @return the name + */ + String getName(); + + /** + * The name in plugal form. + * @return the namePlural. + */ + String getNamePlural(); + + /** + * @return the aliasOfType + */ + String getAliasOfType(); + + /** + * @return the unitGroup + */ + UnitXCGroup getUnitGroup(); + + /** + * @return the toBaseConverterSteps + */ + List getToBaseConverterSteps(); + + /** + * @return the fromBaseConverterSteps + */ + List getFromBaseConverterSteps(); + + /** + * @return the typeFlags + */ + List getTypeFlags(); + + /** + * @return the weblink + */ + String getWebLink(); +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResult.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResult.java new file mode 100644 index 00000000..da3a20c5 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResult.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import java.util.List; + +/** + * Holds the convert result and meta steps how we got there. + * + * @author Willem Cazander + * @version 1.0 Oct 17, 2015 + */ +public interface UnitXConverterResult { + + /** + * @return the startValue + */ + Double getStartValue(); + + /** + * @return the resultSteps + */ + List getResultSteps(); + + /** + * @return the resultValue + */ + Double getResultValue(); + + /** + * @return the convertTime + */ + Long getConvertTime(); + + /** + * @return the startTypeId + */ + String getStartTypeId(); + + /** + * @return the resultTypeId + */ + String getResultTypeId(); +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResultStep.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResultStep.java new file mode 100644 index 00000000..d2c6fe16 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResultStep.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model; + +import net.forwardfire.unitxc.model.step.UnitXConverterStep; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 17, 2015 + */ +public interface UnitXConverterResultStep { + + /** + * @return the startValue + */ + Double getStartValue(); + + /** + * @return the resultValue + */ + Double getResultValue(); + + /** + * @return the convertTime + */ + Long getConvertTime(); + + + /** + * @return the convertStep + */ + UnitXConverterStep getConvertStep(); +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/package-info.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/package-info.java new file mode 100644 index 00000000..08dc542c --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/package-info.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/** + * @author willemc + * + */ +package net.forwardfire.unitxc.model; \ No newline at end of file diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/AbstractUnitXConverterStep.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/AbstractUnitXConverterStep.java new file mode 100644 index 00000000..7e2bc173 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/AbstractUnitXConverterStep.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model.step; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.Validate; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 17, 2015 + */ +public abstract class AbstractUnitXConverterStep implements UnitXConverterStep { + + private final List stepReasons; + + protected AbstractUnitXConverterStep() { + this.stepReasons = new ArrayList<>(); + } + + public AbstractUnitXConverterStep buildReason(String reason) { + addStepReason(reason); + return this; + } + + public final List getStepReasons() { + return stepReasons; + } + + public final void setStepReasons(List stepReasons) { + this.stepReasons.clear(); + this.stepReasons.addAll(stepReasons); + } + + public final void addStepReason(String stepReason) { + stepReasons.add(Validate.notBlank(stepReason)); + } + + @Override + public final String toString() { + return ReflectionToStringBuilder.toString(this); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/RuleStepCode.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/RuleStepCode.java new file mode 100644 index 00000000..faafaccc --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/RuleStepCode.java @@ -0,0 +1,80 @@ +package net.forwardfire.unitxc.model.step; + +public class RuleStepCode { + + private String id; + private String type; + private String style; + private String code; + private String matcher; + + /** + * @return the id + */ + public String getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return the type + */ + public String getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(String type) { + this.type = type; + } + + /** + * @return the style + */ + public String getStyle() { + return style; + } + + /** + * @param style the style to set + */ + public void setStyle(String style) { + this.style = style; + } + + /** + * @return the code + */ + public String getCode() { + return code; + } + + /** + * @param code the code to set + */ + public void setCode(String code) { + this.code = code; + } + + /** + * @return the matcher + */ + public String getMatcher() { + return matcher; + } + + /** + * @param matcher the matcher to set + */ + public void setMatcher(String matcher) { + this.matcher = matcher; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/RuleStepCodePrinter.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/RuleStepCodePrinter.java new file mode 100644 index 00000000..02451c5e --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/RuleStepCodePrinter.java @@ -0,0 +1,105 @@ +package net.forwardfire.unitxc.model.step; + +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; + +public class RuleStepCodePrinter { + + private final StringBuilder result = new StringBuilder(); + private final RuleStepCodeStyle codeStyle; + private int indentLevel = 0; + + public RuleStepCodePrinter(RuleStepCodeStyle codeStyle) { + this.codeStyle = Validate.notNull(codeStyle); + } + + public static String print(RuleStepCodeStyle codeStyle, List steps, String id) { + RuleStepCodePrinter printer = new RuleStepCodePrinter(codeStyle); + printer.line(); // make copy/paste easy + if (printer.isEnglish()) { + printer.line("Description of: ",id); + printer.line(); + } else { + printer.line("code['",id,"'] = function(ctx) {"); + printer.pushIndent(); + } + printer.printSteps(steps); + if (printer.isJavascript()) { + printer.popIndent(); + printer.line("}"); + } + return printer.getResult(); + } + + public void printSteps(List steps) { + steps.forEach(s -> s.toRuleCode(this)); + } + + public String getResult() { + return result.toString(); + } + + public RuleStepCodeStyle getCodeStyle() { + return codeStyle; + } + + public boolean isEnglish() { + return RuleStepCodeStyle.ENGLISH.equals(getCodeStyle()); + } + + public boolean isJavascript() { + return RuleStepCodeStyle.JAVASCRIPT.equals(getCodeStyle()); + } +/* + public boolean isXslt() { + return RuleStepCodeType.XSLT.equals(getCodeStyle()); + } +*/ + public void pushIndent() { + indentLevel++; + } + + public void popIndent() { + if (indentLevel > 0) { + indentLevel--; + } + } + + private void appendIndent() { + for (int i = 0;i < indentLevel*4; i++) { + appendSpace(); + } + } + + public void line(String...text) { + lineStart(text); + lineEnd(); + } + + public void lineStart(String...text) { + appendIndent(); + append(text); + } + + public void lineEnd(String...text) { + append(text); + result.append(StringUtils.LF); + } + + public void append(String...texts) { + Arrays.asList(texts).forEach(text -> result.append(text)); + } + + public void appendJS(String...texts) { + if (isJavascript()) { + append(texts); + } + } + + public void appendSpace() { + result.append(StringUtils.SPACE); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/RuleStepCodeStyle.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/RuleStepCodeStyle.java new file mode 100644 index 00000000..4f735590 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/RuleStepCodeStyle.java @@ -0,0 +1,7 @@ +package net.forwardfire.unitxc.model.step; + +public enum RuleStepCodeStyle { + ENGLISH, + JAVASCRIPT + ; +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepAutoRounding.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepAutoRounding.java new file mode 100644 index 00000000..87e82065 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepAutoRounding.java @@ -0,0 +1,104 @@ +package net.forwardfire.unitxc.model.step; + +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueNamedVariable; +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead; +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReadWrite; + +public class UnitXCConverterStepAutoRounding extends AbstractUnitXConverterStep { + + private UnitXConverterStepValueRead operand; + private UnitXConverterStepValueReadWrite result; + + public UnitXCConverterStepAutoRounding() { + } + + public UnitXCConverterStepAutoRounding(UnitXConverterStepValueRead operand,UnitXConverterStepValueReadWrite result) { + setOperand(operand); + setResult(result); + } + + @Override + public void toRuleCode(RuleStepCodePrinter printer) { + if (printer.isEnglish()) { + printer.lineStart("Rounding "); + getOperand().toRuleCodeRead(printer); + printer.append(" to "); + getResult().toRuleCodeRead(printer); + printer.lineEnd("."); + return; + } + printer.lineStart(); + getResult().toRuleCodeWrite(printer); + printer.append(" = "); + getOperand().toRuleCodeRead(printer); + printer.lineEnd(); + } + + private double round(double value,double prevValue) { + String valueStr = Double.toString(value); + String valueOrgStr = Double.toString(prevValue); + int valueDotIndex = valueStr.indexOf("."); + int valueOrgDotIndex = valueOrgStr.indexOf("."); + int valueDotSize = valueStr.length() - valueDotIndex; + int valueOrgDotSize = valueOrgStr.length() - valueOrgDotIndex; + + if (valueDotSize<10) { + return value; + } + if (valueDotSize<=valueOrgDotSize) { + return value; + } + int valueEIndex = valueStr.indexOf("E"); + String valueShortStr = null; + if (valueEIndex>0) { + int sub = valueOrgStr.length(); + if (sub > valueEIndex) { + sub = valueEIndex; + } + valueShortStr = valueStr.substring(0, sub)+ valueStr.substring(valueEIndex); + } else { + int endIndex = valueOrgStr.length(); + if (endIndex > valueStr.length()) { + endIndex = valueStr.length(); + } + valueShortStr = valueStr.substring(0, endIndex); + } + Double result = Double.valueOf(valueShortStr); + return result.doubleValue(); + } + + @Override + public void runStep(UnitXConverterStepContext ctx) { + // FIXME: rm obj and casting + UnitXConverterStepValueReadWrite startValue = new UnitXConverterStepValueNamedVariable(Double.class,UnitXConverterStepContext.VALUE_START); + getResult().valueWrite(ctx, round((Double)getOperand().valueRead(ctx),(Double)startValue.valueRead(ctx))); + } + + /** + * @return the operand + */ + public UnitXConverterStepValueRead getOperand() { + return operand; + } + + /** + * @param operand the operand to set + */ + public void setOperand(UnitXConverterStepValueRead operand) { + this.operand = operand; + } + + /** + * @return the result + */ + public UnitXConverterStepValueReadWrite getResult() { + return result; + } + + /** + * @param result the result to set + */ + public void setResult(UnitXConverterStepValueReadWrite result) { + this.result = result; + } +} \ No newline at end of file diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepCondition.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepCondition.java new file mode 100644 index 00000000..bd4eec92 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepCondition.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model.step; + +import java.util.ArrayList; +import java.util.List; + +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 17, 2015 + */ +public class UnitXCConverterStepCondition extends AbstractUnitXConverterStep { + + private UnitXCConverterStepConditionEquality equality; + private UnitXConverterStepValueRead operandA; + private UnitXConverterStepValueRead operandB; + private final List conditionalSteps; + + public UnitXCConverterStepCondition() { + this.conditionalSteps = new ArrayList<>(); + } + + @Override + public void runStep(UnitXConverterStepContext ctx) { + if (equality.execute(operandA.valueRead(ctx),operandB.valueRead(ctx))) { + ctx.runSteps(conditionalSteps); + } + } + + @Override + public void toRuleCode(RuleStepCodePrinter printer) { + if (printer.isEnglish()) { + printer.lineStart("If "); + toPseudoCodeExpression(printer); + printer.lineEnd(" then;"); + printer.pushIndent(); + printer.printSteps(getConditionalSteps()); + printer.popIndent(); +// if (!stepsFalse.isEmpty()) { +// printer.line("Else do;"); +// printer.pushIndent(); +// printer.printSteps(getStepsFalse()); +// printer.popIndent(); +// } + printer.line(); // for readablity + return; + } + printer.lineStart("if"); + toPseudoCodeExpression(printer); + printer.lineEnd("{"); + printer.pushIndent(); + printer.printSteps(getConditionalSteps()); + printer.popIndent(); +// if (stepsFalse.isEmpty()) { +// printer.line("}"); +// } else { +// printer.line("} else {"); +// printer.pushIndent(); +// printer.printSteps(getStepsFalse()); +// printer.popIndent(); +// printer.line("}"); +// } + } + + public void toPseudoCodeExpression(RuleStepCodePrinter printer/*, List expressions*/) { + printer.appendJS(" ( "); + getEquality().toRuleCode(printer, operandA, operandB); + printer.appendJS(" ) "); + +// Iterator i = expressions.iterator(); +// if (!i.hasNext()) { +// return; +// } +// printer.appendJS(" ( "); +// while (i.hasNext()) { +// RuleStepConditionExpression ex = i.next(); +// ex.getEquality().toRuleCode(printer, ex.getOperandA(), ex.getOperandB()); +// // TODO: this not yet looks correctly,,.somewhere here? +// if (i.hasNext()) { +// if (printer.isEnglish()) { +// printer.append(" and "); +// } else { +// printer.append(" && "); +// } +// } +// if (!ex.getExpressions().isEmpty()) { +// if (printer.isEnglish()) { +// printer.append(" or "); +// } else { +// printer.append(" || "); +// } +// toPseudoCodeExpression(printer,ex.getExpressions()); +// } +// } +// printer.appendJS(" ) "); + } + + /** + * @return the equality + */ + public UnitXCConverterStepConditionEquality getEquality() { + return equality; + } + + /** + * @param equality the equality to set + */ + public void setEquality(UnitXCConverterStepConditionEquality equality) { + this.equality = equality; + } + + /** + * @return the operandA + */ + public UnitXConverterStepValueRead getOperandA() { + return operandA; + } + + /** + * @param operandA the operandA to set + */ + public void setOperandA(UnitXConverterStepValueRead operandA) { + this.operandA = operandA; + } + + /** + * @return the operandB + */ + public UnitXConverterStepValueRead getOperandB() { + return operandB; + } + + /** + * @param operandB the operandB to set + */ + public void setOperandB(UnitXConverterStepValueRead operandB) { + this.operandB = operandB; + } + + /** + * @return the conditionalSteps + */ + public List getConditionalSteps() { + return conditionalSteps; + } + + /** + * @param conditionalSteps the conditionalSteps to set + */ + public void setConditionalSteps(List conditionalSteps) { + this.conditionalSteps.clear(); + this.conditionalSteps.addAll(conditionalSteps); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepConditionEquality.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepConditionEquality.java new file mode 100644 index 00000000..0ad0b791 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepConditionEquality.java @@ -0,0 +1,63 @@ +package net.forwardfire.unitxc.model.step; + +import java.util.function.BiFunction; + +import org.apache.commons.lang3.StringUtils; + +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead; + +public enum UnitXCConverterStepConditionEquality { + + EQUALS ("===",(l,r) -> l.compareTo(r) == 0, (l,r) -> l.compareTo(r) == 0, (l,r) -> l.compareTo(r) == 0), + NOT_EQUALS ("!==",(l,r) -> l.compareTo(r) != 0, (l,r) -> l.compareTo(r) != 0, (l,r) -> l.compareTo(r) != 0), + GREATER_THEN (">", (l,r) -> l.compareTo(r) > 0, (l,r) -> l.compareTo(r) > 0, (l,r) -> l.compareTo(r) > 0), + LESSER_THEN ("<", (l,r) -> l.compareTo(r) < 0, (l,r) -> l.compareTo(r) < 0, (l,r) -> l.compareTo(r) < 0), + GREATER_OR_EQUALS (">=",(l,r) -> l.compareTo(r) >= 0, (l,r) -> l.compareTo(r) >= 0, (l,r) -> l.compareTo(r) >= 0), + LESSER_OR_EQUALS ("<=",(l,r) -> l.compareTo(r) <= 0, (l,r) -> l.compareTo(r) <= 0, (l,r) -> l.compareTo(r) <= 0), + ; + + private final String jsCode; + private final String enCode; + private final BiFunction opertionDouble; // TODO: convert to IntPredicate + private final BiFunction opertionInteger; + private final BiFunction opertionString; + + private UnitXCConverterStepConditionEquality(String jsCode, BiFunction opertionDouble,BiFunction opertionInteger,BiFunction opertionString) { + this.jsCode = jsCode; + this.enCode = name().toLowerCase().replaceAll("_", StringUtils.SPACE); + this.opertionDouble = opertionDouble; + this.opertionInteger = opertionInteger; + this.opertionString = opertionString; + } + + public boolean execute(Object left, Object right) { + if (Double.class.equals(left.getClass())) { + return opertionDouble.apply(Double.class.cast(left), Double.class.cast(right)); + } + if (Integer.class.equals(left.getClass())) { + return opertionInteger.apply(Integer.class.cast(left), Integer.class.cast(right)); + } + if (String.class.equals(left.getClass())) { + return opertionString.apply(String.class.cast(left), String.class.cast(right)); + } + throw new IllegalArgumentException("Unknown typeClass: "+left.getClass()); + } + + public void toRuleCode(RuleStepCodePrinter printer, UnitXConverterStepValueRead operandA, UnitXConverterStepValueRead operandB) { + if (printer.isEnglish()) { + operandA.toRuleCodeRead(printer); + printer.append(" is ", enCode); + if (jsCode.contains("=")) { + printer.append(" to"); + } + printer.appendSpace(); + operandB.toRuleCodeRead(printer); + return; + } + operandA.toRuleCodeRead(printer); + printer.appendSpace(); + printer.append(jsCode); + printer.appendSpace(); + operandB.toRuleCodeRead(printer); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepOperation.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepOperation.java new file mode 100644 index 00000000..b9f817b9 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepOperation.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model.step; + +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead; +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReadWrite; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 17, 2015 + */ +public class UnitXCConverterStepOperation extends AbstractUnitXConverterStep { + + private UnitXCConverterStepOperationOperator operator; + private UnitXConverterStepValueRead operandA; + private UnitXConverterStepValueRead operandB; + private UnitXConverterStepValueReadWrite result; + + public UnitXCConverterStepOperation() { + } + + public UnitXCConverterStepOperation(UnitXCConverterStepOperationOperator operator,UnitXConverterStepValueRead operandA,UnitXConverterStepValueRead operandB,UnitXConverterStepValueReadWrite result) { + setOperator(operator); + setOperandA(operandA); + setOperandB(operandB); + setResult(result); + } + + @Override + public void runStep(UnitXConverterStepContext ctx) { + result.valueWrite(ctx, operator.execute(operandA.valueRead(ctx),operandB.valueRead(ctx))); + } + + @Override + public void toRuleCode(RuleStepCodePrinter printer) { + if (printer.isEnglish()) { + printer.lineStart("Update "); + getResult().toRuleCodeWrite(printer); + printer.append(" with value from "); + getOperator().toRuleCode(printer, getOperandA(), getOperandB()); + printer.lineEnd("."); + return; + } + printer.lineStart(); + getResult().toRuleCodeWrite(printer); + printer.append(" = "); + getOperator().toRuleCode(printer, getOperandA(), getOperandB()); + printer.lineEnd(); + } + + /** + * @return the operator + */ + public UnitXCConverterStepOperationOperator getOperator() { + return operator; + } + + /** + * @param operator the operator to set + */ + public void setOperator(UnitXCConverterStepOperationOperator operator) { + this.operator = operator; + } + + /** + * @return the operandA + */ + public UnitXConverterStepValueRead getOperandA() { + return operandA; + } + + /** + * @param operandA the operandA to set + */ + public void setOperandA(UnitXConverterStepValueRead operandA) { + this.operandA = operandA; + } + + /** + * @return the operandB + */ + public UnitXConverterStepValueRead getOperandB() { + return operandB; + } + + /** + * @param operandB the operandB to set + */ + public void setOperandB(UnitXConverterStepValueRead operandB) { + this.operandB = operandB; + } + + /** + * @return the result + */ + public UnitXConverterStepValueReadWrite getResult() { + return result; + } + + /** + * @param result the result to set + */ + public void setResult(UnitXConverterStepValueReadWrite result) { + this.result = result; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepOperationOperator.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepOperationOperator.java new file mode 100644 index 00000000..5f16ed8c --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepOperationOperator.java @@ -0,0 +1,86 @@ +package net.forwardfire.unitxc.model.step; + +import java.math.BigDecimal; +import java.math.MathContext; +import java.util.function.BinaryOperator; + +import org.apache.commons.lang3.StringUtils; + +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead; + +public enum UnitXCConverterStepOperationOperator { + + ADD ("+",(l,r) -> l+r, (l,r) -> l+r, (l,r) -> l+r), + SUBTRACT ("-",(l,r) -> l-r, (l,r) -> l-r, (l,r) -> l.replaceAll(l, StringUtils.EMPTY)), + MULTIPLY ("*",(l,r) -> l*r, (l,r) -> l*r, null), + DIVIDE ("/",(l,r) -> l/r, (l,r) -> l/r, null), + POWER ("pow",(l,r) -> p(l,r), (l,r) -> p(l,r), null), + AND ("&", null, (l,r) -> l & r, null), + OR ("|",null, (l,r) -> l | r, null), + ; + + private final String jsCode; + private final String enCode; + private final BinaryOperator opertionDouble; + private final BinaryOperator opertionInteger; + private final BinaryOperator opertionString; + + private UnitXCConverterStepOperationOperator(String jsCode, BinaryOperator opertionDouble,BinaryOperator opertionInteger,BinaryOperator opertionString) { + this.jsCode = jsCode; + this.enCode = name().toLowerCase(); + this.opertionDouble = opertionDouble; + this.opertionInteger = opertionInteger; + this.opertionString = opertionString; + } + + private static BigDecimal p(BigDecimal l,BigDecimal r) { + return l.pow(r.intValueExact(), MathContext.UNLIMITED); + } + + private static double p(double l,double r) { + return Math.pow(l, r); + } + + private static int p(int l,int r) { + for (int i=0;i0):exponent>0); + } + return value; + } + + private double shiftDotStatic(double value,boolean up) { + String valueStr = ""+value; + int dotIdx = valueStr.indexOf('.'); + StringBuilder buf = new StringBuilder(); + buf.append(valueStr); + buf.deleteCharAt(dotIdx); + if (up) { + buf.insert(dotIdx+1, '.'); + } else { + buf.insert(dotIdx-1, '.'); + } + + Double result = new Double(buf.toString()); + return result.doubleValue(); + } + + /** + * @return the exponent + */ + public int getExponent() { + return exponent; + } + + /** + * @param exponent the exponent to set + */ + public void setExponent(int exponent) { + this.exponent = exponent; + } + + /** + * @return the exponentReverse + */ + public boolean isExponentReverse() { + return exponentReverse; + } + + /** + * @param exponentReverse the exponentReverse to set + */ + public void setExponentReverse(boolean exponentReverse) { + this.exponentReverse = exponentReverse; + } + + /** + * @return the operand + */ + public UnitXConverterStepValueRead getOperand() { + return operand; + } + + /** + * @param operand the operand to set + */ + public void setOperand(UnitXConverterStepValueRead operand) { + this.operand = operand; + } + + /** + * @return the result + */ + public UnitXConverterStepValueReadWrite getResult() { + return result; + } + + /** + * @param result the result to set + */ + public void setResult(UnitXConverterStepValueReadWrite result) { + this.result = result; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepReference.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepReference.java new file mode 100644 index 00000000..771dbd4d --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXCConverterStepReference.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model.step; + +import java.util.List; + +import org.apache.commons.lang3.Validate; + +import net.forwardfire.unitxc.model.UnitXCType; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 7, 2016 + */ +public class UnitXCConverterStepReference extends AbstractUnitXConverterStep { + + private final UnitXCType unitType; + private final boolean toBaseSteps; + + public UnitXCConverterStepReference(UnitXCType unitType,boolean toBaseSteps) { + this.unitType = Validate.notNull(unitType); + this.toBaseSteps = toBaseSteps; + } + + @Override + public void runStep(UnitXConverterStepContext ctx) { + List steps = toBaseSteps?unitType.getToBaseConverterSteps():unitType.getFromBaseConverterSteps(); + ctx.runSteps(steps); + } + + @Override + public void toRuleCode(RuleStepCodePrinter printer) { + if (printer.isEnglish()) { + printer.lineStart("Call ", unitType.getName()); + printer.append(" with base steps ... "); + printer.lineEnd("."); + return; + } + printer.lineStart(); + printer.append(" TODO REF "); + printer.lineEnd(); + } + + /** + * @return the unitType + */ + public UnitXCType getUnitType() { + return unitType; + } + + /** + * @return the toBaseSteps + */ + public boolean toBaseSteps() { + return toBaseSteps; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXConverterStep.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXConverterStep.java new file mode 100644 index 00000000..5c0c52b4 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXConverterStep.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model.step; + +import java.util.List; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 10, 2015 + */ +public interface UnitXConverterStep { + + void runStep(UnitXConverterStepContext ctx); + + List getStepReasons(); + + void addStepReason(String stepReason); // TODO: rm : fix builder + + void toRuleCode(RuleStepCodePrinter printer); +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXConverterStepContext.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXConverterStepContext.java new file mode 100644 index 00000000..5f70d450 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/UnitXConverterStepContext.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model.step; + +import java.math.MathContext; +import java.util.List; + +import net.forwardfire.unitxc.UnitXCManager; +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueNamedVariable; +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead; +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReadWrite; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 10, 2015 + */ +public interface UnitXConverterStepContext { + + static final String VALUE = "value"; + static final String VALUE_START = "valueStart"; + + MathContext getMathContext(); + + void setNamedVariable(String name,UnitXConverterStepValueReadWrite variable); + + UnitXConverterStepValueReadWrite getNamedVariable(String name); + + UnitXConverterStepValueRead getNamedParameter(String name); + + void runSteps(List steps); + + public static UnitXConverterStepValueReadWrite createStepValue() { + return new UnitXConverterStepValueNamedVariable(Double.class,VALUE); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/package-info.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/package-info.java new file mode 100644 index 00000000..2478659c --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/package-info.java @@ -0,0 +1,7 @@ + + +/** + * @author willemc + * + */ +package net.forwardfire.unitxc.model.step; \ No newline at end of file diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueNamedParameter.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueNamedParameter.java new file mode 100644 index 00000000..136096df --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueNamedParameter.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model.step.value; + +import net.forwardfire.unitxc.model.step.RuleStepCodePrinter; +import net.forwardfire.unitxc.model.step.UnitXConverterStepContext; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Apr 1, 2016 + */ +public class UnitXConverterStepValueNamedParameter implements UnitXConverterStepValueRead { + + private String parameterName; + + public UnitXConverterStepValueNamedParameter() { + } + + public UnitXConverterStepValueNamedParameter(String parameterName) { + setParameterName(parameterName); + } + + @Override + public Object valueRead(UnitXConverterStepContext ctx) { + return ctx.getNamedParameter(parameterName).valueRead(ctx); + } + + @Override + public void toRuleCodeRead(RuleStepCodePrinter printer) { + if (printer.isEnglish()) { + printer.append(parameterName); + return; + } + printer.append("ctx.params['",parameterName,"']"); + } + +// @Override +// public void toRuleCodeWrite(RuleStepCodePrinter printer) { +// toRuleCodeRead(printer); +// } + + /** + * @return the parameterName + */ + public String getParameterName() { + return parameterName; + } + + /** + * @param parameterName the parameterName to set + */ + public void setParameterName(String parameterName) { + this.parameterName = parameterName; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueNamedVariable.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueNamedVariable.java new file mode 100644 index 00000000..05010297 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueNamedVariable.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model.step.value; + +import net.forwardfire.unitxc.model.step.RuleStepCodePrinter; +import net.forwardfire.unitxc.model.step.UnitXConverterStepContext; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Apr 1, 2016 + */ +public class UnitXConverterStepValueNamedVariable implements UnitXConverterStepValueReadWrite { + + private Class valueType; + private String variableName; + + public UnitXConverterStepValueNamedVariable() { + } + + public UnitXConverterStepValueNamedVariable(Class valueType,String variableName) { + setValueType(valueType); + setVariableName(variableName); + } + + @Override + public Object valueRead(UnitXConverterStepContext ctx) { + return ctx.getNamedVariable(variableName).valueRead(ctx); + } + + @Override + public void valueWrite(UnitXConverterStepContext ctx,Object value) { + ctx.getNamedVariable(variableName).valueWrite(ctx,value); + } + + @Override + public void toRuleCodeRead(RuleStepCodePrinter printer) { + if (printer.isEnglish()) { + printer.append(variableName); + } else { + printer.append("ctx.vars['",variableName,"']"); + } + } + + @Override + public void toRuleCodeWrite(RuleStepCodePrinter printer) { + toRuleCodeRead(printer); + } + + /** + * @return the variableName + */ + public String getVariableName() { + return variableName; + } + + /** + * @param variableName the variableName to set + */ + public void setVariableName(String variableName) { + this.variableName = variableName; + } + + /** + * @return the valueType + */ + public Class getValueType() { + return valueType; + } + + /** + * @param valueType the valueType to set + */ + public void setValueType(Class valueType) { + this.valueType = valueType; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueRead.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueRead.java new file mode 100644 index 00000000..8398ace6 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueRead.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model.step.value; + +import net.forwardfire.unitxc.model.step.RuleStepCodePrinter; +import net.forwardfire.unitxc.model.step.UnitXConverterStepContext; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Apr 1, 2016 + */ +public interface UnitXConverterStepValueRead { + + Object valueRead(UnitXConverterStepContext ctx); + + void toRuleCodeRead(RuleStepCodePrinter printer); +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueReadWrite.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueReadWrite.java new file mode 100644 index 00000000..97f453de --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueReadWrite.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model.step.value; + +import net.forwardfire.unitxc.model.step.RuleStepCodePrinter; +import net.forwardfire.unitxc.model.step.UnitXConverterStepContext; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Apr 1, 2016 + */ +public interface UnitXConverterStepValueReadWrite extends UnitXConverterStepValueRead { + + void valueWrite(UnitXConverterStepContext ctx,Object value); + + void toRuleCodeWrite(RuleStepCodePrinter printer); +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueReferenceDouble.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueReferenceDouble.java new file mode 100644 index 00000000..e8171035 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueReferenceDouble.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model.step.value; + +import org.apache.commons.lang3.StringUtils; + +import net.forwardfire.unitxc.model.step.RuleStepCodePrinter; +import net.forwardfire.unitxc.model.step.UnitXConverterStepContext; + +/** + * Holds an Double value. + * + * @author Willem Cazander + * @version 1.0 Apr 1, 2016 + */ +public class UnitXConverterStepValueReferenceDouble implements UnitXConverterStepValueReadWrite { + + private Double value; + + public UnitXConverterStepValueReferenceDouble() { + } + + public UnitXConverterStepValueReferenceDouble(Double value) { + setValue(value); + } + + @Override + public Object valueRead(UnitXConverterStepContext ctx) { + return value; + } + + @Override + public void valueWrite(UnitXConverterStepContext ctx,Object value) { + this.value = Double.class.cast(value); + } + + @Override + public void toRuleCodeRead(RuleStepCodePrinter printer) { + printer.append(""+value); + } + + @Override + public void toRuleCodeWrite(RuleStepCodePrinter printer) { + printer.append(StringUtils.EMPTY); + } + + /** + * @return the value + */ + public Double getValue() { + return value; + } + + /** + * @param value the value to set + */ + public void setValue(Double value) { + this.value = value; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueReferenceDoubleFraction.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueReferenceDoubleFraction.java new file mode 100644 index 00000000..95094368 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueReferenceDoubleFraction.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model.step.value; + +import net.forwardfire.unitxc.model.step.RuleStepCodePrinter; +import net.forwardfire.unitxc.model.step.UnitXConverterStepContext; + +/** + * Holds an Double value as a Fraction. + * + * @author Willem Cazander + * @version 1.0 Apr 1, 2016 + */ +public class UnitXConverterStepValueReferenceDoubleFraction implements UnitXConverterStepValueRead { + + private int numerator; + private int denominator; + + public UnitXConverterStepValueReferenceDoubleFraction() { + } + + public UnitXConverterStepValueReferenceDoubleFraction(int numerator,int denominator) { + setNumerator(numerator); + setDenominator(denominator); + } + + @Override + public Object valueRead(UnitXConverterStepContext ctx) { + //new BigDecimal(numerator).divide(new BigDecimal(denominator)); + return (Double)(((Integer)numerator).doubleValue()/((Integer)denominator).doubleValue()); // FIXME + } + + @Override + public void toRuleCodeRead(RuleStepCodePrinter printer) { + printer.append(""+numerator+"/"+denominator); + } + + /** + * @return the numerator + */ + public int getNumerator() { + return numerator; + } + + /** + * @param numerator the numerator to set + */ + public void setNumerator(int numerator) { + this.numerator = numerator; + } + + /** + * @return the denominator + */ + public int getDenominator() { + return denominator; + } + + /** + * @param denominator the denominator to set + */ + public void setDenominator(int denominator) { + this.denominator = denominator; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueReferenceInteger.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueReferenceInteger.java new file mode 100644 index 00000000..bef75c60 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueReferenceInteger.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model.step.value; + +import org.apache.commons.lang3.StringUtils; + +import net.forwardfire.unitxc.model.step.RuleStepCodePrinter; +import net.forwardfire.unitxc.model.step.UnitXConverterStepContext; + +/** + * Holds an Integer value. + * + * @author Willem Cazander + * @version 1.0 Apr 1, 2016 + */ +public class UnitXConverterStepValueReferenceInteger implements UnitXConverterStepValueReadWrite { + + private Integer value; + + public UnitXConverterStepValueReferenceInteger() { + } + + public UnitXConverterStepValueReferenceInteger(Integer value) { + setValue(value); + } + + @Override + public Object valueRead(UnitXConverterStepContext ctx) { + return value; + } + + @Override + public void valueWrite(UnitXConverterStepContext ctx,Object value) { + this.value = Integer.class.cast(value); + } + + @Override + public void toRuleCodeRead(RuleStepCodePrinter printer) { + printer.append(""+value); + } + + @Override + public void toRuleCodeWrite(RuleStepCodePrinter printer) { + printer.append(StringUtils.EMPTY); + } + + /** + * @return the value + */ + public Integer getValue() { + return value; + } + + /** + * @param value the value to set + */ + public void setValue(Integer value) { + this.value = value; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueReferenceString.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueReferenceString.java new file mode 100644 index 00000000..e50bb0be --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/UnitXConverterStepValueReferenceString.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.model.step.value; + +import org.apache.commons.lang3.StringUtils; + +import net.forwardfire.unitxc.model.step.RuleStepCodePrinter; +import net.forwardfire.unitxc.model.step.UnitXConverterStepContext; + +/** + * Holds an String value. + * + * @author Willem Cazander + * @version 1.0 Apr 1, 2016 + */ +public class UnitXConverterStepValueReferenceString implements UnitXConverterStepValueReadWrite { + + private String value; + + public UnitXConverterStepValueReferenceString() { + } + + public UnitXConverterStepValueReferenceString(String value) { + setValue(value); + } + + @Override + public Object valueRead(UnitXConverterStepContext ctx) { + return value; + } + + @Override + public void valueWrite(UnitXConverterStepContext ctx,Object value) { + this.value = String.class.cast(value); + } + + @Override + public void toRuleCodeRead(RuleStepCodePrinter printer) { + if (value instanceof String && printer.isJavascript()) { + String valueEscaped = value.toString().replaceAll("'", "\\\\'"); + printer.append("'",valueEscaped,"'"); + } else { + printer.append(""+value); + } + } + + @Override + public void toRuleCodeWrite(RuleStepCodePrinter printer) { + printer.append(StringUtils.EMPTY); + } + + /** + * @return the value + */ + public String getValue() { + return value; + } + + /** + * @param value the value to set + */ + public void setValue(String value) { + this.value = value; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/package-info.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/package-info.java new file mode 100644 index 00000000..3f175a02 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/model/step/value/package-info.java @@ -0,0 +1,5 @@ +/** + * @author willemc + * + */ +package net.forwardfire.unitxc.model.step.value; \ No newline at end of file diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleAmpere.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleAmpere.java new file mode 100644 index 00000000..c38efb27 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleAmpere.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module; + +import static net.forwardfire.unitxc.config.UnitXCConfigModule.buildFlag; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 18, 2015 + */ +public class UnitXCModuleAmpere implements UnitXCConfigModule { + + public static final String GROUP_ID = "ampere"; + public static final String GROUP_BASE_TYPE_ID = "A"; + private static final String[] GROUP_QUANTITIES = {"electric_current"}; + + public static final String TYPE_AMPERE_ID = GROUP_BASE_TYPE_ID; + public static final String TYPE_AMPERE_NAME = "ampere"; + public static final String TYPE_AMPERE_FLAG = buildFlag(GROUP_ID,TYPE_AMPERE_NAME); + private static final String TYPE_AMPERE_WIKI = "Ampere"; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupBase(GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId(GROUP_BASE_TYPE_ID) + .createSIUnitTypes() + .setId( TYPE_AMPERE_ID) + .setName( TYPE_AMPERE_NAME) + .addTypeFlag( TYPE_AMPERE_FLAG) + .setWebLinkWiki( TYPE_AMPERE_WIKI) + .addCommonSIPrefix(UnitXCTypeSIPrefix.MEGA) + .addCommonSIPrefix(UnitXCTypeSIPrefix.KILO) + .addCommonSIPrefix(UnitXCTypeSIPrefix.MILLI) + .addCommonSIPrefix(UnitXCTypeSIPrefix.MICRO) + .addCommonSIPrefix(UnitXCTypeSIPrefix.NANO) + .build() + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleCandela.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleCandela.java new file mode 100644 index 00000000..0fac5082 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleCandela.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module; + +import static net.forwardfire.unitxc.config.UnitXCConfigModule.buildFlag; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 23, 2015 + */ +public class UnitXCModuleCandela implements UnitXCConfigModule { + + public static final String GROUP_ID = "candela"; + public static final String GROUP_BASE_TYPE_ID = "cd"; + private static final String[] GROUP_QUANTITIES = {"luminous_intensity"}; + + public static final String TYPE_CANDELA_ID = GROUP_BASE_TYPE_ID; + public static final String TYPE_CANDELA_NAME = "candela"; + public static final String TYPE_CANDELA_FLAG = buildFlag(GROUP_ID,TYPE_CANDELA_NAME); + private static final String TYPE_CANDELA_WIKI = "Candela"; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupBase(GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId(GROUP_BASE_TYPE_ID) + .createSIUnitTypes() + .setId( TYPE_CANDELA_ID) + .setName( TYPE_CANDELA_NAME) + .addTypeFlag( TYPE_CANDELA_FLAG) + .setWebLinkWiki( TYPE_CANDELA_WIKI) + .build() + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleKelvin.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleKelvin.java new file mode 100644 index 00000000..c0521ab6 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleKelvin.java @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; + +import static net.forwardfire.unitxc.config.UnitXCConfigModule.buildFlag; + +import org.apache.commons.lang3.math.Fraction; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 17, 2015 + */ +public class UnitXCModuleKelvin implements UnitXCConfigModule { + + public static final String GROUP_ID = "kelvin"; + public static final String GROUP_BASE_TYPE_ID = "K"; + private static final String[] GROUP_QUANTITIES = {"thermodynamic_temperature"}; + + public static final String TYPE_KELVIN_ID = GROUP_BASE_TYPE_ID; + public static final String TYPE_KELVIN_NAME = GROUP_ID; + public static final String TYPE_KELVIN_FLAG = buildFlag(GROUP_ID,TYPE_KELVIN_NAME); + private static final String TYPE_KELVIN_WIKI = "Kelvin"; + + public static final String TYPE_CELSIUS_ID = "°C"; + public static final String TYPE_CELSIUS_NAME = "celsius"; + public static final String TYPE_CELSIUS_FLAG = buildFlag(GROUP_ID,TYPE_CELSIUS_NAME); + private static final double TYPE_CELSIUS_OFFSET = 273.15; + private static final String TYPE_CELSIUS_WIKI = "Celsius"; + + public static final String TYPE_FAHRENHEIT_ID = "°F"; + public static final String TYPE_FAHRENHEIT_NAME = "fahrenheit"; + public static final String TYPE_FAHRENHEIT_FLAG = buildFlag(GROUP_ID,TYPE_FAHRENHEIT_NAME); + private static final double TYPE_FAHRENHEIT_OFFSET = 459.67; + private static final Fraction TYPE_FAHRENHEIT_FRACTION = Fraction.getFraction(5,9); + private static final String TYPE_FAHRENHEIT_WIKI = "Fahrenheit"; + + public static final String TYPE_RANKINE_ID = "°R"; + public static final String TYPE_RANKINE_NAME = "rankine"; + public static final String TYPE_RANKINE_FLAG = buildFlag(GROUP_ID,TYPE_RANKINE_NAME); + private static final String TYPE_RANKINE_WIKI = "Rankine_scale"; + + public static final String TYPE_ROMER_ID = "Rø"; + public static final String TYPE_ROMER_NAME = "rømer"; + public static final String TYPE_ROMER_FLAG = buildFlag(GROUP_ID,TYPE_ROMER_NAME); + public static final String TYPE_ROMER_ALIAS_NAME = "romer"; + public static final String TYPE_ROMER_ALIAS_FLAG = buildFlag(GROUP_ID,TYPE_ROMER_ALIAS_NAME); + private static final Fraction TYPE_ROMER_FRACTION = Fraction.getFraction(40,21); + private static final double TYPE_ROMER_FRACTION_OFFSET = 7.5; + private static final String TYPE_ROMER_WIKI = "Rømer_scale"; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupBase(GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId( TYPE_KELVIN_ID) + .createSIUnitTypes() + .setId( TYPE_KELVIN_ID) + .setName( TYPE_KELVIN_NAME) + .addTypeFlag( TYPE_KELVIN_FLAG) + .setWebLinkWiki(TYPE_KELVIN_WIKI) + .build() + .createSIUnitTypes() + .setId( TYPE_CELSIUS_ID) + .setName( TYPE_CELSIUS_NAME) + .addTypeFlag( TYPE_CELSIUS_FLAG) + .setWebLinkWiki(TYPE_CELSIUS_WIKI) + .createToBaseConverterSteps().offsetUp(TYPE_CELSIUS_OFFSET).build() + .createFromBaseConverterSteps().offsetDown(TYPE_CELSIUS_OFFSET).build() + .build() + .createSIUnitTypes() + .setId( TYPE_FAHRENHEIT_ID) + .setName( TYPE_FAHRENHEIT_NAME) + .addTypeFlag( TYPE_FAHRENHEIT_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .setWebLinkWiki( TYPE_FAHRENHEIT_WIKI) + .createToBaseConverterSteps() + .offsetUp( TYPE_FAHRENHEIT_OFFSET) + .multiply( TYPE_FAHRENHEIT_FRACTION) + .build() + .createFromBaseConverterSteps() + .multiply( TYPE_FAHRENHEIT_FRACTION.invert()) + .offsetDown( TYPE_FAHRENHEIT_OFFSET) + .build() + .build() + .createSIUnitTypes() + .setId( TYPE_RANKINE_ID) + .setName( TYPE_RANKINE_NAME) + .addTypeFlag ( TYPE_RANKINE_FLAG) + .setWebLinkWiki( TYPE_RANKINE_WIKI) + .createToBaseConverterSteps().multiply(TYPE_FAHRENHEIT_FRACTION).build() + .createFromBaseConverterSteps().multiply(TYPE_FAHRENHEIT_FRACTION.invert()).build() + .build() + .createSIUnitTypes() + .setId( TYPE_ROMER_ID) + .setName( TYPE_ROMER_NAME) + .addTypeFlag( TYPE_ROMER_FLAG) + .setWebLinkWiki( TYPE_ROMER_WIKI) + .createToBaseConverterSteps() + .offsetUp( TYPE_CELSIUS_OFFSET) + .multiply( TYPE_ROMER_FRACTION) + .offsetUp( TYPE_ROMER_FRACTION_OFFSET) + .build() + .createFromBaseConverterSteps() + .offsetDown( TYPE_ROMER_FRACTION_OFFSET) + .multiply( TYPE_ROMER_FRACTION.invert()) + .offsetDown( TYPE_CELSIUS_OFFSET) + .build() + .build() + .createSIUnitTypes() + .setAliasOfType( TYPE_ROMER_ID) + .setId( TYPE_ROMER_ALIAS_NAME) + .setName( TYPE_ROMER_ALIAS_NAME) + .addTypeFlag( TYPE_ROMER_ALIAS_FLAG) + .build() + .build() + ; + } +} + diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleKilogram.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleKilogram.java new file mode 100644 index 00000000..4168d466 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleKilogram.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module; + +import static net.forwardfire.unitxc.config.UnitXCConfigModule.buildFlag; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 25, 2015 + */ +public class UnitXCModuleKilogram implements UnitXCConfigModule { + + public static final String GROUP_ID = "kilogram"; + public static final String GROUP_BASE_TYPE_ID = "g"; + private static final String[] GROUP_QUANTITIES = {"mass"}; + + public static final String TYPE_GRAM_ID = GROUP_BASE_TYPE_ID; + public static final String TYPE_GRAM_NAME = "gram"; + public static final String TYPE_GRAM_FLAG = buildFlag(GROUP_ID,TYPE_GRAM_NAME); + private static final String TYPE_GRAM_WIKI = "Kilogram"; + + public static final String TYPE_GRAIN_ID = "gr"; + public static final String TYPE_GRAIN_NAME = "grain"; + public static final String TYPE_GRAIN_FLAG = buildFlag(GROUP_ID,TYPE_GRAIN_NAME); + private static final double TYPE_GRAIN_FACTOR = 64.80; + private static final String TYPE_GRAIN_WIKI = "Grain_(unit)"; + + public static final String TYPE_DRAM_ID = "dr"; + public static final String TYPE_DRAM_NAME = "dram"; + public static final String TYPE_DRAM_FLAG = buildFlag(GROUP_ID,TYPE_DRAM_NAME); + private static final double TYPE_DRAM_FACTOR = 1.772; + private static final String TYPE_DRAM_WIKI = "Dram_(unit)"; + + public static final String TYPE_OUNCE_ID = "oz"; + public static final String TYPE_OUNCE_NAME = "ounce"; + public static final String TYPE_OUNCE_FLAG = buildFlag(GROUP_ID,TYPE_OUNCE_NAME); + private static final double TYPE_OUNCE_FACTOR = 28.35; + private static final String TYPE_OUNCE_WIKI = "Ounce"; + + public static final String TYPE_POUND_ID = "lb"; + public static final String TYPE_POUND_NAME = "pound"; + public static final String TYPE_POUND_FLAG = buildFlag(GROUP_ID,TYPE_POUND_NAME); + private static final double TYPE_POUND_FACTOR = 453.6; + private static final String TYPE_POUND_WIKI = "Pound_(mass)"; + + public static final String TYPE_STONE_ID = "st"; + public static final String TYPE_STONE_NAME = "stone"; + public static final String TYPE_STONE_FLAG = buildFlag(GROUP_ID,TYPE_STONE_NAME); + private static final double TYPE_STONE_FACTOR = 6.350; + private static final String TYPE_STONE_WIKI = "Stone_(unit)"; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupBase(GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId(GROUP_BASE_TYPE_ID) + .createSIUnitTypes() + .setId( TYPE_GRAM_ID) + .setName( TYPE_GRAM_NAME) + .addTypeFlag( TYPE_GRAM_FLAG) + .setWebLinkWiki( TYPE_GRAM_WIKI) + .addCommonSIPrefix(UnitXCTypeSIPrefix.MEGA) + .addCommonSIPrefix(UnitXCTypeSIPrefix.KILO) + .addCommonSIPrefix(UnitXCTypeSIPrefix.HECTO) + .addCommonSIPrefix(UnitXCTypeSIPrefix.DECI) + .addCommonSIPrefix(UnitXCTypeSIPrefix.DECA) + .addCommonSIPrefix(UnitXCTypeSIPrefix.CENTI) + .addCommonSIPrefix(UnitXCTypeSIPrefix.MILLI) + .addCommonSIPrefix(UnitXCTypeSIPrefix.MICRO) + .build() + .createSIUnitTypes() + .setId( TYPE_GRAIN_ID) + .setName( TYPE_GRAIN_NAME) + .addTypeFlag( TYPE_GRAIN_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .setWebLinkWiki( TYPE_GRAIN_WIKI) + .createToBaseConverterSteps().multiply(TYPE_GRAIN_FACTOR).power10Down(UnitXCTypeSIPrefix.MILLI).build() + .createFromBaseConverterSteps().power10Up(UnitXCTypeSIPrefix.MILLI).divide(TYPE_GRAIN_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_DRAM_ID) + .setName( TYPE_DRAM_NAME) + .addTypeFlag( TYPE_DRAM_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL_EXTRA) + .setWebLinkWiki( TYPE_DRAM_WIKI) + .createToBaseConverterSteps().multiply(TYPE_DRAM_FACTOR).build() + .createFromBaseConverterSteps().divide(TYPE_DRAM_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_OUNCE_ID) + .setName( TYPE_OUNCE_NAME) + .addTypeFlag( TYPE_OUNCE_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .setWebLinkWiki( TYPE_OUNCE_WIKI) + .createToBaseConverterSteps().multiply(TYPE_OUNCE_FACTOR).build() + .createFromBaseConverterSteps().divide(TYPE_OUNCE_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_POUND_ID) + .setName( TYPE_POUND_NAME) + .addTypeFlag( TYPE_POUND_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .setWebLinkWiki( TYPE_POUND_WIKI) + .createToBaseConverterSteps().multiply(TYPE_POUND_FACTOR).build() + .createFromBaseConverterSteps().divide(TYPE_POUND_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_STONE_ID) + .setName( TYPE_STONE_NAME) + .addTypeFlag( TYPE_STONE_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL_EXTRA) + .setWebLinkWiki( TYPE_STONE_WIKI) + .createToBaseConverterSteps().multiply(TYPE_STONE_FACTOR).power10Up(UnitXCTypeSIPrefix.MILLI).build() + .createFromBaseConverterSteps().power10Down(UnitXCTypeSIPrefix.MILLI).divide(TYPE_STONE_FACTOR).build() + .build() + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleMetre.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleMetre.java new file mode 100644 index 00000000..636b984e --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleMetre.java @@ -0,0 +1,243 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module; + +import static net.forwardfire.unitxc.config.UnitXCConfigModule.buildFlag; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 24, 2015 + */ +public class UnitXCModuleMetre implements UnitXCConfigModule { + + public static final String GROUP_ID = "metre"; + public static final String GROUP_BASE_TYPE_ID = "m"; + private static final String[] GROUP_QUANTITIES = {"length"}; + + public static final String TYPE_METRE_ID = GROUP_BASE_TYPE_ID; + public static final String TYPE_METRE_NAME = "metre"; + public static final String TYPE_METRE_FLAG = buildFlag(GROUP_ID,TYPE_METRE_NAME); + public static final String TYPE_METRE_ALIAS_METER = "meter"; + public static final String TYPE_METRE_ALIAS_METER_FLAG = buildFlag(GROUP_ID,TYPE_METRE_ALIAS_METER); + private static final String TYPE_METRE_WIKI = "Metre"; + private static final UnitXCTypeSIPrefix[] TYPE_METRE_COMMON_SI = new UnitXCTypeSIPrefix[] { + UnitXCTypeSIPrefix.KILO, + UnitXCTypeSIPrefix.HECTO, + UnitXCTypeSIPrefix.DECA, + UnitXCTypeSIPrefix.DECI, + UnitXCTypeSIPrefix.CENTI, + UnitXCTypeSIPrefix.MILLI, + UnitXCTypeSIPrefix.MICRO, + UnitXCTypeSIPrefix.NANO, + UnitXCTypeSIPrefix.PICO, + UnitXCTypeSIPrefix.FEMTO + }; + + public static final String TYPE_INCH_ID = "in"; + public static final String TYPE_INCH_NAME = "inch"; + public static final String TYPE_INCH_NAME_PLURAL = "inches"; + public static final String TYPE_INCH_FLAG = buildFlag(GROUP_ID,TYPE_INCH_NAME); + private static final double TYPE_INCH_FACTOR = 25.4; + private static final String TYPE_INCH_WIKI = "Inch"; + + public static final String TYPE_LINK_ID = "li"; + public static final String TYPE_LINK_NAME = "link"; + public static final String TYPE_LINK_FLAG = buildFlag(GROUP_ID,TYPE_LINK_NAME); + private static final double TYPE_LINK_FACTOR = 201.1; + public static final String TYPE_LINK_WIKI = "Link_(unit)"; + + public static final String TYPE_FOOT_ID = "ft"; + public static final String TYPE_FOOT_NAME = "foot"; + public static final String TYPE_FOOT_NAME_PLURAL = "feet"; + public static final String TYPE_FOOT_FLAG = buildFlag(GROUP_ID,TYPE_FOOT_NAME); + private static final double TYPE_FOOT_FACTOR = 304.8; + private static final String TYPE_FOOT_WIKI = "Foot_(unit)"; + + public static final String TYPE_YARD_ID = "yd"; + public static final String TYPE_YARD_NAME = "yard"; + public static final String TYPE_YARD_FLAG = buildFlag(GROUP_ID,TYPE_YARD_NAME); + private static final double TYPE_YARD_FACTOR = 0.9144; + private static final String TYPE_YARD_WIKI = "Yard"; + + public static final String TYPE_ROD_ID = "rd"; + public static final String TYPE_ROD_NAME = "rod"; + public static final String TYPE_ROD_FLAG = buildFlag(GROUP_ID,TYPE_ROD_NAME); + private static final double TYPE_ROD_FACTOR = 5.029; + private static final String TYPE_ROD_WIKI = "Rod_(unit)"; + + public static final String TYPE_CHAIN_ID = "ch"; + public static final String TYPE_CHAIN_NAME = "chain"; + public static final String TYPE_CHAIN_FLAG = buildFlag(GROUP_ID,TYPE_CHAIN_NAME); + private static final double TYPE_CHAIN_FACTOR = 20.117; + private static final String TYPE_CHAIN_WIKI = "Chain_(unit)"; + + public static final String TYPE_FURLONG_ID = "fur"; + public static final String TYPE_FURLONG_NAME = "furlong"; + public static final String TYPE_FURLONG_FLAG = buildFlag(GROUP_ID,TYPE_FURLONG_NAME); + private static final double TYPE_FURLONG_FACTOR = 201.17; + private static final String TYPE_FURLONG_WIKI = "Furlong"; + + public static final String TYPE_MILE_ID = "mi"; + public static final String TYPE_MILE_NAME = "mile"; + public static final String TYPE_MILE_FLAG = buildFlag(GROUP_ID,TYPE_MILE_NAME); + private static final double TYPE_MILE_FACTOR = 1609.344; + private static final String TYPE_MILE_WIKI = "Mile"; + + public static final String TYPE_MILE_US_ID = "us-mi"; + public static final String TYPE_MILE_US_NAME = "us-mile"; + public static final String TYPE_MILE_US_FLAG = buildFlag(GROUP_ID,TYPE_MILE_US_NAME); + private static final double TYPE_MILE_US_FACTOR = 1609.34721869; + private static final String TYPE_MILE_US_WIKI = "Mile#US_survey_mile"; + + public static final String TYPE_MILE_NAUTICAL_ID = "nau-mi"; + public static final String TYPE_MILE_NAUTICAL_NAME = "nautical-mile"; + public static final String TYPE_MILE_NAUTICAL_FLAG = buildFlag(GROUP_ID,TYPE_MILE_NAUTICAL_NAME); + private static final double TYPE_MILE_NAUTICAL_FACTOR = 1852; + private static final String TYPE_MILE_NAUTICAL_WIKI = "Mile#Nautical_mile"; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupBase(GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId( TYPE_METRE_ID) + .createSIUnitTypes() + .setId( TYPE_METRE_ID) + .setName( TYPE_METRE_NAME) + .addTypeFlag( TYPE_METRE_FLAG) + .setWebLinkWiki( TYPE_METRE_WIKI) + .addCommonSIPrefixes(TYPE_METRE_COMMON_SI) + .build() + .createSIUnitTypes() + .setAliasOfType(TYPE_METRE_ID) + .setId( TYPE_METRE_ALIAS_METER) + .setName( TYPE_METRE_ALIAS_METER) + .addTypeFlag( TYPE_METRE_ALIAS_METER_FLAG) + .addCommonSIPrefixes(TYPE_METRE_COMMON_SI) + .build() + .createSIUnitTypes() + .setId( TYPE_INCH_ID) + .setName( TYPE_INCH_NAME) + .setNamePlural( TYPE_INCH_NAME_PLURAL) + .addTypeFlag( TYPE_INCH_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .setWebLinkWiki( TYPE_INCH_WIKI) + .createToBaseConverterSteps().multiply(TYPE_INCH_FACTOR).power10Down(UnitXCTypeSIPrefix.MILLI).build() + .createFromBaseConverterSteps().power10Up(UnitXCTypeSIPrefix.MILLI).divide(TYPE_INCH_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_LINK_ID) + .setName( TYPE_LINK_NAME) + .addTypeFlag( TYPE_LINK_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL_EXTRA) + .setWebLinkWiki( TYPE_LINK_WIKI) + .createToBaseConverterSteps().multiply(TYPE_LINK_FACTOR).power10Down(UnitXCTypeSIPrefix.MILLI).build() + .createFromBaseConverterSteps().power10Up(UnitXCTypeSIPrefix.MILLI).divide(TYPE_LINK_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_FOOT_ID) + .setName( TYPE_FOOT_NAME) + .setNamePlural( TYPE_FOOT_NAME_PLURAL) + .addTypeFlag( TYPE_FOOT_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .setWebLinkWiki( TYPE_FOOT_WIKI) + .createToBaseConverterSteps().multiply(TYPE_FOOT_FACTOR).power10Down(UnitXCTypeSIPrefix.MILLI).build() + .createFromBaseConverterSteps().power10Up(UnitXCTypeSIPrefix.MILLI).divide(TYPE_FOOT_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_YARD_ID) + .setName( TYPE_YARD_NAME) + .addTypeFlag( TYPE_YARD_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .setWebLinkWiki( TYPE_YARD_WIKI) + .createToBaseConverterSteps().multiply(TYPE_YARD_FACTOR).build() + .createFromBaseConverterSteps().divide(TYPE_YARD_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_ROD_ID) + .setName( TYPE_ROD_NAME) + .addTypeFlag( TYPE_ROD_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL_EXTRA) + .setWebLinkWiki( TYPE_ROD_WIKI) + .createToBaseConverterSteps().multiply(TYPE_ROD_FACTOR).build() + .createFromBaseConverterSteps().divide(TYPE_ROD_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_CHAIN_ID) + .setName( TYPE_CHAIN_NAME) + .addTypeFlag( TYPE_CHAIN_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL_EXTRA) + .setWebLinkWiki( TYPE_CHAIN_WIKI) + .createToBaseConverterSteps().multiply(TYPE_CHAIN_FACTOR).build() + .createFromBaseConverterSteps().divide(TYPE_CHAIN_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_FURLONG_ID) + .setName( TYPE_FURLONG_NAME) + .addTypeFlag( TYPE_FURLONG_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL_EXTRA) + .setWebLinkWiki( TYPE_FURLONG_WIKI) + .createToBaseConverterSteps().multiply(TYPE_FURLONG_FACTOR).build() + .createFromBaseConverterSteps().divide(TYPE_FURLONG_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_MILE_ID) + .setName( TYPE_MILE_NAME) + .addTypeFlag( TYPE_MILE_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .setWebLinkWiki( TYPE_MILE_WIKI) + .createToBaseConverterSteps().multiply(TYPE_MILE_FACTOR).build() + .createFromBaseConverterSteps().divide(TYPE_MILE_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_MILE_US_ID) + .setName( TYPE_MILE_US_NAME) + .addTypeFlag( TYPE_MILE_US_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .setWebLinkWiki( TYPE_MILE_US_WIKI) + .createToBaseConverterSteps().multiply(TYPE_MILE_US_FACTOR).build() + .createFromBaseConverterSteps().divide(TYPE_MILE_US_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_MILE_NAUTICAL_ID) + .setName( TYPE_MILE_NAUTICAL_NAME) + .addTypeFlag( TYPE_MILE_NAUTICAL_FLAG) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .setWebLinkWiki( TYPE_MILE_NAUTICAL_WIKI) + .createToBaseConverterSteps().multiply(TYPE_MILE_NAUTICAL_FACTOR).build() + .createFromBaseConverterSteps().divide(TYPE_MILE_NAUTICAL_FACTOR).build() + .build() + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleMole.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleMole.java new file mode 100644 index 00000000..098272b2 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleMole.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module; + +import static net.forwardfire.unitxc.config.UnitXCConfigModule.buildFlag; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 23, 2015 + */ +public class UnitXCModuleMole implements UnitXCConfigModule { + + public static final String GROUP_ID = "mole"; + public static final String GROUP_BASE_TYPE_ID = "mol"; + private static final String[] GROUP_QUANTITIES = {"amount_of_substance"}; + + public static final String TYPE_MOL_ID = GROUP_BASE_TYPE_ID; + public static final String TYPE_MOL_NAME = "mole"; + public static final String TYPE_MOL_FLAG = buildFlag(GROUP_ID,TYPE_MOL_NAME); + private static final String TYPE_MOL_WIKI = "Mole_(unit)"; + + public static final String TYPE_POUND_MOLE_ID = "lbmol";// TODO: add lb-mol + public static final String TYPE_POUND_MOLE_NAME = "pound-mole"; + public static final String TYPE_POUND_MOLE_FLAG = buildFlag(GROUP_ID,TYPE_POUND_MOLE_NAME); + private static final double TYPE_POUND_MOLE_FACTOR = 453.59237; + private static final String TYPE_POUND_MOLE_WIKI = "Mole_(unit)#Other_units_called_.22mole.22"; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupBase(GROUP_ID) + .addQuantityIds( GROUP_QUANTITIES) + .setBaseTypeId( TYPE_MOL_ID) + .createSIUnitTypes() + .setId( TYPE_MOL_ID) + .setName( TYPE_MOL_NAME) + .addTypeFlag( TYPE_MOL_FLAG) + .setWebLinkWiki( TYPE_MOL_WIKI) + .addCommonSIPrefix(UnitXCTypeSIPrefix.MILLI) + .addCommonSIPrefix(UnitXCTypeSIPrefix.MICRO) + .addCommonSIPrefix(UnitXCTypeSIPrefix.NANO) + .addCommonSIPrefix(UnitXCTypeSIPrefix.PICO) + .addCommonSIPrefix(UnitXCTypeSIPrefix.FEMTO) + .build() + .createUnitType() + .setId( TYPE_POUND_MOLE_ID) + .setName( TYPE_POUND_MOLE_NAME) + .addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL) + .setWebLinkWiki( TYPE_POUND_MOLE_WIKI) + .createToBaseConverterSteps().multiply(TYPE_POUND_MOLE_FACTOR).build() + .createFromBaseConverterSteps().divide(TYPE_POUND_MOLE_FACTOR).build() + .build() + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleSecond.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleSecond.java new file mode 100644 index 00000000..32b82886 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleSecond.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module; + +import static net.forwardfire.unitxc.config.UnitXCConfigModule.buildFlag; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 25, 2015 + */ +public class UnitXCModuleSecond implements UnitXCConfigModule { + + public static final String GROUP_ID = "second"; + public static final String GROUP_BASE_TYPE_ID = "s"; + private static final String[] GROUP_QUANTITIES = {"time"}; + + public static final String TYPE_SECOND_ID = GROUP_BASE_TYPE_ID; + public static final String TYPE_SECOND_NAME = "second"; + public static final String TYPE_SECOND_NAMES = TYPE_SECOND_NAME+TYPE_SECOND_ID; + public static final String TYPE_SECOND_FLAG = buildFlag(GROUP_ID,TYPE_SECOND_NAME); + + private static final double TIME_EARTH_MINUTE = 60; + private static final double TIME_EARTH_HOUR = TIME_EARTH_MINUTE*60; + private static final double TIME_EARTH_DAY = TIME_EARTH_HOUR*24; + private static final double TIME_EARTH_WEEK = TIME_EARTH_DAY*7; + private static final double TIME_EARTH_YEAR = 31557600; + // related to the rotating earth, or change to be 794 243 384 928 000 hyperfine oscillations + + public static final String TYPE_MINUTE_ID = "min"; + public static final String TYPE_MINUTE_NAME = "minute"; + public static final String TYPE_MINUTE_FLAG = buildFlag(GROUP_ID,TYPE_MINUTE_NAME); + public static final String TYPE_HOUR_ID = "h"; + public static final String TYPE_HOUR_NAME = "hour"; + public static final String TYPE_HOUR_FLAG = buildFlag(GROUP_ID,TYPE_HOUR_NAME); + public static final String TYPE_DAY_ID = "d"; + public static final String TYPE_DAY_NAME = "day"; + public static final String TYPE_DAY_FLAG = buildFlag(GROUP_ID,TYPE_DAY_NAME); + public static final String TYPE_WEEK_ID = "wk"; + public static final String TYPE_WEEK_NAME = "week"; + public static final String TYPE_WEEK_FLAG = buildFlag(GROUP_ID,TYPE_WEEK_NAME); + public static final String TYPE_YEAR_ID = "yr"; + public static final String TYPE_YEAR_NAME = "year"; + public static final String TYPE_YEAR_FLAG = buildFlag(GROUP_ID,TYPE_YEAR_NAME); + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupBase(GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId( TYPE_SECOND_ID) + .createSIUnitTypes() + .setId( TYPE_SECOND_ID) + .setName( TYPE_SECOND_NAME) + .addTypeFlag( TYPE_SECOND_FLAG) + .addCommonSIPrefix(UnitXCTypeSIPrefix.MILLI) + .addCommonSIPrefix(UnitXCTypeSIPrefix.MICRO) + .addCommonSIPrefix(UnitXCTypeSIPrefix.NANO) + .addCommonSIPrefix(UnitXCTypeSIPrefix.PICO) + .addCommonSIPrefix(UnitXCTypeSIPrefix.FEMTO) + .addCommonSIPrefix(UnitXCTypeSIPrefix.ATTO) + .build() + .createSIUnitTypes() + .setId( TYPE_MINUTE_ID) + .setName( TYPE_MINUTE_NAME) + .addTypeFlag( TYPE_MINUTE_FLAG) + .createToBaseConverterSteps().multiply(TIME_EARTH_MINUTE).build() + .createFromBaseConverterSteps().divide(TIME_EARTH_MINUTE).build() + .build() + .createSIUnitTypes() + .setId( TYPE_HOUR_ID) + .setName( TYPE_HOUR_NAME) + .addTypeFlag( TYPE_HOUR_FLAG) + .createToBaseConverterSteps().multiply(TIME_EARTH_HOUR).build() + .createFromBaseConverterSteps().divide(TIME_EARTH_HOUR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_DAY_ID) + .setName( TYPE_DAY_NAME) + .addTypeFlag( TYPE_DAY_FLAG) + .createToBaseConverterSteps().multiply(TIME_EARTH_DAY).build() + .createFromBaseConverterSteps().divide(TIME_EARTH_DAY).build() + .build() + .createSIUnitTypes() + .setId( TYPE_WEEK_ID) + .setName( TYPE_WEEK_NAME) + .addTypeFlag( TYPE_WEEK_FLAG) + .createToBaseConverterSteps().multiply(TIME_EARTH_WEEK).build() + .createFromBaseConverterSteps().divide(TIME_EARTH_WEEK).build() + .build() + .createSIUnitTypes() + .setId( TYPE_YEAR_ID) + .setName( TYPE_YEAR_NAME) + .addTypeFlag( TYPE_YEAR_FLAG) + .createToBaseConverterSteps().multiply(TIME_EARTH_YEAR).build() + .createFromBaseConverterSteps().divide(TIME_EARTH_YEAR).build() + .build() + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleCubicMetre.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleCubicMetre.java new file mode 100644 index 00000000..e478ae7b --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleCubicMetre.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module.derived; + +import static net.forwardfire.unitxc.config.builder.UnitXCNumberTypeSetting.toSuperScript; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.module.UnitXCModuleMetre; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 28, 2015 + */ +public class UnitXCModuleCubicMetre implements UnitXCConfigModule { + + private static final int UNIT_COMPOUND_EXPONENT = 3; + private static final String UNIT_ID_POSTFIX = toSuperScript(UNIT_COMPOUND_EXPONENT); + private static final String UNIT_NAME_PREFIX = "cubic "; + + public static final String GROUP_ID = "cubic_metre"; + public static final String GROUP_DESCRIPTION = ""; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMetre.GROUP_BASE_TYPE_ID+UNIT_ID_POSTFIX; + private static final String[] GROUP_QUANTITIES = {"volume"}; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupCompoundExponent(GROUP_ID,UnitXCModuleMetre.GROUP_ID, UNIT_COMPOUND_EXPONENT) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId(GROUP_BASE_TYPE_ID) + .setUnitIdPostfix(UNIT_ID_POSTFIX) + .setUnitNamePrefix(UNIT_NAME_PREFIX) + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleCubicMetrePerKilogram.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleCubicMetrePerKilogram.java new file mode 100644 index 00000000..84dc8ad0 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleCubicMetrePerKilogram.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module.derived; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; +import net.forwardfire.unitxc.module.UnitXCModuleKilogram; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 12, 2016 + */ +public class UnitXCModuleCubicMetrePerKilogram implements UnitXCConfigModule { + + public static final String GROUP_ID = "cubic_metre_per_kilogram"; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleCubicMetre.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleKilogram.GROUP_BASE_TYPE_ID; + private static final String[] GROUP_QUANTITIES = {"specific_volume"}; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleCubicMetre.GROUP_ID, UnitXCModuleKilogram.GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId(GROUP_BASE_TYPE_ID) + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleCubicMetrePerMole.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleCubicMetrePerMole.java new file mode 100644 index 00000000..c58b2a49 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleCubicMetrePerMole.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module.derived; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; +import net.forwardfire.unitxc.module.UnitXCModuleMole; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 12, 2016 + */ +public class UnitXCModuleCubicMetrePerMole implements UnitXCConfigModule { + + public static final String GROUP_ID = "cubic_metre_per_mole"; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleCubicMetre.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleMole.GROUP_BASE_TYPE_ID; + private static final String[] GROUP_QUANTITIES = {"molar_volume"}; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleCubicMetre.GROUP_ID, UnitXCModuleMole.GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId(GROUP_BASE_TYPE_ID) + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleCubicMetrePerSecond.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleCubicMetrePerSecond.java new file mode 100644 index 00000000..3b09c173 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleCubicMetrePerSecond.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module.derived; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; +import net.forwardfire.unitxc.module.UnitXCModuleSecond; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 1, 2016 + */ +public class UnitXCModuleCubicMetrePerSecond implements UnitXCConfigModule { + + public static final String GROUP_ID = "cubic_metre_per_second"; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleCubicMetre.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleSecond.GROUP_BASE_TYPE_ID; + private static final String[] GROUP_QUANTITIES = {"volumetric_flow"}; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupCompoundPair(GROUP_ID,UnitXCModuleCubicMetre.GROUP_ID, UnitXCModuleSecond.GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId( GROUP_BASE_TYPE_ID) + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleKilogramPerCubicMetre.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleKilogramPerCubicMetre.java new file mode 100644 index 00000000..173bc3b1 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleKilogramPerCubicMetre.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module.derived; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; +import net.forwardfire.unitxc.module.UnitXCModuleKilogram; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 12, 2016 + */ +public class UnitXCModuleKilogramPerCubicMetre implements UnitXCConfigModule { + + public static final String GROUP_ID = "kilogram_per_cubic_metre"; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleKilogram.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleCubicMetre.GROUP_BASE_TYPE_ID; + private static final String[] GROUP_QUANTITIES = {"density","mass_density"}; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleKilogram.GROUP_ID, UnitXCModuleCubicMetre.GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId(GROUP_BASE_TYPE_ID) + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleKilogramPerSquareMetre.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleKilogramPerSquareMetre.java new file mode 100644 index 00000000..7361e1f8 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleKilogramPerSquareMetre.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module.derived; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; +import net.forwardfire.unitxc.module.UnitXCModuleKilogram; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 12, 2016 + */ +public class UnitXCModuleKilogramPerSquareMetre implements UnitXCConfigModule { + + public static final String GROUP_ID = "kilogram_per_square_metre"; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleKilogram.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleSquareMetre.GROUP_BASE_TYPE_ID; + private static final String[] GROUP_QUANTITIES = {"area_density"}; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleKilogram.GROUP_ID, UnitXCModuleSquareMetre.GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId( GROUP_BASE_TYPE_ID) + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMetrePerQuarticSecond.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMetrePerQuarticSecond.java new file mode 100644 index 00000000..f649f861 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMetrePerQuarticSecond.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module.derived; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; +import net.forwardfire.unitxc.module.UnitXCModuleSecond; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 1, 2016 + */ +public class UnitXCModuleMetrePerQuarticSecond implements UnitXCConfigModule { + + public static final String GROUP_ID = "metre_per_quartic_second"; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMetrePerSecondCubed.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleSecond.GROUP_BASE_TYPE_ID; + private static final String[] GROUP_QUANTITIES = {"snap","jounce"}; + + // TODO: add aliases + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleMetrePerSecondCubed.GROUP_ID, UnitXCModuleSecond.GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId(GROUP_BASE_TYPE_ID) + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMetrePerSecond.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMetrePerSecond.java new file mode 100644 index 00000000..dd890934 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMetrePerSecond.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module.derived; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; +import net.forwardfire.unitxc.model.UnitXCModule; +import net.forwardfire.unitxc.module.UnitXCModuleMetre; +import net.forwardfire.unitxc.module.UnitXCModuleSecond; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Nov 3, 2015 + */ +@UnitXCModule(groupId=UnitXCModuleMetrePerSecond.GROUP_ID,dependencies={UnitXCModuleMetre.GROUP_ID, UnitXCModuleSecond.GROUP_ID}) +public class UnitXCModuleMetrePerSecond implements UnitXCConfigModule { + + public static final String GROUP_ID = "metre_per_second"; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMetre.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleSecond.GROUP_BASE_TYPE_ID; + private static final String[] GROUP_QUANTITIES = {"speed","velocity"}; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupCompoundPair(GROUP_ID,UnitXCModuleMetre.GROUP_ID, UnitXCModuleSecond.GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId(GROUP_BASE_TYPE_ID) + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMetrePerSecondCubed.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMetrePerSecondCubed.java new file mode 100644 index 00000000..aeb3f32f --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMetrePerSecondCubed.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module.derived; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; +import net.forwardfire.unitxc.module.UnitXCModuleSecond; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 1, 2016 + */ +public class UnitXCModuleMetrePerSecondCubed implements UnitXCConfigModule { + + public static final String GROUP_ID = "metre_per_second_cubed"; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMetrePerSecondSquared.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleSecond.GROUP_BASE_TYPE_ID; + private static final String[] GROUP_QUANTITIES = {"jerk","jolt","surge","lurch"}; + + // TODO: add aliases + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleMetrePerSecondSquared.GROUP_ID, UnitXCModuleSecond.GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId( GROUP_BASE_TYPE_ID) + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMetrePerSecondSquared.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMetrePerSecondSquared.java new file mode 100644 index 00000000..31c5b648 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMetrePerSecondSquared.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module.derived; + +import static net.forwardfire.unitxc.config.builder.UnitXCNumberTypeSetting.toSuperScript; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; +import net.forwardfire.unitxc.module.UnitXCModuleSecond; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 1, 2016 + */ +public class UnitXCModuleMetrePerSecondSquared implements UnitXCConfigModule { + + private static final int UNIT_COMPOUND_EXPONENT = 2; + private static final String UNIT_ID_POSTFIX = toSuperScript(UNIT_COMPOUND_EXPONENT); + + public static final String GROUP_ID = "metre_per_second_squared"; + public static final String GROUP_BASE_TYPE_ID = "m"+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleSecond.GROUP_BASE_TYPE_ID+UNIT_ID_POSTFIX; //UnitXCModuleSpeed.GROUP_BASE_TYPE_ID; + private static final String[] GROUP_QUANTITIES = {"acceleration"}; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupCompoundPair(GROUP_ID,UnitXCModuleMetrePerSecond.GROUP_ID, UnitXCModuleSecond.GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId(GROUP_BASE_TYPE_ID) + .createUnitType() + .setAliasOfType("m/s/s") + .setId(GROUP_BASE_TYPE_ID) + .setName("Meter per second squared") + .build() + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMolePerCubicMetre.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMolePerCubicMetre.java new file mode 100644 index 00000000..ae711690 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMolePerCubicMetre.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module.derived; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; +import net.forwardfire.unitxc.module.UnitXCModuleMole; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 12, 2016 + */ +public class UnitXCModuleMolePerCubicMetre implements UnitXCConfigModule { + + public static final String GROUP_ID = "mole_per_cubic_metre"; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMole.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleCubicMetre.GROUP_BASE_TYPE_ID; + private static final String[] GROUP_QUANTITIES = {"molarity"}; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleMole.GROUP_ID, UnitXCModuleCubicMetre.GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId(GROUP_BASE_TYPE_ID) + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleNewtonPerSecond.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleNewtonPerSecond.java new file mode 100644 index 00000000..a6fb9764 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleNewtonPerSecond.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module.derived; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.module.UnitXCModuleSecond; +import net.forwardfire.unitxc.module.named.UnitXCModuleNewton; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 31, 2016 + */ +public class UnitXCModuleNewtonPerSecond implements UnitXCConfigModule { + + public static final String GROUP_ID = "newton_per_second"; + public static final String GROUP_BASE_TYPE_ID = "kg/m/s/s/s"; //FIXME: UnitXCModuleNewton.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID; + private static final String[] GROUP_QUANTITIES = {"yank"}; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleNewton.GROUP_ID, UnitXCModuleSecond.GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId( GROUP_BASE_TYPE_ID) + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleSquareMetre.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleSquareMetre.java new file mode 100644 index 00000000..fc39d10c --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleSquareMetre.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module.derived; + +import static net.forwardfire.unitxc.config.builder.UnitXCNumberTypeSetting.toSuperScript; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.module.UnitXCModuleMetre; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 26, 2015 + */ +public class UnitXCModuleSquareMetre implements UnitXCConfigModule { + + private static final int UNIT_COMPOUND_EXPONENT = 2; + private static final String UNIT_ID_POSTFIX = toSuperScript(UNIT_COMPOUND_EXPONENT); + private static final String UNIT_NAME_PREFIX = "square "; + + public static final String GROUP_ID = "square_metre"; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMetre.GROUP_BASE_TYPE_ID+UNIT_ID_POSTFIX; + private static final String[] GROUP_QUANTITIES = {"area"}; + + public static final String TYPE_CENTIARE_ALIAS = "m²"; + public static final String TYPE_CENTIARE_ID = "ca"; + public static final String TYPE_CENTIARE_NAME = "centiare"; + public static final String TYPE_CENTIARE_URL = "https://en.wikipedia.org/wiki/Hectare#Centiare"; + + public static final String TYPE_ARE_ALIAS = "dam²"; + public static final String TYPE_ARE_ID = "a"; + public static final String TYPE_ARE_NAME = "are"; + public static final String TYPE_ARE_URL = "https://en.wikipedia.org/wiki/Hectare#Are"; + + public static final String TYPE_HECTARE_ALIAS = "hm²"; + public static final String TYPE_HECTARE_ID = "ha"; + public static final String TYPE_HECTARE_NAME = "hectare"; + public static final String TYPE_HECTARE_URL = "https://en.wikipedia.org/wiki/Hectare"; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupCompoundExponent(GROUP_ID, UnitXCModuleMetre.GROUP_ID, UNIT_COMPOUND_EXPONENT) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId( GROUP_BASE_TYPE_ID) + .setUnitIdPostfix(UNIT_ID_POSTFIX) + .setUnitNamePrefix(UNIT_NAME_PREFIX) + .createUnitType() + .setAliasOfType( TYPE_CENTIARE_ALIAS) + .setId( TYPE_CENTIARE_ID) + .setName( TYPE_CENTIARE_NAME) + .setWebLink( TYPE_CENTIARE_URL) + .build() + .createUnitType() + .setAliasOfType( TYPE_ARE_ALIAS) + .setId( TYPE_ARE_ID) + .setName( TYPE_ARE_NAME) + .setWebLink( TYPE_ARE_URL) + .build() + .createUnitType() + .setAliasOfType( TYPE_HECTARE_ALIAS) + .setId( TYPE_HECTARE_ID) + .setName( TYPE_HECTARE_NAME) + .setWebLink( TYPE_HECTARE_URL) + .build() + .build() + ; + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/package-info.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/package-info.java new file mode 100644 index 00000000..424063a7 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/derived/package-info.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/** + * @author willemc + * + */ +package net.forwardfire.unitxc.module.derived; \ No newline at end of file diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/named/UnitXCModuleNewton.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/named/UnitXCModuleNewton.java new file mode 100644 index 00000000..f645d8c5 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/named/UnitXCModuleNewton.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module.named; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; +import net.forwardfire.unitxc.module.UnitXCModuleKilogram; +import net.forwardfire.unitxc.module.derived.UnitXCModuleMetrePerSecondSquared; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 12, 2016 + */ +public class UnitXCModuleNewton implements UnitXCConfigModule { + + public static final String GROUP_ID = "newton"; + public static final String GROUP_BASE_TYPE_ID = "N"; + private static final String GROUP_BASE_TYPE_ID_ALIAS = "kg"+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleMetrePerSecondSquared.GROUP_BASE_TYPE_ID; + private static final String[] GROUP_QUANTITIES = {"force","weight"}; + + // TODO: symbol N + fix builder + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleKilogram.GROUP_ID, UnitXCModuleMetrePerSecondSquared.GROUP_ID) + .addQuantityIds(GROUP_QUANTITIES) + .setBaseTypeId(GROUP_BASE_TYPE_ID) + .createUnitType() + .setId(GROUP_BASE_TYPE_ID) + .setName(GROUP_ID) + .setAliasOfType(GROUP_BASE_TYPE_ID_ALIAS) + .build() + .build(); + } +} diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/named/package-info.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/named/package-info.java new file mode 100644 index 00000000..b6a07853 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/named/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author willemc + * + */ +package net.forwardfire.unitxc.module.named; \ No newline at end of file diff --git a/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/package-info.java b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/package-info.java new file mode 100644 index 00000000..f4ea756f --- /dev/null +++ b/gdxapp4d-unitxc/src/main/java/net/forwardfire/unitxc/module/package-info.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/** + * @author willemc + * + */ +package net.forwardfire.unitxc.module; \ No newline at end of file diff --git a/gdxapp4d-unitxc/src/main/resources/net/forwardfire/unitxc/UnitXCBundle.properties b/gdxapp4d-unitxc/src/main/resources/net/forwardfire/unitxc/UnitXCBundle.properties new file mode 100644 index 00000000..ffe1ead0 --- /dev/null +++ b/gdxapp4d-unitxc/src/main/resources/net/forwardfire/unitxc/UnitXCBundle.properties @@ -0,0 +1,122 @@ + + +group.mole.name = mole +group.mole.description = The mole is the amount of substance of a system which contains as many elementary entities as there are atoms in 0.012 kilogram of carbon 12. +group.mole.quantity.amount_of_substance.name = amount of substance +group.mole.quantity.amount_of_substance.wikiLink = Amount_of_substance + +group.second.name = second +group.second.description = The second is the duration of 9192631770 periods of the radiation corresponding to the transition between the two hyperfine levels of the ground state of the caesium 133 atom. +group.second.quantity.time.name = time +group.second.quantity.time.wikiLink = Time + +group.kelvin.name = kelvin +group.kelvin.description = The kelvin, unit of thermodynamic temperature, is the fraction 1/273.16 of the thermodynamic temperature of the triple point of water. +group.kelvin.quantity.thermodynamic_temperature.name = thermodynamic temperature +group.kelvin.quantity.thermodynamic_temperature.wikiLink = Thermodynamic_temperature + +group.candela.name = candela +group.candela.description = The candela is the luminous intensity, in a given direction, of a source that emits monochromatic radiation of frequency 5401012 hertz and that has a radiant intensity in that direction of 1/683 watt per steradian. +group.candela.quantity.luminous_intensity.name = luminous intensity +group.candela.quantity.luminous_intensity.wikiLink = Luminous_intensity + +group.ampere.name = ampere +group.ampere.description = The ampere is a measure of the amount of electric charge passing a point in an electric circuit per unit time, with 6.2411018 electrons (or one coulomb) per second constituting one ampere. +group.ampere.quantity.electric_current.name = electric current +group.ampere.quantity.electric_current.wikiLink = Electric_current + +group.kilogram.name = kilogram +group.kilogram.description = The kilogram is the unit of mass; it is equal to the mass of the international prototype of the kilogram. +group.kilogram.quantity.mass.name = mass +group.kilogram.quantity.mass.wikiLink = Mass + +group.metre.name = metre +group.metre.description = The metre is the length of the path travelled by light in vacuum during a time interval of 1/299792458 of a second. +group.metre.quantity.length.name = length +group.metre.quantity.length.wikiLink = Length + + + +group.metre_per_second.name = metre per second +group.metre_per_second.description = Speed is the dimensions of a length divided by a time. +group.metre_per_second.quantity.speed.name = speed +group.metre_per_second.quantity.speed.wikiLink = Speed +group.metre_per_second.quantity.velocity.name = velocity +group.metre_per_second.quantity.velocity.wikiLink = Velocity + + +group.cubic_metre.name = cubic metre +group.cubic_metre.description = It is the volume of a cube with edges one metre in length. +group.cubic_metre.quantity.volume.name = volume +group.cubic_metre.quantity.volume.wikiLink = Volume + +group.cubic_metre_per_second.name = cubic metre per second +group.cubic_metre_per_second.description = Volumetric flow is the volume of fluid which passes per unit time. +group.cubic_metre_per_second.quantity.volumetric_flow.name = volumetric flow +group.cubic_metre_per_second.quantity.volumetric_flow.wikiLink = Volumetric_flow + +group.metre_per_second_squared.name = metre per second squared +group.metre_per_second_squared.description = Acceleration, is the rate of change of velocity of an object with respect to time. +group.metre_per_second_squared.acceleration.volumetric_flow.name = acceleration +group.metre_per_second_squared.acceleration.volumetric_flow.wikiLink = Acceleration + +group.metre_per_second_cubed.name = metre per second cubed +group.metre_per_second_cubed.description = Jerk, also known as jolt, surge, or lurch, is the rate of change of acceleration, with respect to time. +group.metre_per_second_cubed.quantity.jerk.name = jerk +group.metre_per_second_cubed.quantity.jerk.wikiLink = Jerk_(physics) +group.metre_per_second_cubed.quantity.jolt.name = jolt +group.metre_per_second_cubed.quantity.surge.name = surge +group.metre_per_second_cubed.quantity.lurch.name = lurch + +group.metre_per_quartic_second.name = metre per quartic second +group.metre_per_quartic_second.description = Is the fourth derivative of the position vector with respect to time or the rate of change of the jerk with respect to time. +group.metre_per_quartic_second.quantity.jounce.name = jounce +group.metre_per_quartic_second.quantity.jounce.wikiLink = Jounce +group.metre_per_quartic_second.quantity.snap.name = snap + +group.kilogram_per_square_metre.name = kilogram per square metre +group.kilogram_per_square_metre.description = Area density is of a two-dimensional object is calculated as the mass per unit area. +group.kilogram_per_square_metre.quantity.area_density.name = area_density +group.kilogram_per_square_metre.quantity.area_density.wikiLink = Area_density + +group.kilogram_per_cubic_metre.name = kilogram per cubic metre +group.kilogram_per_cubic_metre.description = The volumetric mass density, of a substance is its mass per unit volume. +group.kilogram_per_cubic_metre.quantity.density.name = density +group.kilogram_per_cubic_metre.quantity.density.wikiLink = Density +group.kilogram_per_cubic_metre.quantity.mass_density.name = mass_density + +group.mole_per_cubic_metre.name = mole per cubic metre +group.mole_per_cubic_metre.description = Molar concentration is a measure of the concentration of a solute in a solution. +group.mole_per_cubic_metre.quantity.molarity.name = molarity +group.mole_per_cubic_metre.quantity.molarity.wikiLink = Molarity + +group.cubic_metre_per_mole.name = cubic metre per mole +group.cubic_metre_per_mole.description = Molar volume is the volume occupied by one mole of a substance. +group.cubic_metre_per_mole.quantity.molar_volume.name = molar volume +group.cubic_metre_per_mole.quantity.molar_volume.wikiLink = Molar_volume + +group.newton_per_second.name = newton per second +group.newton_per_second.description = Newton per second. +group.newton_per_second.quantity.yank.name = yank + +group.cubic_metre_per_kilogram.name = cubic metre per kilogram +group.cubic_metre_per_kilogram.description = In thermodynamics, the specific volume of a substance is the ratio of the substance's volume to its mass. +group.cubic_metre_per_kilogram.quantity.specific_volume.name = specific volume +group.cubic_metre_per_kilogram.quantity.specific_volume.wikiLink = Specific_volume + +group.square_metre.name = square metre +group.square_metre.description = It is defined as the area of a square whose sides measure exactly one metre. The square metre is derived from the SI base unit of the metre, +group.square_metre.quantity.area.name = area +group.square_metre.quantity.area.wikiLink = Area + +group.newton.name = newton +group.newton.description = One newton is the force needed to accelerate one kilogram of mass at the rate of one metre per second squared in direction of the applied force. +group.newton.quantity.force.name = force +group.newton.quantity.force.wikiLink = Force +group.newton.quantity.weight.name = weigth +group.newton.quantity.weight.wikiLink = Weight + + +# type.mol.wikiLink = ${general.wiki.base.url}/Mole_(unit) +# type.mol.name = Mole + diff --git a/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/UnitXCAssert.java b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/UnitXCAssert.java new file mode 100644 index 00000000..49b8654e --- /dev/null +++ b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/UnitXCAssert.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc; + +import org.junit.jupiter.api.Assertions; + +import net.forwardfire.unitxc.converter.UnitXConverter; + +public class UnitXCAssert { + + private static final UnitXConverter DEFAULT_CONVERTER = UnitXCFactory.createManager().getConverter(); + private static final double DEFAULT_VALUE_DELTA = 0; + + public static void convertEquals(double expected,String toType,double fromValue,String fromType) { + convertEquals(DEFAULT_CONVERTER,expected, toType, fromValue, fromType); + } + + public static void convertEquals(UnitXConverter converter,double expected,String toType,double fromValue,String fromType) { + convertEquals(converter, expected, toType, fromValue, fromType, DEFAULT_VALUE_DELTA); + } + + public static void convertEquals(UnitXConverter converter,double expected,String toType,double fromValue,String fromType,double valueDelta) { + Assertions.assertNotNull(converter); + Assertions.assertEquals(expected,converter.convert(fromValue, fromType, toType),valueDelta); + } +} diff --git a/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/UnitXCConverterStepTest.java b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/UnitXCConverterStepTest.java new file mode 100644 index 00000000..3d5e9861 --- /dev/null +++ b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/UnitXCConverterStepTest.java @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc; + +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import net.forwardfire.unitxc.converter.UnitXConverterParameterValue; +import net.forwardfire.unitxc.model.UnitXCType; +import net.forwardfire.unitxc.model.UnitXCGroup; +import net.forwardfire.unitxc.model.UnitXCGroupJump; +import net.forwardfire.unitxc.model.UnitXCGroupJumpParameter; +import net.forwardfire.unitxc.model.UnitXCGroupQuantity; +import net.forwardfire.unitxc.model.UnitXConverterResult; +import net.forwardfire.unitxc.model.step.RuleStepCodePrinter; +import net.forwardfire.unitxc.model.step.RuleStepCodeStyle; +import net.forwardfire.unitxc.model.step.UnitXConverterStep; + +public class UnitXCConverterStepTest { + + @Test + public void testFac() throws Exception { + UnitXCManager unitManager = UnitXCFactory.createManager(); + + Assertions.assertNotNull(unitManager); + Assertions.assertNotNull(unitManager.getConfig()); + Assertions.assertNotNull(unitManager.getConfig().getUnitGroups()); + Assertions.assertFalse(unitManager.getConfig().getUnitGroups().isEmpty()); + + long ts = 0l; + for (UnitXCGroup typeGroup:unitManager.getConfig().getUnitGroups()) { + UnitXCType type = unitManager.getUnitType(typeGroup.getBaseTypeId()); + if (type == null) { + throw new IllegalStateException("No base type for: "+typeGroup.getId()+" needs: "+typeGroup.getBaseTypeId()); + } + long tc = typeGroup.getUnitTypeSize(); + ts += tc; + String groupLine = String.format("%-40s %-20d %-10s", typeGroup.getName().getValue(""),tc,type.getId()); + System.out.println(groupLine); + } + System.out.println("\ntotalTypes: "+ts); + System.out.println(""); + + Set paraSet = new HashSet<>(); + for (UnitXCGroup typeGroup:unitManager.getConfig().getUnitGroups()) { + for (UnitXCGroupJump jumpGroup:typeGroup.getGroupJumps()) { + for (UnitXCGroupJumpParameter jumpPara:jumpGroup.getJumpParameters()) { + System.out.println("jumpPara: "+jumpPara.getId()+" as: "+jumpPara.getUnitGroupId()); + if (paraSet.contains(jumpPara.getId())) { + //throw new IllegalStateException("duplicate jump parameter id found: "+jumpPara.getId()); + } + paraSet.add(jumpPara.getId()); + } + } + } + System.out.println("\ntotalTypes: "+ts); + System.out.println(""); + + UnitXConverterResult result2 = unitManager.getConverter().convertStepped(20.0, "m/s/s", "km/s/s"); + System.out.println("20m/s = "+result2.getResultValue()+" km/h"); + + UnitXConverterResult result = unitManager.getConverter().convertStepped(211.0, "k°F", "m°C"); + System.out.println("result: "+result); + + //result = unitManager.getConverter().convertStepped(10.763, "ft²", "in²"); + //xmlDriver.marshal(result, System.out); + //System.out.println(""); + + //result = unitManager.getConverter().convertStepped(10.763, "ft³", "in³"); + //xmlDriver.marshal(result, System.out); + + + //result = unitManager.getConverter().convertStepped(1079000000, "km/h", "m/s"); + //xmlDriver.marshal(result, System.out); + + + //try (OutputStream out = new FileOutputStream("/tmp/unitxc.conf.xml")) { + // jaxbDriver.getUnitXCConfig().marshal(unitManager.getConfig(), out); + //} + + //System.out.println("GROUP:"); + //jaxbDriver.getUnitXCGroup().marshal(unitManager.getUnitGroup("length"), System.out); + + Map para = new HashMap<>(); + para.put("metre_per_second_second", new UnitXConverterParameterValue(2, unitManager.getUnitType("minute"))); + result = unitManager.getConverter().convertStepped(50, "km/h", "mm",para); + //System.out.println("CONVERT-RESULT: "+result); + + long totalUnits=0; + StringBuilder buf = new StringBuilder(); + buf.append("digraph G {\n"); + + //buf.append("\tsize = \"4,4\"\n"); + for (UnitXCGroup typeGroup:unitManager.getConfig().getUnitGroups()) { + UnitXCType baseType = unitManager.getUnitType(typeGroup.getBaseTypeId()); + System.out.println("group: "+typeGroup.getId()); + + // print info + buf.append("\t"+typeGroup.getId()); + buf.append("["); + if (typeGroup.getDerivedFrom().isEmpty()) { + buf.append("shape=box,style=filled,color=\".9 0.5 0.9\","); + } + StringBuilder label = new StringBuilder(); + label.append("label=\""); + label.append(typeGroup.getId()+"\\n"); + label.append(baseType.getId()+"\\n"); + label.append(baseType.getName()+"\\n"); + Iterator q = typeGroup.getQuantities().iterator(); + label.append("("); + while (q.hasNext()) { + UnitXCGroupQuantity gq = q.next(); + label.append(gq.getId()); + //label.append(gq.getName()); + if (q.hasNext()) { + label.append(","); + } + } + label.append(")"); + label.append("\""); + + buf.append(label+",labelloc=b"); + buf.append("];\n"); + + // print unit per group + buf.append("\t"+typeGroup.getId()+" -> "+typeGroup.getId()); + buf.append("["); + buf.append("color=red,label=\""+typeGroup.getUnitTypeSize()+"\""); + buf.append("];\n"); + + totalUnits += typeGroup.getUnitTypeSize(); + + // print relations + for (String groupFrom:typeGroup.getDerivedFrom()) { + buf.append("\t"+groupFrom+" -> "+typeGroup.getId()); + buf.append("["); + buf.append("dir=none"); + buf.append("];\n"); + } + + //for (UnitXCGroupJump jumpGroup:typeGroup.getGroupJumps()) { + // System.out.println("jumpGruop: "+jumpGroup.getId()+" to: "+jumpGroup.getUnitGroupId()); + // buf.append("\t"+typeGroup.getId()+" -> "+jumpGroup.getUnitGroupId()); + // buf.append("["); + // buf.append("];\n"); +// buf.append("\t"+typeGroup.getId()+" -> "+jumpGroup.getId()); +// buf.append(";\n"); +// +// buf.append("\t"+jumpGroup.getId()+" -> "+jumpGroup.getUnitGroupId()); +// buf.append(";\n"); + + //for (UnitXCGroupJumpParameter jumpPara:jumpGroup.getJumpParameters()) { + + //buf.append("\t"+jumpPara.getUnitGroupId()+"_"+(x++)+" -> "+jumpGroup.getId()); + //buf.append(";\n"); + + //buf.append("\t"+typeGroup.getId()+" -> "+jumpPara.getId()); + //buf.append(";\n"); + + //buf.append("\t"+jumpPara.getId()+" -> "+jumpGroup.getUnitGroupId()); + //buf.append(";\n"); + //} + //} + } + + buf.append("Stats[shape=box,color=\".9 0.2 0.8\",label=\"unit groups: "+unitManager.getConfig().getUnitGroups().size()+"\\ntotal units: "+totalUnits+"\",labelloc=b];\n"); + + buf.append("}\n"); + System.out.println("dot: \n"+buf.toString()); + Files.write(Paths.get("target/groups.dot"), buf.toString().getBytes(Charset.forName("UTF-8"))); + + List steps = new ArrayList<>(); + result.getResultSteps().forEach(v -> steps.add(v.getConvertStep())); + + String code = RuleStepCodePrinter.print(RuleStepCodeStyle.JAVASCRIPT, steps, result.getStartTypeId()+"_to_"+result.getResultTypeId()); + System.out.println("\n\ncode: \n"+code); + } +} diff --git a/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/UnitXCFactoryTest.java b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/UnitXCFactoryTest.java new file mode 100644 index 00000000..e85f4197 --- /dev/null +++ b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/UnitXCFactoryTest.java @@ -0,0 +1,45 @@ +package net.forwardfire.unitxc; + +import net.forwardfire.unitxc.model.UnitXCConfig; + +import java.util.ArrayList; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class UnitXCFactoryTest { + + @Test + public void testCreateConfig() { + Assertions.assertNotNull(UnitXCFactory.createConfig()); + } + + @Test + public void testCreateConfigList() { + Assertions.assertNotNull(UnitXCFactory.createConfig(new ArrayList<>())); + } + + @Test + public void testCreateConfigListNull() { + Assertions.assertThrows(NullPointerException.class, () -> { + Assertions.assertNotNull(UnitXCFactory.createConfig(null)); + }); + } + + @Test + public void testCreateManager() { + Assertions.assertNotNull(UnitXCFactory.createManager()); + } + + @Test + public void testCreateManagerConfig() { + Assertions.assertNotNull(UnitXCFactory.createManager(new UnitXCConfig())); + } + + @Test + public void testCreateManagerConfigNull() { + Assertions.assertThrows(NullPointerException.class, () -> { + Assertions.assertNotNull(UnitXCFactory.createManager(null)); + }); + } +} diff --git a/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/UnitXCManagerTest.java b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/UnitXCManagerTest.java new file mode 100644 index 00000000..f6e4e606 --- /dev/null +++ b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/UnitXCManagerTest.java @@ -0,0 +1,128 @@ +package net.forwardfire.unitxc; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import net.forwardfire.unitxc.module.UnitXCModuleKelvin; + +public class UnitXCManagerTest { + + private UnitXCManager test = UnitXCFactory.createManager(); + + @Test + public void testGetConverter() { + Assertions.assertNotNull(test.getConverter()); + } + + @Test + public void testGetUnitType() { + Assertions.assertNotNull(test.getUnitType(UnitXCModuleKelvin.TYPE_KELVIN_ID)); + } + + @Test + public void testGetUnitTypeNull() { + Assertions.assertThrows(NullPointerException.class, () -> { + Assertions.assertNotNull(test.getUnitType(null)); + }); + } + + @Test + public void testGetUnitTypeInvalid() { + Assertions.assertNull(test.getUnitType(getClass().getName())); + } + + @Test + public void testGetUnitTypeResultId() { + Assertions.assertNotNull(test.getUnitType(UnitXCModuleKelvin.TYPE_KELVIN_ID).getId()); + } + + @Test + public void testGetUnitTypeResultName() { + Assertions.assertNotNull(test.getUnitType(UnitXCModuleKelvin.TYPE_KELVIN_ID).getName()); + } + + @Test + public void testGetUnitTypeResultTypeFlags() { + Assertions.assertNotNull(test.getUnitType(UnitXCModuleKelvin.TYPE_KELVIN_ID).getTypeFlags()); + } + + @Test + public void testGetUnitTypeGroup() { + Assertions.assertNotNull(test.getUnitGroup(UnitXCModuleKelvin.GROUP_ID)); + } + + @Test + public void testGetUnitTypeGroupNull() { + Assertions.assertThrows(NullPointerException.class, () -> { + Assertions.assertNotNull(test.getUnitGroup(null)); + }); + } + + @Test + public void testGetUnitTypeGroupInvalid() { + Assertions.assertThrows(NullPointerException.class, () -> { + Assertions.assertNotNull(test.getUnitGroup(getClass().getName())); + }); + } + + @Test + public void testGetUnitTypeGroupResultId() { + Assertions.assertNotNull(test.getUnitGroup(UnitXCModuleKelvin.GROUP_ID).getId()); + } + + @Test + public void testGetUnitTypeGroupResultDescription() { + Assertions.assertNotNull(test.getUnitGroup(UnitXCModuleKelvin.GROUP_ID).getDescription()); + } + + @Test + public void testGetUnitTypeResultTypeBaseTypeID() { + Assertions.assertNotNull(test.getUnitGroup(UnitXCModuleKelvin.GROUP_ID).getBaseTypeId()); + } + + @Test + public void testIsUnitTypeGroupTrue() { + Assertions.assertTrue(test.isUnitGroup(UnitXCModuleKelvin.GROUP_ID)); + } + + @Test + public void testIsUnitTypeGroupFalse() { + Assertions.assertFalse(test.isUnitGroup(getClass().getName())); + } + + @Test + public void testIsUnitTypeGroupNull() { + Assertions.assertThrows(NullPointerException.class, () -> { + Assertions.assertTrue(test.isUnitGroup(null)); + }); + } + + @Test + public void testIsUnitTypeGroupEmpty() { + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Assertions.assertTrue(test.isUnitGroup("")); + }); + } + +// @Test +// public void testIsUnitTypeTrue() { +// assertTrue(test.isUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID)); +// } +// +// @Test +// public void testIsUnitTypeFalse() { +// assertFalse(test.isUnitType(getClass().getName())); +// } +// +// @Test(expected=NullPointerException.class) +// public void testIsUnitTypeNull() { +// assertTrue(test.isUnitType(null)); +// } + + @Test + public void testIsUnitTypeEmpty() { + Assertions.assertThrows(IllegalArgumentException.class, () -> { + Assertions.assertTrue(test.isUnitGroup("")); + }); + } +} diff --git a/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/module/UnitXCModuleAreaTest.java b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/module/UnitXCModuleAreaTest.java new file mode 100644 index 00000000..93deb20e --- /dev/null +++ b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/module/UnitXCModuleAreaTest.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module; + +import static net.forwardfire.unitxc.UnitXCAssert.convertEquals; + +import org.junit.jupiter.api.Test; + +public class UnitXCModuleAreaTest { + + @Test + public void test1ToSquareKilometre() throws Exception { + convertEquals(0.000001,"km²",1.0, "m²"); + } + + @Test + public void test1ToSquareCentimetre() throws Exception { + convertEquals(10000,"cm²",1.0, "m²"); + } + + @Test + public void test1ToHectares() throws Exception { + convertEquals(0.0001,"ha",1.0, "m²"); + } + /* + @Test + public void test1ToDecares() throws Exception { + convertEquals(0.001,"daa",1.0, "m²"); + } + */ + @Test + public void test1ToAres() throws Exception { + convertEquals(0.01,"a",1.0, "m²"); + } + /* + @Test + public void test1ToDeciares() throws Exception { + convertEquals(0.1,"da",1.0, "m²"); + } + */ + @Test + public void test1ToCentiare() throws Exception { + convertEquals(1.0,"ca",1.0, "m²"); + } + /* + @Test + public void test1ToAcres() throws Exception { + convertEquals(0.000247105381,"acres",1.0, "m²"); + } + + @Test + public void test1ToCents() throws Exception { + convertEquals(0.024710538 ,"cents",1.0, "m²"); + } + + @Test + public void test1ToSquareYard() throws Exception { + convertEquals(1.195990 ,"yd²",1.0, "m²"); + } + + @Test + public void test1ToSquareFeet() throws Exception { + convertEquals(10.763911 ,"ft²",1.0, "m²"); + } + + @Test + public void test1ToSquareInch() throws Exception { + convertEquals(1550.0031 ,"in²",1.0, "m²"); + } + */ +} diff --git a/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/module/UnitXCModuleLengthTest.java b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/module/UnitXCModuleLengthTest.java new file mode 100644 index 00000000..9b532ece --- /dev/null +++ b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/module/UnitXCModuleLengthTest.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module; + +import static net.forwardfire.unitxc.UnitXCAssert.convertEquals; + +import org.junit.jupiter.api.Test; + +public class UnitXCModuleLengthTest { + + @Test + public void test10cm2mm() { + convertEquals(100.0,"mm",10.0, "cm"); + } + + @Test + public void test2mm2cm() { + convertEquals(1.0,"cm",10.0,"mm"); + } + + @Test + public void test004567km2cm() { + convertEquals(4567,"cm",0.04567,"km"); + } + + @Test + public void test2cm2mm() { + convertEquals(232.0,"mm",23.2, "cm"); + } + + @Test + public void test2345mm2cm() { + convertEquals(234.56,"cm",2345.6, "mm"); + } + + @Test + public void test1in2mm() { + convertEquals(25.4,"mm",1.0, "in"); + } + + @Test + public void test25mm2in() { + convertEquals(1.0,"in",25.4,"mm"); + } + + @Test + public void test2ft2mm() { + convertEquals(304.8*2,"mm",2.0,"ft"); + } + + @Test + public void test2ft2m() { + convertEquals(0.6096,"m",2.0, "ft"); + } + + @Test + public void test06m2in() { + convertEquals(24.0,"in",0.6096, "m"); + } + + @Test + public void test2ft2in() { + convertEquals(24.0,"in",2.0, "ft"); + } + + @Test + public void test2ft2cm() { + convertEquals(73.152,"cm",2.4, "ft"); + } + + @Test + public void test24ft2m() { + convertEquals(7.315,"m",24, "ft"); + } +} diff --git a/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/module/UnitXCModuleTemperatureTest.java b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/module/UnitXCModuleTemperatureTest.java new file mode 100644 index 00000000..4f9492df --- /dev/null +++ b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/module/UnitXCModuleTemperatureTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module; + +import static net.forwardfire.unitxc.UnitXCAssert.convertEquals; + +import org.junit.jupiter.api.Test; + +public class UnitXCModuleTemperatureTest { + + @Test + public void test300K2C() throws Exception { + convertEquals(26.85,"°C",300.0, "K"); + } + + @Test + public void test37C2K() throws Exception { + convertEquals(310.65,"K",37.5, "°C"); + } + + @Test + public void test300K2F() throws Exception { + convertEquals(80.32,"°F",300.0, "K"); + } + + @Test + public void test37C2F() throws Exception { + convertEquals(276.0,"K",37.5, "°F"); + } + + @Test + public void test37F2K() throws Exception { + convertEquals(276.2,"K",37.505, "°F"); + } + + @Test + public void test166F2C() throws Exception { + convertEquals(74.937,"°C",166.888, "°F"); + } + + @Test + public void test100C2F() throws Exception { + convertEquals(211.9,"°F",100.0, "°C"); + } + + @Test + public void test233R2C() throws Exception { + convertEquals(-143.64,"°C",233.12,"°R"); + } + + @Test + public void test666C2R() throws Exception { + convertEquals(1691.06,"°R",666.333,"°C"); + } +} diff --git a/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/module/UnitXCModuleTimeTest.java b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/module/UnitXCModuleTimeTest.java new file mode 100644 index 00000000..385e2cb2 --- /dev/null +++ b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/module/UnitXCModuleTimeTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module; + +import static net.forwardfire.unitxc.UnitXCAssert.convertEquals; + +import org.junit.jupiter.api.Test; + +public class UnitXCModuleTimeTest { + + @Test + public void test30SecondToMinute() throws Exception { + convertEquals(0.5,"minute",30.0, "s"); + } + + @Test + public void test300SecondToMinute() throws Exception { + convertEquals(5,"minute",300.0, "s"); + } + + @Test + public void test7200SecondToHour() throws Exception { + convertEquals(2,"hour",7200.0, "s"); + } + + @Test + public void test120MinuteToHour() throws Exception { + convertEquals(2,"hour",120.0, "minute"); + } + + @Test + public void test300MinuteToHour() throws Exception { + convertEquals(5,"hour",300.0, "minute"); + } + + @Test + public void test48HourToDay() throws Exception { + convertEquals(2,"day",48, "hour"); + } +} diff --git a/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/module/UnitXCModuleVolumeTest.java b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/module/UnitXCModuleVolumeTest.java new file mode 100644 index 00000000..475611c5 --- /dev/null +++ b/gdxapp4d-unitxc/src/test/java/net/forwardfire/unitxc/module/UnitXCModuleVolumeTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module; + +import static net.forwardfire.unitxc.UnitXCAssert.convertEquals; + +import org.junit.jupiter.api.Test; + +public class UnitXCModuleVolumeTest { + + @Test + public void test10CubicFootToCubicInch() throws Exception { + convertEquals(18593.0,"in³",10.763, "ft³"); // redo after fix + } + + @Test + public void test1ToCubicCentimetre() throws Exception { + convertEquals(1000000,"cm³",1.0, "m³"); + } + + @Test + public void test1ToCubicDecimetre() throws Exception { + convertEquals(1000,"dm³",1.0, "m³"); + } +} diff --git a/gdxapp4d-vrgem4/pom.xml b/gdxapp4d-vrgem4/pom.xml index 26d02a64..487f785f 100644 --- a/gdxapp4d-vrgem4/pom.xml +++ b/gdxapp4d-vrgem4/pom.xml @@ -32,13 +32,11 @@ ${tos4.packages} + org.slf4j.impl, love.distributedrebirth.gdxapp4d.vrgem4.service, love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp love.distributedrebirth.gdxapp4d.vrgem4.* - love.distributedrebirth.gdxapp4d.vrgem4.GDXAppVrGem4Activator distributedrebirth.love diff --git a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/GDXAppVrGem4Activator.java b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/GDXAppVrGem4Activator.java index 6fdbb977..7096a236 100644 --- a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/GDXAppVrGem4Activator.java +++ b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/GDXAppVrGem4Activator.java @@ -36,7 +36,7 @@ import love.distributedrebirth.numberxd.base2t.Base2PartsFactory; import love.distributedrebirth.numberxd.base2t.Base2Terminator; import love.distributedrebirth.numberxd.base2t.Base2WarpCore; import love.distributedrebirth.numberxd.unicode.BaseGlyphSet; -import love.distributedrebirth.warpme.ship.WaterShipOcean; +import love.distributedrebirth.warpme.ship.WaterShipWarp; @BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") public class GDXAppVrGem4Activator implements BundleActivator { @@ -93,7 +93,7 @@ public class GDXAppVrGem4Activator implements BundleActivator { List registratedSeas = new ArrayList<>(); int result = 0; try { - for (WaterShipOcean ocean:systemWarpShip.getWarpShip().theShip().getShipOceans()) { + for (WaterShipWarp ocean:systemWarpShip.getWarpShip().theShip().getWarpSeas()) { result = systemWarpShip.loadWaterOcean(context, registratedSeas, ocean.getSea(), v -> bootScreen.bootLine(v)); } } catch (Exception e) { @@ -197,7 +197,7 @@ public class GDXAppVrGem4Activator implements BundleActivator { } } - private void startTerminalScreens(GDXAppVrGem4BootScreen bootScreen, SystemGdxBootArgs bootArgs, SystemGdxTerminal terminal, VrGem4DeskAppServiceImpl deskAppService) { + private void startTerminalScreens(GDXAppVrGem4BootScreen bootScreen, SystemGdxBootArgs bootArgs, SystemGdxTerminal terminal, VrGem4DeskAppService deskAppService) { bootScreen.bootLine("vrGEM⁴: add terminal screens"); Gdx.app.postRunnable(new Runnable() { @Override diff --git a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/VrGem4DeskAppServiceImpl.java b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/VrGem4DeskAppServiceImpl.java index 4f83b117..1244ed40 100644 --- a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/VrGem4DeskAppServiceImpl.java +++ b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/VrGem4DeskAppServiceImpl.java @@ -1,6 +1,7 @@ package love.distributedrebirth.gdxapp4d.vrgem4; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -15,22 +16,31 @@ public class VrGem4DeskAppServiceImpl implements VrGem4DeskAppService { private Map> menu = new HashMap<>(); - public List getMenuSection(DeskAppMenuSection section) { - List result = menu.get(section); - if (result == null) { - result = new ArrayList<>(); - menu.put(section, result); + private List buildMenuSection(DeskAppMenuSection section) { + List launchers = menu.get(section); + if (launchers == null) { + launchers = new ArrayList<>(); + menu.put(section, launchers); } + return launchers; + } + + @Override + public List getMenuSection(DeskAppMenuSection section) { + List result = new ArrayList<>(buildMenuSection(section)); + Collections.sort(result, (v1, v2) -> { + return v1.getName().compareTo(v2.getName()); // TODO: change data structure + }); return result; } @Override public void installDeskApp(DeskAppLauncher launcher) { - getMenuSection(launcher.getMenuSection()).add(launcher); + buildMenuSection(launcher.getMenuSection()).add(launcher); } @Override public void removeDeskApp(DeskAppLauncher launcher) { - getMenuSection(launcher.getMenuSection()).remove(launcher); + buildMenuSection(launcher.getMenuSection()).remove(launcher); } } diff --git a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/AbstractScreenDesktop.java b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/AbstractScreenDesktop.java index e9fdb3d3..6e0caab9 100644 --- a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/AbstractScreenDesktop.java +++ b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/AbstractScreenDesktop.java @@ -23,7 +23,7 @@ import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxBootArgs; import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxTerminal; import love.distributedrebirth.gdxapp4d.vrgem4.ImGuiSetup; -import love.distributedrebirth.gdxapp4d.vrgem4.VrGem4DeskAppServiceImpl; +import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4DeskAppService; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskApp; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppContourSection; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppRenderer; @@ -49,7 +49,7 @@ public abstract class AbstractScreenDesktop extends ScreenAdapter implements Des private ModelBatch modelBatch; private Array modelInstances = new Array(); - public AbstractScreenDesktop(String name, SystemGdxBootArgs bootArgs, SystemGdxTerminal terminal, VrGem4DeskAppServiceImpl deskAppService) { + public AbstractScreenDesktop(String name, SystemGdxBootArgs bootArgs, SystemGdxTerminal terminal, VrGem4DeskAppService deskAppService) { this.create(); screenMenu = new DeskTopScreenMenu(bootArgs, terminal, deskAppService); deskAppScreen = new DeskAppController(name); diff --git a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop1.java b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop1.java index c52552e0..98a452b7 100644 --- a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop1.java +++ b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop1.java @@ -19,7 +19,7 @@ import com.badlogic.gdx.utils.Array; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxBootArgs; import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxTerminal; -import love.distributedrebirth.gdxapp4d.vrgem4.VrGem4DeskAppServiceImpl; +import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4DeskAppService; @BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") public class ScreenDesktop1 extends AbstractScreenDesktop { @@ -37,7 +37,7 @@ public class ScreenDesktop1 extends AbstractScreenDesktop { private Model pyramid3_2; private Model pyramid3_3; - public ScreenDesktop1(SystemGdxBootArgs bootArgs, SystemGdxTerminal terminal, VrGem4DeskAppServiceImpl deskAppService) { + public ScreenDesktop1(SystemGdxBootArgs bootArgs, SystemGdxTerminal terminal, VrGem4DeskAppService deskAppService) { super("Desktop1", bootArgs, terminal, deskAppService); } diff --git a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop2.java b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop2.java index 4591f148..40d06eab 100644 --- a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop2.java +++ b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop2.java @@ -16,7 +16,7 @@ import com.badlogic.gdx.utils.Array; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxBootArgs; import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxTerminal; -import love.distributedrebirth.gdxapp4d.vrgem4.VrGem4DeskAppServiceImpl; +import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4DeskAppService; @BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") public class ScreenDesktop2 extends AbstractScreenDesktop { @@ -24,7 +24,7 @@ public class ScreenDesktop2 extends AbstractScreenDesktop { private Model background; private Model grid; - public ScreenDesktop2(SystemGdxBootArgs bootArgs, SystemGdxTerminal terminal, VrGem4DeskAppServiceImpl deskAppService) { + public ScreenDesktop2(SystemGdxBootArgs bootArgs, SystemGdxTerminal terminal, VrGem4DeskAppService deskAppService) { super("Desktop2", bootArgs, terminal, deskAppService); } diff --git a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop3.java b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop3.java index 955e2c50..f6eae0c5 100644 --- a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop3.java +++ b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop3.java @@ -16,7 +16,7 @@ import com.badlogic.gdx.utils.Array; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxBootArgs; import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxTerminal; -import love.distributedrebirth.gdxapp4d.vrgem4.VrGem4DeskAppServiceImpl; +import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4DeskAppService; @BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") public class ScreenDesktop3 extends AbstractScreenDesktop { @@ -24,7 +24,7 @@ public class ScreenDesktop3 extends AbstractScreenDesktop { private Model background; private Model grid; - public ScreenDesktop3(SystemGdxBootArgs bootArgs, SystemGdxTerminal terminal, VrGem4DeskAppServiceImpl deskAppService) { + public ScreenDesktop3(SystemGdxBootArgs bootArgs, SystemGdxTerminal terminal, VrGem4DeskAppService deskAppService) { super("Desktop3", bootArgs, terminal, deskAppService); } diff --git a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop4.java b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop4.java index bae90325..b158c143 100644 --- a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop4.java +++ b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/screen/ScreenDesktop4.java @@ -27,7 +27,7 @@ import com.badlogic.gdx.utils.viewport.ScreenViewport; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxBootArgs; import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxTerminal; -import love.distributedrebirth.gdxapp4d.vrgem4.VrGem4DeskAppServiceImpl; +import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4DeskAppService; @BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") public class ScreenDesktop4 extends AbstractScreenDesktop { @@ -45,7 +45,7 @@ public class ScreenDesktop4 extends AbstractScreenDesktop { private Texture backgroundImage; private Model background; - public ScreenDesktop4(SystemGdxBootArgs bootArgs, SystemGdxTerminal terminal, VrGem4DeskAppServiceImpl deskAppService) { + public ScreenDesktop4(SystemGdxBootArgs bootArgs, SystemGdxTerminal terminal, VrGem4DeskAppService deskAppService) { super("Desktop4", bootArgs, terminal, deskAppService); shader = new UserColorShader(); shader.init(); diff --git a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/service/VrGem4DeskAppService.java b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/service/VrGem4DeskAppService.java index 4dbeda5c..0bb32bb0 100644 --- a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/service/VrGem4DeskAppService.java +++ b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/service/VrGem4DeskAppService.java @@ -1,11 +1,16 @@ package love.distributedrebirth.gdxapp4d.vrgem4.service; +import java.util.List; + import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppLauncher; +import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppMenuSection; @BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") public interface VrGem4DeskAppService { + List getMenuSection(DeskAppMenuSection section); + void installDeskApp(DeskAppLauncher launcher); void removeDeskApp(DeskAppLauncher launcher); diff --git a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/view/DeskTopScreenMenu.java b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/view/DeskTopScreenMenu.java index dc6d0fd3..4cb7c378 100644 --- a/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/view/DeskTopScreenMenu.java +++ b/gdxapp4d-vrgem4/src/main/java/love/distributedrebirth/gdxapp4d/vrgem4/view/DeskTopScreenMenu.java @@ -10,13 +10,13 @@ import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxBootArgs; import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxTerminal; import love.distributedrebirth.gdxapp4d.vrgem4.FontAwesomeIcons; -import love.distributedrebirth.gdxapp4d.vrgem4.VrGem4DeskAppServiceImpl; import love.distributedrebirth.gdxapp4d.vrgem4.screen.ScreenCredits; import love.distributedrebirth.gdxapp4d.vrgem4.screen.ScreenDesktop1; import love.distributedrebirth.gdxapp4d.vrgem4.screen.ScreenDesktop2; import love.distributedrebirth.gdxapp4d.vrgem4.screen.ScreenDesktop3; import love.distributedrebirth.gdxapp4d.vrgem4.screen.ScreenDesktop4; import love.distributedrebirth.gdxapp4d.vrgem4.screen.ScreenHelp; +import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4DeskAppService; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskApp; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppContourSection; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppLauncher; @@ -28,12 +28,12 @@ public class DeskTopScreenMenu { private SystemGdxBootArgs bootArgs; private SystemGdxTerminal terminal; - private VrGem4DeskAppServiceImpl deskAppService; + private VrGem4DeskAppService deskAppService; private ImBoolean fileMinimizeSelected = new ImBoolean(false); private ImBoolean fileCloseSelected = new ImBoolean(false); private ImBoolean tosSelfSelected = new ImBoolean(false); - public DeskTopScreenMenu(SystemGdxBootArgs bootArgs, SystemGdxTerminal terminal, VrGem4DeskAppServiceImpl deskAppService) { + public DeskTopScreenMenu(SystemGdxBootArgs bootArgs, SystemGdxTerminal terminal, VrGem4DeskAppService deskAppService) { this.bootArgs = bootArgs; this.terminal = terminal; this.deskAppService = deskAppService; diff --git a/gdxapp4d-vrgem4/src/main/java/org/slf4j/impl/MyClass.java b/gdxapp4d-vrgem4/src/main/java/org/slf4j/impl/MyClass.java new file mode 100644 index 00000000..d391e67f --- /dev/null +++ b/gdxapp4d-vrgem4/src/main/java/org/slf4j/impl/MyClass.java @@ -0,0 +1,7 @@ +package org.slf4j.impl; + +public class MyClass { + + public static void fakeDepToBootSLF4J(String out) { + } +} diff --git a/gdxapp4d-vrsys5/pom.xml b/gdxapp4d-vrsys5/pom.xml index 31a72a61..aab9e4a9 100644 --- a/gdxapp4d-vrsys5/pom.xml +++ b/gdxapp4d-vrsys5/pom.xml @@ -29,7 +29,10 @@ <_donotcopy>(.git) <_dsannotations>* <_metatypeannotations>* - ${vrgem4.packages} + + ${tos4.packages}, + ${vrgem4.packages} + distributedrebirth.love diff --git a/pom.xml b/pom.xml index 73718e4a..6522f930 100644 --- a/pom.xml +++ b/pom.xml @@ -15,8 +15,6 @@ gdxapp4d-chain-default-music gdxapp4d-chain-dep-osgi-scr gdxapp4d-chain-font-unicode4d - gdxapp4d-chain-sys-default - gdxapp4d-chain-sys-engine gdxapp4d-lib-basicwd gdxapp4d-lib-imxmi gdxapp4d-lib-numberxd @@ -29,8 +27,14 @@ gdxapp4d-app-hewallet gdxapp4d-vrsys5 gdxapp4d-chain-default-apps - gdxapp4d-chain-vrlib gdxapp4d-app-glyphdemo + gdxapp4d-unitxc + gdxapp4d-chain-dep-osgi-lib + gdxapp4d-chain-boot-ship-engine + gdxapp4d-chain-boot-warp-sea + gdxapp4d-chain-mod-unitxc + gdxapp4d-chain-mod-vrgem4 + gdxapp4d-chain-mod-vrsys5 UTF-8 @@ -139,10 +143,21 @@ love.distributedrebirth.unicode4d.draw - ${tos4.packages}, love.distributedrebirth.gdxapp4d.vrgem4.service, love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp + + net.forwardfire.unitxc, + net.forwardfire.unitxc.config, + net.forwardfire.unitxc.config.builder, + net.forwardfire.unitxc.converter, + net.forwardfire.unitxc.model, + net.forwardfire.unitxc.model.step, + net.forwardfire.unitxc.model.step.value, + net.forwardfire.unitxc.module, + net.forwardfire.unitxc.module.derived, + net.forwardfire.unitxc.named +