Added UnitXrossConverter
This commit is contained in:
parent
84738628af
commit
d97076d436
|
@ -29,7 +29,10 @@
|
||||||
<_donotcopy>(.git)</_donotcopy>
|
<_donotcopy>(.git)</_donotcopy>
|
||||||
<_dsannotations>*</_dsannotations>
|
<_dsannotations>*</_dsannotations>
|
||||||
<_metatypeannotations>*</_metatypeannotations>
|
<_metatypeannotations>*</_metatypeannotations>
|
||||||
<Import-Package>${vrgem4.packages}</Import-Package>
|
<Import-Package>
|
||||||
|
${tos4.packages},
|
||||||
|
${vrgem4.packages}
|
||||||
|
</Import-Package>
|
||||||
<Bundle-Vendor>distributedrebirth.love</Bundle-Vendor>
|
<Bundle-Vendor>distributedrebirth.love</Bundle-Vendor>
|
||||||
</instructions>
|
</instructions>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -15,6 +15,12 @@
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>love.distributedrebirth.gdxapp4d</groupId>
|
||||||
|
<artifactId>gdxapp4d-unitxc</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -29,7 +35,23 @@
|
||||||
<_donotcopy>(.git)</_donotcopy>
|
<_donotcopy>(.git)</_donotcopy>
|
||||||
<_dsannotations>*</_dsannotations>
|
<_dsannotations>*</_dsannotations>
|
||||||
<_metatypeannotations>*</_metatypeannotations>
|
<_metatypeannotations>*</_metatypeannotations>
|
||||||
<Import-Package>${vrgem4.packages}</Import-Package>
|
<Import-Package>
|
||||||
|
${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
|
||||||
|
</Import-Package>
|
||||||
<Bundle-Vendor>distributedrebirth.love</Bundle-Vendor>
|
<Bundle-Vendor>distributedrebirth.love</Bundle-Vendor>
|
||||||
</instructions>
|
</instructions>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.osgi.service.component.annotations.Deactivate;
|
||||||
import org.osgi.service.component.annotations.Reference;
|
import org.osgi.service.component.annotations.Reference;
|
||||||
|
|
||||||
import love.distributedrebirth.gdxapp4d.app.glyphdemo.apps.DemoUnicodePlaneDeskApp;
|
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.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||||
import love.distributedrebirth.gdxapp4d.app.glyphdemo.apps.DemoGlyphSetDeskApp;
|
import love.distributedrebirth.gdxapp4d.app.glyphdemo.apps.DemoGlyphSetDeskApp;
|
||||||
import love.distributedrebirth.gdxapp4d.app.glyphdemo.apps.DemoNumberPartDeskApp;
|
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.VrGem4Unicode4DService;
|
||||||
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppLauncher;
|
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppLauncher;
|
||||||
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppMenuSection;
|
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppMenuSection;
|
||||||
|
import net.forwardfire.unitxc.UnitXCManager;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
|
@BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
|
||||||
|
@ -34,15 +36,20 @@ public class GlyphDemoComponent {
|
||||||
@Reference
|
@Reference
|
||||||
private VrGem4Unicode4DService unicode4DService;
|
private VrGem4Unicode4DService unicode4DService;
|
||||||
|
|
||||||
|
@Reference
|
||||||
|
private UnitXCManager unitManager;
|
||||||
|
|
||||||
private final static String I18N_BUNDLE = "love.distributedrebirth.gdxapp4d.app.glyphdemo.Messages";
|
private final static String I18N_BUNDLE = "love.distributedrebirth.gdxapp4d.app.glyphdemo.Messages";
|
||||||
private final DeskAppLauncher unicodeLauncher;
|
private final DeskAppLauncher unicodeLauncher;
|
||||||
private final DeskAppLauncher baseGlyphLauncher;
|
private final DeskAppLauncher baseGlyphLauncher;
|
||||||
private final DeskAppLauncher basePartLauncher;
|
private final DeskAppLauncher basePartLauncher;
|
||||||
|
private final DeskAppLauncher unitConverterLauncher;
|
||||||
|
|
||||||
public GlyphDemoComponent() {
|
public GlyphDemoComponent() {
|
||||||
unicodeLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Demo Unicode Plane", () -> new DemoUnicodePlaneDeskApp(createBundle(), unicode4DService));
|
unicodeLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Unicode Plane", () -> new DemoUnicodePlaneDeskApp(createBundle(), unicode4DService));
|
||||||
baseGlyphLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Demo Glyph Set", () -> new DemoGlyphSetDeskApp(createBundle()));
|
baseGlyphLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Glyph Set", () -> new DemoGlyphSetDeskApp(createBundle()));
|
||||||
basePartLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Demo Number Parts", () -> new DemoNumberPartDeskApp(createBundle()));
|
basePartLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Number Parts", () -> new DemoNumberPartDeskApp(createBundle()));
|
||||||
|
unitConverterLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Unitˣᶜ Converter", () -> new DemoUnitConverterDeskApp(unitManager));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResourceBundle createBundle() {
|
private ResourceBundle createBundle() {
|
||||||
|
@ -55,6 +62,7 @@ public class GlyphDemoComponent {
|
||||||
deskAppService.installDeskApp(unicodeLauncher);
|
deskAppService.installDeskApp(unicodeLauncher);
|
||||||
deskAppService.installDeskApp(baseGlyphLauncher);
|
deskAppService.installDeskApp(baseGlyphLauncher);
|
||||||
deskAppService.installDeskApp(basePartLauncher);
|
deskAppService.installDeskApp(basePartLauncher);
|
||||||
|
deskAppService.installDeskApp(unitConverterLauncher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deactivate
|
@Deactivate
|
||||||
|
@ -63,5 +71,6 @@ public class GlyphDemoComponent {
|
||||||
deskAppService.removeDeskApp(unicodeLauncher);
|
deskAppService.removeDeskApp(unicodeLauncher);
|
||||||
deskAppService.removeDeskApp(baseGlyphLauncher);
|
deskAppService.removeDeskApp(baseGlyphLauncher);
|
||||||
deskAppService.removeDeskApp(basePartLauncher);
|
deskAppService.removeDeskApp(basePartLauncher);
|
||||||
|
deskAppService.removeDeskApp(unitConverterLauncher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<UnitXCType> unitTypes;
|
||||||
|
private final List<UnitXCGroup> unitGroups;
|
||||||
|
private final Map<String, String> unitTypesFlags;
|
||||||
|
private final Map<String, String> 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<UnitXCType> 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<String> 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<String> types = typeGroup.getUnitTypeIds();
|
||||||
|
List<String> 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<String> 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<G1BarrierSet::AccessBarrier<0ul, G1BarrierSet>, (AccessInternal::BarrierType)2, 0ul>::oop_access_barrier(void*)+0x1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.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.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.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.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
|
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.selectBase=\uE0C0\u2005\uE13F\u2005\uE2F4
|
||||||
DemoNumberPartDeskApp.selectName=\uE216\u2005\uE13F\u2005\uE153\u2005\uE3EC
|
DemoNumberPartDeskApp.selectName=\uE216\u2005\uE13F\u2005\uE153\u2005\uE3EC
|
||||||
DemoNumberPartDeskApp.selectPurpose=\uE203\u2005\uE171\u2005\uE08C\u2005\uE203\u2005\uE2F4\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.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
|
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.colPlane=Unicode Plane
|
||||||
DemoUnicodePlaneDeskApp.colText=Example
|
DemoUnicodePlaneDeskApp.colText=Example
|
||||||
DemoUnicodePlaneDeskApp.render4DPlane0=Show all in unicode4D
|
DemoUnicodePlaneDeskApp.render4DPlane0=Show all in unicode4D
|
|
@ -1,11 +1,11 @@
|
||||||
DemoGlyphSetDeskApp.title=Demo Glyph Set
|
DemoGlyphSetDeskApp.title=Glyph Set
|
||||||
DemoGlyphSetDeskApp.showBase27=Toon basis27
|
DemoGlyphSetDeskApp.showBase27=Toon basis27
|
||||||
DemoGlyphSetDeskApp.colScript=Script
|
DemoGlyphSetDeskApp.colScript=Script
|
||||||
DemoGlyphSetDeskApp.col10Num=10Nummer
|
DemoGlyphSetDeskApp.col10Num=10Nummer
|
||||||
DemoGlyphSetDeskApp.col16Num=16Nummer
|
DemoGlyphSetDeskApp.col16Num=16Nummer
|
||||||
DemoGlyphSetDeskApp.col27Num=27Nummer
|
DemoGlyphSetDeskApp.col27Num=27Nummer
|
||||||
|
|
||||||
DemoNumberPartDeskApp.title=Demo Nummer Onderdeel
|
DemoNumberPartDeskApp.title=Nummer Onderdeel
|
||||||
DemoNumberPartDeskApp.selectBase=Basis
|
DemoNumberPartDeskApp.selectBase=Basis
|
||||||
DemoNumberPartDeskApp.selectName=Naam:
|
DemoNumberPartDeskApp.selectName=Naam:
|
||||||
DemoNumberPartDeskApp.selectPurpose=Doel:
|
DemoNumberPartDeskApp.selectPurpose=Doel:
|
||||||
|
@ -13,7 +13,7 @@ DemoNumberPartDeskApp.showBase10=Toon basis10
|
||||||
DemoNumberPartDeskApp.showBase16=Toon basis16
|
DemoNumberPartDeskApp.showBase16=Toon basis16
|
||||||
DemoNumberPartDeskApp.showBase27=Toon basis27
|
DemoNumberPartDeskApp.showBase27=Toon basis27
|
||||||
|
|
||||||
DemoUnicodePlaneDeskApp.title=Demo Unicode Vlak
|
DemoUnicodePlaneDeskApp.title=Unicode Vlak
|
||||||
DemoUnicodePlaneDeskApp.colPlane=Unicode Vlak
|
DemoUnicodePlaneDeskApp.colPlane=Unicode Vlak
|
||||||
DemoUnicodePlaneDeskApp.colText=Voorbeeld
|
DemoUnicodePlaneDeskApp.colText=Voorbeeld
|
||||||
DemoUnicodePlaneDeskApp.render4DPlane0=Toon alles in unicode4D
|
DemoUnicodePlaneDeskApp.render4DPlane0=Toon alles in unicode4D
|
|
@ -29,7 +29,10 @@
|
||||||
<_donotcopy>(.git)</_donotcopy>
|
<_donotcopy>(.git)</_donotcopy>
|
||||||
<_dsannotations>*</_dsannotations>
|
<_dsannotations>*</_dsannotations>
|
||||||
<_metatypeannotations>*</_metatypeannotations>
|
<_metatypeannotations>*</_metatypeannotations>
|
||||||
<Import-Package>${vrgem4.packages}</Import-Package>
|
<Import-Package>
|
||||||
|
${tos4.packages},
|
||||||
|
${vrgem4.packages}
|
||||||
|
</Import-Package>
|
||||||
<Bundle-Vendor>distributedrebirth.love</Bundle-Vendor>
|
<Bundle-Vendor>distributedrebirth.love</Bundle-Vendor>
|
||||||
</instructions>
|
</instructions>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -29,7 +29,10 @@
|
||||||
<_donotcopy>(.git)</_donotcopy>
|
<_donotcopy>(.git)</_donotcopy>
|
||||||
<_dsannotations>*</_dsannotations>
|
<_dsannotations>*</_dsannotations>
|
||||||
<_metatypeannotations>*</_metatypeannotations>
|
<_metatypeannotations>*</_metatypeannotations>
|
||||||
<Import-Package>${vrgem4.packages}</Import-Package>
|
<Import-Package>
|
||||||
|
${tos4.packages},
|
||||||
|
${vrgem4.packages}
|
||||||
|
</Import-Package>
|
||||||
<Bundle-Vendor>distributedrebirth.love</Bundle-Vendor>
|
<Bundle-Vendor>distributedrebirth.love</Bundle-Vendor>
|
||||||
</instructions>
|
</instructions>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class NotepadDeskApp extends AbstractDeskApp implements DeskAppRenderer {
|
||||||
private final int[] gridRank;
|
private final int[] gridRank;
|
||||||
private final Random random;
|
private final Random random;
|
||||||
private int runCounter;
|
private int runCounter;
|
||||||
private final ImInt runSpeed = new ImInt(30);
|
private final ImInt runSpeed = new ImInt(10);
|
||||||
private final static UnicodePlane[] GRID_PLANES = {
|
private final static UnicodePlane[] GRID_PLANES = {
|
||||||
UnicodePlane.BRAHMI,
|
UnicodePlane.BRAHMI,
|
||||||
UnicodePlane.UGARITIC,
|
UnicodePlane.UGARITIC,
|
||||||
|
|
|
@ -29,7 +29,10 @@
|
||||||
<_donotcopy>(.git)</_donotcopy>
|
<_donotcopy>(.git)</_donotcopy>
|
||||||
<_dsannotations>*</_dsannotations>
|
<_dsannotations>*</_dsannotations>
|
||||||
<_metatypeannotations>*</_metatypeannotations>
|
<_metatypeannotations>*</_metatypeannotations>
|
||||||
<Import-Package>${vrgem4.packages}</Import-Package>
|
<Import-Package>
|
||||||
|
${tos4.packages},
|
||||||
|
${vrgem4.packages}
|
||||||
|
</Import-Package>
|
||||||
<Bundle-Vendor>distributedrebirth.love</Bundle-Vendor>
|
<Bundle-Vendor>distributedrebirth.love</Bundle-Vendor>
|
||||||
</instructions>
|
</instructions>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||||
<properties>
|
<properties>
|
||||||
<entry key="1c2d010066a39d96ace8af0ecc37c72d6f79109f30939e2959befcd9ce25fc8d">../gdxapp4d-chain-sys-engine/target/chain</entry>
|
<entry key="1c2d010066a39d96ace8af0ecc37c72d6f79109f30939e2959befcd9ce25fc8d">../gdxapp4d-chain-boot-ship-engine/target/chain</entry>
|
||||||
<entry key="f8be3b29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41a410b">../gdxapp4d-chain-sys-default/target/chain</entry>
|
<entry key="f8be3b29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41a410b">../gdxapp4d-chain-boot-warp-sea/target/chain</entry>
|
||||||
|
|
||||||
|
<entry key="7777aa29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41b58de">../gdxapp4d-chain-dep-osgi-lib/target/chain</entry>
|
||||||
<entry key="8833aa29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41b58de">../gdxapp4d-chain-dep-osgi-scr/target/chain</entry>
|
<entry key="8833aa29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41b58de">../gdxapp4d-chain-dep-osgi-scr/target/chain</entry>
|
||||||
<entry key="9944bb29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41b62ed">../gdxapp4d-chain-font-unicode4d/target/chain</entry>
|
<entry key="9944bb29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41b62ed">../gdxapp4d-chain-font-unicode4d/target/chain</entry>
|
||||||
<entry key="ffee3329da5b6b2cb4befcc14aac55de6777d848d158293a4cdffbc2c41b12ad">../gdxapp4d-chain-default-music/target/chain</entry>
|
<entry key="ffee3329da5b6b2cb4befcc14aac55de6777d848d158293a4cdffbc2c41b12ad">../gdxapp4d-chain-default-music/target/chain</entry>
|
||||||
|
@ -14,7 +15,12 @@
|
||||||
<entry key="7744aa29da5b6b2cb4b8f781469c33de688fd848d158293a4cdddbc2c41b12aa.bundle/gdxapp4d-app-notepad.jar">../gdxapp4d-app-notepad/target/classes</entry>
|
<entry key="7744aa29da5b6b2cb4b8f781469c33de688fd848d158293a4cdddbc2c41b12aa.bundle/gdxapp4d-app-notepad.jar">../gdxapp4d-app-notepad/target/classes</entry>
|
||||||
<entry key="7744aa29da5b6b2cb4b8f781469c33de688fd848d158293a4cdddbc2c41b12aa.bundle/gdxapp4d-app-glyphdemo.jar">../gdxapp4d-app-glyphdemo/target/classes</entry>
|
<entry key="7744aa29da5b6b2cb4b8f781469c33de688fd848d158293a4cdddbc2c41b12aa.bundle/gdxapp4d-app-glyphdemo.jar">../gdxapp4d-app-glyphdemo/target/classes</entry>
|
||||||
|
|
||||||
<entry key="ccba3b29da8b1b1cb444f381449beede3cbfd442d158293a4cdffbc3c41a31cc">../gdxapp4d-chain-vrlib/target/chain</entry>
|
<entry key="2222010099a37897688af0ecc37c72d6faabb7709ee39e2959befcd9ce253333">../gdxapp4d-chain-mod-vrgem4/target/chain</entry>
|
||||||
<entry key="ccba3b29da8b1b1cb444f381449beede3cbfd442d158293a4cdffbc3c41a31cc.bundle/gdxapp4d-vrgem4.jar">../gdxapp4d-vrgem4/target/classes</entry>
|
<entry key="2222010099a37897688af0ecc37c72d6faabb7709ee39e2959befcd9ce253333.bundle/gdxapp4d-vrgem4.jar">../gdxapp4d-vrgem4/target/classes</entry>
|
||||||
|
|
||||||
|
<entry key="ccba3b29da8b1b1cb444f381449beede3cbfd442d158293a4cdffbc3c41a31cc">../gdxapp4d-chain-mod-vrsys5/target/chain</entry>
|
||||||
<entry key="ccba3b29da8b1b1cb444f381449beede3cbfd442d158293a4cdffbc3c41a31cc.bundle/gdxapp4d-vrsys5.jar">../gdxapp4d-vrsys5/target/classes</entry>
|
<entry key="ccba3b29da8b1b1cb444f381449beede3cbfd442d158293a4cdffbc3c41a31cc.bundle/gdxapp4d-vrsys5.jar">../gdxapp4d-vrsys5/target/classes</entry>
|
||||||
|
|
||||||
|
<entry key="12343b29da8b1b1cb444f381449beede3cbfd442d158293a4cdffbc3c41a7890">../gdxapp4d-chain-mod-unitxc/target/chain</entry>
|
||||||
|
<entry key="12343b29da8b1b1cb444f381449beede3cbfd442d158293a4cdffbc3c41a7890.bundle/gdxapp4d-unitxc.jar">../gdxapp4d-unitxc/target/classes</entry>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
@ -4,9 +4,8 @@
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:boot="http://warp-ship.x4o.distributedrebirth.love/xml/ns/warp-ship-boot"
|
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">
|
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">
|
||||||
<boot:ship name="tos4-mark1-local"
|
<boot:ship name="tos4-mark1-phoenix-poc"
|
||||||
engine="1c2d010066a39d96ace8af0ecc37c72d6f79109f30939e2959befcd9ce25fc8d">
|
engine="1c2d010066a39d96ace8af0ecc37c72d6f79109f30939e2959befcd9ce25fc8d">
|
||||||
<boot:ocean
|
<boot:warp sea="f8be3b29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41a410b" />
|
||||||
sea="f8be3b29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41a410b" />
|
|
||||||
</boot:ship>
|
</boot:ship>
|
||||||
</root:device>
|
</root:device>
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
<artifactId>gdxapp4d</artifactId>
|
<artifactId>gdxapp4d</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>gdxapp4d-chain-sys-engine</artifactId>
|
<artifactId>gdxapp4d-chain-boot-ship-engine</artifactId>
|
||||||
<name>GDXApp⁴ᴰ-Chain-Sys-محرك</name>
|
<name>GDXApp⁴ᴰ-Chain-Boot-Ship-محرك</name>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
|
@ -3,12 +3,12 @@
|
||||||
xmlns:link="http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-link"
|
xmlns:link="http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-link"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
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">
|
||||||
<link:sea name="System Engine" provider="gdxapp4d.system" author="للَّٰهِilLצسُو">
|
<link:sea name="Boot Ship Engine" provider="gdxapp4d.system" author="للَّٰهِilLצسُو">
|
||||||
<!-- Link font-unicode4d -->
|
<!-- Link font-unicode4d -->
|
||||||
<link:chain key="9944bb29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41b62ed"/>
|
<link:chain key="9944bb29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41b62ed"/>
|
||||||
<!-- Link dep-osgi-scr -->
|
<!-- Link dep-osgi-scr -->
|
||||||
<link:chain key="8833aa29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41b58de"/>
|
<link:chain key="8833aa29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41b58de"/>
|
||||||
<!-- Link vrlib -->
|
<!-- Link mod-vrgem4 -->
|
||||||
<link:chain key="ccba3b29da8b1b1cb444f381449beede3cbfd442d158293a4cdffbc3c41a31cc"/>
|
<link:chain key="2222010099a37897688af0ecc37c72d6faabb7709ee39e2959befcd9ce253333"/>
|
||||||
</link:sea>
|
</link:sea>
|
||||||
</root:ocean>
|
</root:ocean>
|
|
@ -5,8 +5,8 @@
|
||||||
<artifactId>gdxapp4d</artifactId>
|
<artifactId>gdxapp4d</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>gdxapp4d-chain-sys-default</artifactId>
|
<artifactId>gdxapp4d-chain-boot-warp-sea</artifactId>
|
||||||
<name>GDXApp⁴ᴰ-Chain-Sys-ค่าเริ่มต้น</name>
|
<name>GDXApp⁴ᴰ-Chain-Boot-Warp-ค่าเริ่มต้น</name>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
|
@ -3,7 +3,14 @@
|
||||||
xmlns:link="http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-link"
|
xmlns:link="http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-link"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
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">
|
||||||
<link:sea name="System Default" provider="gdxapp4d.system" author="للَّٰهِilLצسُو">
|
<link:sea name="Boot Warp Sea" provider="gdxapp4d.system" author="للَّٰهِilLצسُو">
|
||||||
|
<!-- Link dep-osgi-lib -->
|
||||||
|
<link:chain key="7777aa29da5b6b2cb464f781469ceede6ccfd848d158293a4cdffbc2c41b58de"/>
|
||||||
|
<!-- Link mod-unitxc -->
|
||||||
|
<link:chain key="12343b29da8b1b1cb444f381449beede3cbfd442d158293a4cdffbc3c41a7890"/>
|
||||||
|
<!-- Link mod-vrsys5 -->
|
||||||
|
<link:chain key="ccba3b29da8b1b1cb444f381449beede3cbfd442d158293a4cdffbc3c41a31cc"/>
|
||||||
|
|
||||||
<!-- Link default-apps -->
|
<!-- Link default-apps -->
|
||||||
<link:chain key="7744aa29da5b6b2cb4b8f781469c33de688fd848d158293a4cdddbc2c41b12aa"/>
|
<link:chain key="7744aa29da5b6b2cb4b8f781469c33de688fd848d158293a4cdddbc2c41b12aa"/>
|
||||||
<!-- Link default-music -->
|
<!-- Link default-music -->
|
72
gdxapp4d-chain-dep-osgi-lib/pom.xml
Normal file
72
gdxapp4d-chain-dep-osgi-lib/pom.xml
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>love.distributedrebirth.gdxapp4d</groupId>
|
||||||
|
<artifactId>gdxapp4d</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>gdxapp4d-chain-dep-osgi-lib</artifactId>
|
||||||
|
<name>GDXApp⁴ᴰ-Chain-Dep-OSGI-LIB</name>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>unpack-dependencies</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-dependencies</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<configuration>
|
||||||
|
<target>
|
||||||
|
<copy todir="target/chain">
|
||||||
|
<fileset dir="src/main/chain" />
|
||||||
|
</copy>
|
||||||
|
<copy todir="target/chain/bundle">
|
||||||
|
<file file="target/dependency/slf4j-api-1.7.36.jar" />
|
||||||
|
<file file="target/dependency/logback-core-1.2.10.jar" />
|
||||||
|
<file file="target/dependency/logback-classic-1.2.10.jar" />
|
||||||
|
<file file="target/dependency/commons-lang3-3.5.jar" />
|
||||||
|
</copy>
|
||||||
|
<java failonerror="true" fork="true" classname="love.distributedrebirth.warpme.hash.WaterShotAddict">
|
||||||
|
<arg value="target/chain" />
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="../gdxapp4d-lib-warpme/target/gdxapp4d-lib-warpme.jar" />
|
||||||
|
<pathelement location="../gdxapp4d-lib-warpme/target/dependency/x4o-driver-0.8.7-SNAPSHOT.jar" />
|
||||||
|
<pathelement location="../gdxapp4d-lib-warpme/target/dependency/jasper-el-6.0.20.jar" />
|
||||||
|
<pathelement location="../gdxapp4d-lib-warpme/target/dependency/el-api-6.0.20.jar" />
|
||||||
|
</classpath>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
</configuration>
|
||||||
|
<goals>
|
||||||
|
<goal>run</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
11
gdxapp4d-chain-dep-osgi-lib/src/main/chain/warp-hash.xml
Normal file
11
gdxapp4d-chain-dep-osgi-lib/src/main/chain/warp-hash.xml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<root:shot xmlns:root="http://wrap-core.x4o.distributedrebirth.love/xml/ns/warp-hash-root"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:soft="http://warp-hash.x4o.distributedrebirth.love/xml/ns/warp-hash-soft"
|
||||||
|
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">
|
||||||
|
<soft:hash file="warp-sea.xml" hex="0"/>
|
||||||
|
<soft:hash file="bundle/slf4j-api-1.7.36.jar" hex="0"/>
|
||||||
|
<soft:hash file="bundle/logback-core-1.2.10.jar" hex="0"/>
|
||||||
|
<soft:hash file="bundle/logback-classic-1.2.10.jar" hex="0"/>
|
||||||
|
<soft:hash file="bundle/commons-lang3-3.5.jar" hex="0"/>
|
||||||
|
</root:shot>
|
12
gdxapp4d-chain-dep-osgi-lib/src/main/chain/warp-sea.xml
Normal file
12
gdxapp4d-chain-dep-osgi-lib/src/main/chain/warp-sea.xml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<root:ocean xmlns:root="http://wrap-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-root"
|
||||||
|
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">
|
||||||
|
<link:sea name="Dep Osgi Lib" provider="gdxapp4d.system" author="للَّٰهِilLצسُو">
|
||||||
|
<link:magic file="bundle/slf4j-api-1.7.36.jar" mime="application/vnd.osgi.bundle"/>
|
||||||
|
<link:magic file="bundle/logback-core-1.2.10.jar" mime="application/vnd.osgi.bundle"/>
|
||||||
|
<link:magic file="bundle/logback-classic-1.2.10.jar" mime="application/vnd.osgi.bundle"/>
|
||||||
|
<link:magic file="bundle/commons-lang3-3.5.jar" mime="application/vnd.osgi.bundle"/>
|
||||||
|
</link:sea>
|
||||||
|
</root:ocean>
|
|
@ -3,7 +3,7 @@
|
||||||
xmlns:link="http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-link"
|
xmlns:link="http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-link"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
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">
|
||||||
<link:sea name="Osgi SCR" provider="gdxapp4d.system" author="للَّٰهِilLצسُو">
|
<link:sea name="Dep Osgi Scr" provider="gdxapp4d.system" author="للَّٰهِilLצسُو">
|
||||||
<link:magic file="bundle/org.osgi.util.function-1.2.0.jar" mime="application/vnd.osgi.bundle"/>
|
<link:magic file="bundle/org.osgi.util.function-1.2.0.jar" mime="application/vnd.osgi.bundle"/>
|
||||||
<link:magic file="bundle/org.osgi.util.promise-1.2.0.jar" mime="application/vnd.osgi.bundle"/>
|
<link:magic file="bundle/org.osgi.util.promise-1.2.0.jar" mime="application/vnd.osgi.bundle"/>
|
||||||
<link:magic file="bundle/org.apache.felix.scr-2.2.0.jar" mime="application/vnd.osgi.bundle"/>
|
<link:magic file="bundle/org.apache.felix.scr-2.2.0.jar" mime="application/vnd.osgi.bundle"/>
|
||||||
|
|
53
gdxapp4d-chain-mod-unitxc/pom.xml
Normal file
53
gdxapp4d-chain-mod-unitxc/pom.xml
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>love.distributedrebirth.gdxapp4d</groupId>
|
||||||
|
<artifactId>gdxapp4d</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>gdxapp4d-chain-mod-unitxc</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<name>GDXApp⁴ᴰ-Chain-Module-Unitˣᶜ</name>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>love.distributedrebirth.gdxapp4d</groupId>
|
||||||
|
<artifactId>gdxapp4d-unitxc</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<configuration>
|
||||||
|
<target>
|
||||||
|
<copy todir="target/chain">
|
||||||
|
<fileset dir="src/main/chain" />
|
||||||
|
</copy>
|
||||||
|
<copy todir="target/chain/bundle">
|
||||||
|
<file file="../gdxapp4d-unitxc/target/gdxapp4d-unitxc.jar" />
|
||||||
|
</copy>
|
||||||
|
<java failonerror="true" fork="true" classname="love.distributedrebirth.warpme.hash.WaterShotAddict">
|
||||||
|
<arg value="target/chain" />
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="../gdxapp4d-lib-warpme/target/gdxapp4d-lib-warpme.jar" />
|
||||||
|
<pathelement location="../gdxapp4d-lib-warpme/target/dependency/x4o-driver-0.8.7-SNAPSHOT.jar" />
|
||||||
|
<pathelement location="../gdxapp4d-lib-warpme/target/dependency/jasper-el-6.0.20.jar" />
|
||||||
|
<pathelement location="../gdxapp4d-lib-warpme/target/dependency/el-api-6.0.20.jar" />
|
||||||
|
</classpath>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
</configuration>
|
||||||
|
<goals>
|
||||||
|
<goal>run</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
8
gdxapp4d-chain-mod-unitxc/src/main/chain/warp-hash.xml
Normal file
8
gdxapp4d-chain-mod-unitxc/src/main/chain/warp-hash.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<root:shot xmlns:root="http://wrap-core.x4o.distributedrebirth.love/xml/ns/warp-hash-root"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:soft="http://warp-hash.x4o.distributedrebirth.love/xml/ns/warp-hash-soft"
|
||||||
|
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">
|
||||||
|
<soft:hash file="warp-sea.xml" hex="0"/>
|
||||||
|
<soft:hash file="bundle/gdxapp4d-unitxc.jar" hex="0"/>
|
||||||
|
</root:shot>
|
9
gdxapp4d-chain-mod-unitxc/src/main/chain/warp-sea.xml
Normal file
9
gdxapp4d-chain-mod-unitxc/src/main/chain/warp-sea.xml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<root:ocean xmlns:root="http://wrap-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-root"
|
||||||
|
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">
|
||||||
|
<link:sea name="Module Unitˣᶜ" provider="gdxapp4d.system" author="للَّٰهِilLצسُو">
|
||||||
|
<link:magic file="bundle/gdxapp4d-unitxc.jar" mime="application/vnd.osgi.bundle"/>
|
||||||
|
</link:sea>
|
||||||
|
</root:ocean>
|
|
@ -5,8 +5,8 @@
|
||||||
<artifactId>gdxapp4d</artifactId>
|
<artifactId>gdxapp4d</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>gdxapp4d-chain-vrlib</artifactId>
|
<artifactId>gdxapp4d-chain-mod-vrgem4</artifactId>
|
||||||
<name>GDXApp⁴ᴰ-Chain-vrLib</name>
|
<name>GDXApp⁴ᴰ-Chain-Module-vrGEM⁴</name>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -15,12 +15,6 @@
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>love.distributedrebirth.gdxapp4d</groupId>
|
|
||||||
<artifactId>gdxapp4d-vrsys5</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -36,7 +30,6 @@
|
||||||
</copy>
|
</copy>
|
||||||
<copy todir="target/chain/bundle">
|
<copy todir="target/chain/bundle">
|
||||||
<file file="../gdxapp4d-vrgem4/target/gdxapp4d-vrgem4.jar" />
|
<file file="../gdxapp4d-vrgem4/target/gdxapp4d-vrgem4.jar" />
|
||||||
<file file="../gdxapp4d-vrsys5/target/gdxapp4d-vrsys5.jar" />
|
|
||||||
</copy>
|
</copy>
|
||||||
<java failonerror="true" fork="true" classname="love.distributedrebirth.warpme.hash.WaterShotAddict">
|
<java failonerror="true" fork="true" classname="love.distributedrebirth.warpme.hash.WaterShotAddict">
|
||||||
<arg value="target/chain" />
|
<arg value="target/chain" />
|
|
@ -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">
|
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">
|
||||||
<soft:hash file="warp-sea.xml" hex="0"/>
|
<soft:hash file="warp-sea.xml" hex="0"/>
|
||||||
<soft:hash file="bundle/gdxapp4d-vrgem4.jar" hex="0"/>
|
<soft:hash file="bundle/gdxapp4d-vrgem4.jar" hex="0"/>
|
||||||
<soft:hash file="bundle/gdxapp4d-vrsys5.jar" hex="0"/>
|
|
||||||
</root:shot>
|
</root:shot>
|
|
@ -3,8 +3,7 @@
|
||||||
xmlns:link="http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-link"
|
xmlns:link="http://warp-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-link"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
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">
|
||||||
<link:sea name="vrLIB" provider="gdxapp4d.system" author="للَّٰهِilLצسُو">
|
<link:sea name="Module vrGEM⁴" provider="gdxapp4d.system" author="للَّٰهِilLצسُو">
|
||||||
<link:magic file="bundle/gdxapp4d-vrgem4.jar" mime="application/vnd.osgi.bundle"/>
|
<link:magic file="bundle/gdxapp4d-vrgem4.jar" mime="application/vnd.osgi.bundle"/>
|
||||||
<link:magic file="bundle/gdxapp4d-vrsys5.jar" mime="application/vnd.osgi.bundle"/>
|
|
||||||
</link:sea>
|
</link:sea>
|
||||||
</root:ocean>
|
</root:ocean>
|
53
gdxapp4d-chain-mod-vrsys5/pom.xml
Normal file
53
gdxapp4d-chain-mod-vrsys5/pom.xml
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>love.distributedrebirth.gdxapp4d</groupId>
|
||||||
|
<artifactId>gdxapp4d</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>gdxapp4d-chain-mod-vrsys5</artifactId>
|
||||||
|
<name>GDXApp⁴ᴰ-Chain-Module-vrSYS⁵</name>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>love.distributedrebirth.gdxapp4d</groupId>
|
||||||
|
<artifactId>gdxapp4d-vrsys5</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<configuration>
|
||||||
|
<target>
|
||||||
|
<copy todir="target/chain">
|
||||||
|
<fileset dir="src/main/chain" />
|
||||||
|
</copy>
|
||||||
|
<copy todir="target/chain/bundle">
|
||||||
|
<file file="../gdxapp4d-vrsys5/target/gdxapp4d-vrsys5.jar" />
|
||||||
|
</copy>
|
||||||
|
<java failonerror="true" fork="true" classname="love.distributedrebirth.warpme.hash.WaterShotAddict">
|
||||||
|
<arg value="target/chain" />
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="../gdxapp4d-lib-warpme/target/gdxapp4d-lib-warpme.jar" />
|
||||||
|
<pathelement location="../gdxapp4d-lib-warpme/target/dependency/x4o-driver-0.8.7-SNAPSHOT.jar" />
|
||||||
|
<pathelement location="../gdxapp4d-lib-warpme/target/dependency/jasper-el-6.0.20.jar" />
|
||||||
|
<pathelement location="../gdxapp4d-lib-warpme/target/dependency/el-api-6.0.20.jar" />
|
||||||
|
</classpath>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
</configuration>
|
||||||
|
<goals>
|
||||||
|
<goal>run</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
8
gdxapp4d-chain-mod-vrsys5/src/main/chain/warp-hash.xml
Normal file
8
gdxapp4d-chain-mod-vrsys5/src/main/chain/warp-hash.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<root:shot xmlns:root="http://wrap-core.x4o.distributedrebirth.love/xml/ns/warp-hash-root"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:soft="http://warp-hash.x4o.distributedrebirth.love/xml/ns/warp-hash-soft"
|
||||||
|
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">
|
||||||
|
<soft:hash file="warp-sea.xml" hex="0"/>
|
||||||
|
<soft:hash file="bundle/gdxapp4d-vrsys5.jar" hex="0"/>
|
||||||
|
</root:shot>
|
9
gdxapp4d-chain-mod-vrsys5/src/main/chain/warp-sea.xml
Normal file
9
gdxapp4d-chain-mod-vrsys5/src/main/chain/warp-sea.xml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<root:ocean xmlns:root="http://wrap-sea.x4o.distributedrebirth.love/xml/ns/warp-sea-root"
|
||||||
|
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">
|
||||||
|
<link:sea name="Module vrSYS⁵" provider="gdxapp4d.system" author="للَّٰهِilLצسُو">
|
||||||
|
<link:magic file="bundle/gdxapp4d-vrsys5.jar" mime="application/vnd.osgi.bundle"/>
|
||||||
|
</link:sea>
|
||||||
|
</root:ocean>
|
|
@ -10,7 +10,7 @@ public class WaterShip {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String engine;
|
private String engine;
|
||||||
private List<WaterShipOcean> shipOceans = new ArrayList<>();
|
private List<WaterShipWarp> warpSeas = new ArrayList<>();
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
|
@ -28,17 +28,17 @@ public class WaterShip {
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<WaterShipOcean> getShipOceans() {
|
public List<WaterShipWarp> getWarpSeas() {
|
||||||
return shipOceans;
|
return warpSeas;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShipOcean(List<WaterShipOcean> shipOceans) {
|
public void setWarpSeas(List<WaterShipWarp> shipOceans) {
|
||||||
for (WaterShipOcean shipOcean:shipOceans) {
|
for (WaterShipWarp shipOcean:shipOceans) {
|
||||||
addShipOcean(shipOcean);
|
addWarpSea(shipOcean);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addShipOcean(WaterShipOcean shipSea) {
|
public void addWarpSea(WaterShipWarp shipSea) {
|
||||||
shipOceans.add(shipSea);
|
warpSeas.add(shipSea);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,14 @@ package love.distributedrebirth.warpme.ship;
|
||||||
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||||
|
|
||||||
@BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
|
@BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
|
||||||
public class WaterShipOcean {
|
public class WaterShipWarp {
|
||||||
|
|
||||||
private String sea;
|
private String sea;
|
||||||
|
|
||||||
public WaterShipOcean() {
|
public WaterShipWarp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public WaterShipOcean(String sea) {
|
public WaterShipWarp(String sea) {
|
||||||
setSea(sea);
|
setSea(sea);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,10 @@
|
||||||
parentClass="love.distributedrebirth.warpme.ship.WaterDevice"
|
parentClass="love.distributedrebirth.warpme.ship.WaterDevice"
|
||||||
childClass="love.distributedrebirth.warpme.ship.WaterShip"
|
childClass="love.distributedrebirth.warpme.ship.WaterShip"
|
||||||
addMethod="buildShip" getMethod="theShip" />
|
addMethod="buildShip" getMethod="theShip" />
|
||||||
<eld:classBindingHandler id="WaterShip-WaterShipOcean"
|
<eld:classBindingHandler id="WaterShip-WaterShipWarp"
|
||||||
parentClass="love.distributedrebirth.warpme.ship.WaterShip"
|
parentClass="love.distributedrebirth.warpme.ship.WaterShip"
|
||||||
childClass="love.distributedrebirth.warpme.ship.WaterShipOcean"
|
childClass="love.distributedrebirth.warpme.ship.WaterShipWarp"
|
||||||
addMethod="addShipOcean" getMethod="getShipOceans" />
|
addMethod="addWarpSea" getMethod="getWarpSeas" />
|
||||||
|
|
||||||
<eld:namespace
|
<eld:namespace
|
||||||
uri="http://wrap-ship.x4o.distributedrebirth.love/xml/ns/warp-ship-root"
|
uri="http://wrap-ship.x4o.distributedrebirth.love/xml/ns/warp-ship-root"
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
<eld:attribute id="name" writeOrder="0"/>
|
<eld:attribute id="name" writeOrder="0"/>
|
||||||
<eld:attribute id="engine" writeOrder="1"/>
|
<eld:attribute id="engine" writeOrder="1"/>
|
||||||
</eld:element>
|
</eld:element>
|
||||||
<eld:element tag="ocean"
|
<eld:element tag="warp"
|
||||||
objectClass="love.distributedrebirth.warpme.ship.WaterShipOcean" />
|
objectClass="love.distributedrebirth.warpme.ship.WaterShipWarp" />
|
||||||
</eld:namespace>
|
</eld:namespace>
|
||||||
</root:module>
|
</root:module>
|
|
@ -19,9 +19,9 @@ public class WaterDeviceDriverTest {
|
||||||
WaterShip ship = new WaterShip();
|
WaterShip ship = new WaterShip();
|
||||||
ship.setName("tos4-mark1");
|
ship.setName("tos4-mark1");
|
||||||
ship.setEngine("123349858934");
|
ship.setEngine("123349858934");
|
||||||
ship.addShipOcean(new WaterShipOcean("2349058490584"));
|
ship.addWarpSea(new WaterShipWarp("2349058490584"));
|
||||||
ship.addShipOcean(new WaterShipOcean("7867834823244"));
|
ship.addWarpSea(new WaterShipWarp("7867834823244"));
|
||||||
ship.addShipOcean(new WaterShipOcean("3948758927389"));
|
ship.addWarpSea(new WaterShipWarp("3948758927389"));
|
||||||
|
|
||||||
device.buildShip(ship);
|
device.buildShip(ship);
|
||||||
|
|
||||||
|
|
|
@ -73,9 +73,9 @@
|
||||||
<instructions>
|
<instructions>
|
||||||
<_donotcopy>(.git)</_donotcopy>
|
<_donotcopy>(.git)</_donotcopy>
|
||||||
<Import-Package>org.osgi.framework,org.osgi.service.packageadmin,org.osgi.service.url,org.osgi.service.startlevel,org.osgi.util.tracker,*</Import-Package>
|
<Import-Package>org.osgi.framework,org.osgi.service.packageadmin,org.osgi.service.url,org.osgi.service.startlevel,org.osgi.util.tracker,*</Import-Package>
|
||||||
<Export-Package>love.distributedrebirth.gdxapp4d.tos4.service</Export-Package>
|
<Export-Package>
|
||||||
<Private-Package>love.distributedrebirth.gdxapp4d.tos4.*</Private-Package>
|
${tos4.packages}
|
||||||
<Embed-Dependency>*;artifactId=org.apache.felix.framework;inline=true,*;artifactId=gdxapp4d-lib-bassboonyd;inline=true</Embed-Dependency>
|
</Export-Package>
|
||||||
<Bundle-Activator>love.distributedrebirth.gdxapp4d.tos4.GDXAppTos4Activator</Bundle-Activator>
|
<Bundle-Activator>love.distributedrebirth.gdxapp4d.tos4.GDXAppTos4Activator</Bundle-Activator>
|
||||||
<Bundle-Vendor>distributedrebirth.love</Bundle-Vendor>
|
<Bundle-Vendor>distributedrebirth.love</Bundle-Vendor>
|
||||||
</instructions>
|
</instructions>
|
||||||
|
|
|
@ -230,6 +230,7 @@ public class GDXAppTos4Activator implements BundleActivator {
|
||||||
buf.append("BãßBȍőnAuthorInfoʸᴰ");
|
buf.append("BãßBȍőnAuthorInfoʸᴰ");
|
||||||
buf.append("@Ω仙⁴ ˧꜏⋇꜊꜔ ⁴ﷲΩ@");
|
buf.append("@Ω仙⁴ ˧꜏⋇꜊꜔ ⁴ﷲΩ@");
|
||||||
buf.append("בְּרֵאשִׁית :o: יְסוֺד :o: יִשְׂרָאֵל");
|
buf.append("בְּרֵאשִׁית :o: יְסוֺד :o: יִשְׂרָאֵל");
|
||||||
|
buf.append("⁰¹²³⁴⁵⁶⁷⁸⁹ˣᶜᴰ");
|
||||||
for (int c=0x0100;c<=0x0200;c++) {
|
for (int c=0x0100;c<=0x0200;c++) {
|
||||||
buf.append(""+(char)c);
|
buf.append(""+(char)c);
|
||||||
}
|
}
|
||||||
|
|
64
gdxapp4d-unitxc/pom.xml
Normal file
64
gdxapp4d-unitxc/pom.xml
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>love.distributedrebirth.gdxapp4d</groupId>
|
||||||
|
<artifactId>gdxapp4d</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>gdxapp4d-unitxc</artifactId>
|
||||||
|
<name>GDXApp⁴ᴰ-Unitˣᶜ</name>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>love.distributedrebirth.gdxapp4d</groupId>
|
||||||
|
<artifactId>gdxapp4d-tos4</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<exportScr>true</exportScr>
|
||||||
|
<niceManifest>true</niceManifest>
|
||||||
|
<instructions>
|
||||||
|
<_donotcopy>(.git)</_donotcopy>
|
||||||
|
<_dsannotations>*</_dsannotations>
|
||||||
|
<_metatypeannotations>*</_metatypeannotations>
|
||||||
|
<Import-Package>
|
||||||
|
${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
|
||||||
|
</Import-Package>
|
||||||
|
<Export-Package>
|
||||||
|
${unitxc.packages}
|
||||||
|
</Export-Package>
|
||||||
|
<Bundle-Activator>love.distributedrebirth.gdxapp4d.unitxc.UnitXrossConverterActivator</Bundle-Activator>
|
||||||
|
<Bundle-Vendor>distributedrebirth.love</Bundle-Vendor>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -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<SystemGdxLog> 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<SystemGdxLog> 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<String, String>());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<UnitXCConfigModule> 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<UnitXCConfigModule> 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<UnitXCConfigModule> configInit) {
|
||||||
|
return buildAll(new UnitXCConfig(), configInit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UnitXCManager createManager() {
|
||||||
|
return createManager(createConfig());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UnitXCManager createManager(UnitXCConfig config) {
|
||||||
|
return new UnitXCConfigManager(config);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
|
@ -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<String,UnitXCGroup> 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<String,UnitXCGroup> createUnitGroups(Collection<UnitXCGroup> values) {
|
||||||
|
Map<String,UnitXCGroup> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 <P> The parent builder.
|
||||||
|
* @param <T> The object to build.
|
||||||
|
* @param <B> This builder.
|
||||||
|
* @author Willem Cazander
|
||||||
|
* @version 1.0 Oct 22, 2015
|
||||||
|
*/
|
||||||
|
public abstract class AbstractUnitXCBuilder<P,T,B> implements Builder<P> {
|
||||||
|
|
||||||
|
private final P parent;
|
||||||
|
private final T value;
|
||||||
|
private final BiConsumer<P, T> parentBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the builder.
|
||||||
|
* @param parent The parent builder.
|
||||||
|
* @param value The object to build.
|
||||||
|
*/
|
||||||
|
public AbstractUnitXCBuilder(P parent,T value,BiConsumer<P, T> 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<T> mixer) {
|
||||||
|
mixer.accept(getValue());
|
||||||
|
return getBuilder();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<P,T extends AbstractUnitXCGroup,B> extends AbstractUnitXCBuilder<P,T,B> {
|
||||||
|
|
||||||
|
public AbstractUnitXCGroupBuilder(P parent, T model, BiConsumer<P, T> parentBuilder) {
|
||||||
|
super(parent, model, parentBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitXCGroupJumpBuilder<AbstractUnitXCGroupBuilder<P,T,B>> createGroupJump(String unitGroupId) {
|
||||||
|
return new UnitXCGroupJumpBuilder<>(this,getValue(),unitGroupId,(p,v) -> p.getValue().addGroupJump(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitXCTypeBuilder<AbstractUnitXCGroupBuilder<P,T,B>> 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));
|
||||||
|
// }
|
||||||
|
}
|
|
@ -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<P,B> extends AbstractUnitXCBuilder<P,DefaultUnitXCType,B> {
|
||||||
|
|
||||||
|
public AbstractUnitXCTypeBuilder(P parent,DefaultUnitXCType model,BiConsumer<P, DefaultUnitXCType> 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<String> flags) {
|
||||||
|
return make(v -> flags.forEach(flag -> v.getTypeFlags().add(flag)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public B addTypeFlags(String[] flags) {
|
||||||
|
return addTypeFlags(Arrays.asList(flags));
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitXConverterStepBuilder<AbstractUnitXCTypeBuilder<P,B>> createFromBaseConverterSteps() {
|
||||||
|
return new UnitXConverterStepBuilder<>(this,(p,v) -> p.addFromBaseConverterSteps(v),() -> "convert "+getValue().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitXConverterStepBuilder<AbstractUnitXCTypeBuilder<P,B>> 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<UnitXConverterStep> 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<UnitXConverterStep> unitTypeConverters) {
|
||||||
|
return make((v) -> unitTypeConverters.forEach(c -> v.getToBaseConverterSteps().add(c)));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 {
|
||||||
|
|
||||||
|
}
|
|
@ -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<UnitXCConfigBuilder,UnitXCGroupBase,UnitXCGroupBaseBuilder> {
|
||||||
|
|
||||||
|
public UnitXCGroupBaseBuilder(UnitXCConfigBuilder parent, UnitXCGroupBase model, BiConsumer<UnitXCConfigBuilder, UnitXCGroupBase> parentBuilder) {
|
||||||
|
super(parent, model, parentBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected UnitXCGroupBaseBuilder getBuilder() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitXCTypeSIPrefixBuilder<UnitXCGroupBaseBuilder> createSIUnitTypes() {
|
||||||
|
return new UnitXCTypeSIPrefixBuilder<>(this,this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<UnitXCConfigBuilder,UnitXCGroupCompoundExponent,UnitXCGroupCompoundExponentBuilder> {
|
||||||
|
|
||||||
|
public UnitXCGroupCompoundExponentBuilder(UnitXCConfigBuilder parent, UnitXCGroupCompoundExponent model, BiConsumer<UnitXCConfigBuilder, UnitXCGroupCompoundExponent> 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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<UnitXCConfigBuilder,UnitXCGroupCompoundPair,UnitXCGroupCompoundPairBuilder> {
|
||||||
|
|
||||||
|
public UnitXCGroupCompoundPairBuilder(UnitXCConfigBuilder parent, UnitXCGroupCompoundPair model, BiConsumer<UnitXCConfigBuilder, UnitXCGroupCompoundPair> 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();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<UnitXCConfigBuilder,AbstractUnitXCGroup,UnitXCGroupExtendBuilder> {
|
||||||
|
|
||||||
|
public UnitXCGroupExtendBuilder(UnitXCConfigBuilder parent, AbstractUnitXCGroup model, BiConsumer<UnitXCConfigBuilder, AbstractUnitXCGroup> parentBuilder) {
|
||||||
|
super(parent, model, parentBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected UnitXCGroupExtendBuilder getBuilder() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<P> extends AbstractUnitXCBuilder<P,DefaultUnitXCGroupJump,UnitXCGroupJumpBuilder<P>> {
|
||||||
|
|
||||||
|
public UnitXCGroupJumpBuilder(P parent, UnitXCGroup forGroup, String unitGroupId,BiConsumer<P, DefaultUnitXCGroupJump> parentBuilder) {
|
||||||
|
super(parent, new DefaultUnitXCGroupJump(), parentBuilder);
|
||||||
|
getValue().setUnitGroupId(unitGroupId);
|
||||||
|
getValue().setId(forGroup.getId()+"_"+unitGroupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected UnitXCGroupJumpBuilder<P> getBuilder() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitXCGroupJumpBuilder<P> setId(String id) {
|
||||||
|
return make((v) -> v.setId(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitXCGroupJumpBuilder<P> addJumpParameter(String id,String unitGroupId) {
|
||||||
|
return make((v) -> v.addJumpParameter(new DefaultUnitXCGroupJumpParameter(id, unitGroupId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitXConverterStepBuilder<UnitXCGroupJumpBuilder<P>> createToGroupConverterSteps() {
|
||||||
|
return new UnitXConverterStepBuilder<>(this,(p,v) -> getValue().getToGroupConverterSteps().addAll(v),() -> "group jump");
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<P> extends AbstractUnitXCTypeBuilder<P,UnitXCTypeBuilder<P>> {
|
||||||
|
|
||||||
|
public UnitXCTypeBuilder(P parent,DefaultUnitXCType model, BiConsumer<P, DefaultUnitXCType> parentBuilder) {
|
||||||
|
super(parent,model, parentBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected UnitXCTypeBuilder<P> getBuilder() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<String> flags;
|
||||||
|
private final List<String> 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<String> 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<String> 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<String> getFlags() {
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getNameAliases() {
|
||||||
|
return nameAliases;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<P> extends AbstractUnitXCTypeBuilder<P,UnitXCTypeSIPrefixBuilder<P>> {
|
||||||
|
|
||||||
|
private final UnitXCGroupBaseBuilder builder;
|
||||||
|
private final List<UnitXCTypeSIPrefix> commonSIPrefixes;
|
||||||
|
|
||||||
|
public UnitXCTypeSIPrefixBuilder(P parent, UnitXCGroupBaseBuilder builder) {
|
||||||
|
super(parent,new DefaultUnitXCType(), (p,v) -> {});
|
||||||
|
this.builder = builder;
|
||||||
|
this.commonSIPrefixes = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected UnitXCTypeSIPrefixBuilder<P> 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<String> 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<P> addCommonSIPrefixes(UnitXCTypeSIPrefix[] prefixes) {
|
||||||
|
return make(t -> addCommonSIPrefixes(Arrays.asList(prefixes)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitXCTypeSIPrefixBuilder<P> addCommonSIPrefixes(Collection<UnitXCTypeSIPrefix> prefixes) {
|
||||||
|
return make(t -> prefixes.forEach(prefix -> addCommonSIPrefix(prefix)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitXCTypeSIPrefixBuilder<P> addCommonSIPrefix(UnitXCTypeSIPrefix prefix) {
|
||||||
|
return make((v) -> commonSIPrefixes.add(prefix));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<P extends AbstractUnitXCBuilder<?,?,?>> extends AbstractUnitXCBuilder<P,List<UnitXConverterStep>,UnitXConverterStepBuilder<P>> {
|
||||||
|
|
||||||
|
private final Supplier<String> stepReason;
|
||||||
|
|
||||||
|
public UnitXConverterStepBuilder(P parent, BiConsumer<P, List<UnitXConverterStep>> parentBuilder, Supplier<String> stepReason) {
|
||||||
|
super(parent, new ArrayList<>(), parentBuilder);
|
||||||
|
this.stepReason = Validate.notNull(stepReason);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected UnitXConverterStepBuilder<P> 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<P> offsetUp(double offset,String stepReason) {
|
||||||
|
return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.ADD,new UnitXConverterStepValueReferenceDouble(offset))));
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> offsetDown(double offset,String stepReason) {
|
||||||
|
return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.SUBTRACT,new UnitXConverterStepValueReferenceDouble(offset))));
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> offsetUp(double offset) {
|
||||||
|
return offsetUp(offset,createStepReason());
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> offsetDown(double offset) {
|
||||||
|
return offsetDown(offset,createStepReason());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public UnitXConverterStepBuilder<P> multiply(Fraction fraction,String stepReason) {
|
||||||
|
return multiply(fraction.getNumerator(),fraction.getDenominator(),stepReason);
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> multiply(int numerator,int denominator,String stepReason) {
|
||||||
|
return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.MULTIPLY,new UnitXConverterStepValueReferenceDoubleFraction(numerator,denominator))));
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> multiply(Fraction fraction) {
|
||||||
|
return multiply(fraction,createStepReason());
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> multiply(int numerator,int denominator) {
|
||||||
|
return multiply(numerator,denominator,createStepReason());
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitXConverterStepBuilder<P> multiply(UnitXConverterStepValueRead factor,String stepReason) {
|
||||||
|
return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.MULTIPLY,factor)));
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> multiply(double factor,String stepReason) {
|
||||||
|
return multiply(new UnitXConverterStepValueReferenceDouble(factor),stepReason);
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> divide(UnitXConverterStepValueRead factor,String stepReason) {
|
||||||
|
return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.DIVIDE,factor)));
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> divide(double factor,String stepReason) {
|
||||||
|
return divide(new UnitXConverterStepValueReferenceDouble(factor),stepReason);
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> multiply(double factor) {
|
||||||
|
return multiply(factor,createStepReason());
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> multiply(UnitXConverterStepValueRead factor) {
|
||||||
|
return multiply(factor,createStepReason());
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> divide(UnitXConverterStepValueRead factor) {
|
||||||
|
return divide(factor,createStepReason());
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> divide(double factor) {
|
||||||
|
return divide(factor,createStepReason());
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitXConverterStepBuilder<P> power(double exponent,String stepReason) {
|
||||||
|
return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.POWER,new UnitXConverterStepValueReferenceDouble(exponent))));
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> power(double exponent) {
|
||||||
|
return power(exponent,createStepReason());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private UnitXConverterStepBuilder<P> powerOfTen(int exponent,boolean rev,String stepReason) {
|
||||||
|
return make(v -> v.add(new UnitXCConverterStepPowerOfTen(exponent,rev,UnitXConverterStepContext.createStepValue(),UnitXConverterStepContext.createStepValue()).buildReason(stepReason)));
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> power10Up(UnitXCTypeSIPrefix exponent,String stepReason) {
|
||||||
|
return powerOfTen(exponent.getExponent(), true,stepReason);
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> power10Down(UnitXCTypeSIPrefix exponent,String stepReason) {
|
||||||
|
return powerOfTen(exponent.getExponent(), false,stepReason);
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> power10Up(UnitXCTypeSIPrefix exponent) {
|
||||||
|
return power10Up(exponent,createStepReason());
|
||||||
|
}
|
||||||
|
public UnitXConverterStepBuilder<P> power10Down(UnitXCTypeSIPrefix exponent) {
|
||||||
|
return power10Down(exponent,createStepReason());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
|
@ -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;
|
|
@ -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<String, UnitXConverterParameterValue> 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<String,UnitXConverterParameterValue> parameters) {
|
||||||
|
return convertStepped(BigDecimal.valueOf(value), fromType, toType, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitXConverterResult convertStepped(BigDecimal value, UnitXCType fromType, UnitXCType toType, Map<String,UnitXConverterParameterValue> parameters) {
|
||||||
|
return convertEngine.convertStepped(value, fromType, toType, parameters);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<String,UnitXConverterParameterValue> 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<UnitXConverterResultStep> resultSteps = new ArrayList<>();
|
||||||
|
Map<String,UnitXConverterStepValueReadWrite> namedVariables = new HashMap<>();
|
||||||
|
Map<String,UnitXConverterStepValueRead> 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<UnitXConverterStep> 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;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
|
@ -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<UnitXCGroupQuantity> quantities;
|
||||||
|
private final List<String> derivedFrom;
|
||||||
|
private final List<UnitXCType> unitTypes;
|
||||||
|
private final List<UnitXCGroupJump> 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<String> localUnitTypeIds();
|
||||||
|
abstract UnitXCType localUnitType(String id);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
final public long getUnitTypeSize() {
|
||||||
|
return getUnitTypes().size() + localUnitTypeSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
final public Iterator<String> getUnitTypeIds() {
|
||||||
|
Iterator<String> l = localUnitTypeIds();
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
getUnitTypes().forEach(t -> result.add(t.getId()));
|
||||||
|
Iterator<String> g = result.iterator();
|
||||||
|
return new Iterator<String>() {
|
||||||
|
@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<UnitXCGroupQuantity> getQuantities() {
|
||||||
|
return quantities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addQuantity(UnitXCGroupQuantity quantity) {
|
||||||
|
this.quantities.add(quantity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the derivedFrom
|
||||||
|
*/
|
||||||
|
public List<String> getDerivedFrom() {
|
||||||
|
return derivedFrom;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param derivedFrom the derivedFrom to add
|
||||||
|
*/
|
||||||
|
public void addDerivedFrom(String derivedFrom) {
|
||||||
|
this.derivedFrom.add(derivedFrom);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the unit types.
|
||||||
|
*/
|
||||||
|
public List<UnitXCType> getUnitTypes() {
|
||||||
|
return unitTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addUnitType(DefaultUnitXCType type) {
|
||||||
|
Validate.notNull(type);
|
||||||
|
type.setUnitGroup(this);
|
||||||
|
type.validate();
|
||||||
|
unitTypes.add(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the groupJumps
|
||||||
|
*/
|
||||||
|
public List<UnitXCGroupJump> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<UnitXConverterStep> toGroupConverterSteps;
|
||||||
|
private final List<UnitXCGroupJumpParameter> 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<UnitXConverterStep> getToGroupConverterSteps() {
|
||||||
|
return toGroupConverterSteps;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param toGroupConverterSteps the toGroupConverterSteps to set
|
||||||
|
*/
|
||||||
|
public void setToBaseConverterSteps(List<UnitXConverterStep> toGroupConverterSteps) {
|
||||||
|
this.toGroupConverterSteps.clear();
|
||||||
|
this.toGroupConverterSteps.addAll(toGroupConverterSteps);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the jumpParameters
|
||||||
|
*/
|
||||||
|
public List<UnitXCGroupJumpParameter> getJumpParameters() {
|
||||||
|
return jumpParameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param jumpParameters the jumpParameters to set
|
||||||
|
*/
|
||||||
|
public void setJumpParameters(List<UnitXCGroupJumpParameter> jumpParameters) {
|
||||||
|
this.jumpParameters.clear();
|
||||||
|
this.jumpParameters.addAll(jumpParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addJumpParameter(UnitXCGroupJumpParameter jumpParameter) {
|
||||||
|
this.jumpParameters.add(Validate.notNull(jumpParameter));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<String> getLanguages() {
|
||||||
|
return bundle.getValueLanguages(getBundleKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getValue(String language) {
|
||||||
|
return bundle.getValue(language, getBundleKey());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<UnitXConverterStep> toBaseConverterSteps;
|
||||||
|
private final List<UnitXConverterStep> fromBaseConverterSteps;
|
||||||
|
private final List<String> 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<UnitXConverterStep> getToBaseConverterSteps() {
|
||||||
|
return toBaseConverterSteps;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param toBaseConverterSteps the toBaseConverterSteps to set
|
||||||
|
*/
|
||||||
|
public void setToBaseConverterSteps(List<UnitXConverterStep> toBaseConverterSteps) {
|
||||||
|
this.toBaseConverterSteps.clear();
|
||||||
|
this.toBaseConverterSteps.addAll(toBaseConverterSteps);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the fromBaseConverterSteps
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<UnitXConverterStep> getFromBaseConverterSteps() {
|
||||||
|
return fromBaseConverterSteps;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param fromBaseConverterSteps the fromBaseConverterSteps to set
|
||||||
|
*/
|
||||||
|
public void setFromBaseConverterSteps(List<UnitXConverterStep> fromBaseConverterSteps) {
|
||||||
|
this.fromBaseConverterSteps.clear();
|
||||||
|
this.fromBaseConverterSteps.addAll(fromBaseConverterSteps);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the typeFlags
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> getTypeFlags() {
|
||||||
|
return typeFlags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param typeFlags the typeFlags to set
|
||||||
|
*/
|
||||||
|
public void setTypeFlags(List<String> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<UnitXConverterResultStep> 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<UnitXConverterResultStep> getResultSteps() {
|
||||||
|
return resultSteps;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param resultSteps the resultSteps to set
|
||||||
|
*/
|
||||||
|
public void setResultSteps(List<UnitXConverterResultStep> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<UnitXCGroup> unitGroups;
|
||||||
|
private final List<Locale> 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<UnitXCGroup> getUnitGroups() {
|
||||||
|
return unitGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addUnitGroup(AbstractUnitXCGroup group) {
|
||||||
|
Validate.notNull(group);
|
||||||
|
group.validate();
|
||||||
|
unitGroups.add(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Locale> getLanguages() {
|
||||||
|
return languages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLanguage(Locale language) {
|
||||||
|
languages.add(Validate.notNull(language));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<UnitXCGroupQuantity> getQuantities();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the derivedFrom
|
||||||
|
*/
|
||||||
|
List<String> getDerivedFrom();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the groupJumps
|
||||||
|
*/
|
||||||
|
List<UnitXCGroupJump> getGroupJumps();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the totalUnitTypes
|
||||||
|
*/
|
||||||
|
long getUnitTypeSize();
|
||||||
|
|
||||||
|
Iterator<String> getUnitTypeIds();
|
||||||
|
|
||||||
|
UnitXCType getUnitType(String id);
|
||||||
|
}
|
|
@ -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<String> localUnitTypeIds() {
|
||||||
|
return Collections.emptyIterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UnitXCType localUnitType(String id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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<String> localUnitTypeIds() {
|
||||||
|
Iterator<String> g = getParentGroup().getUnitTypeIds();
|
||||||
|
return new Iterator<String>() {
|
||||||
|
@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<Object> typeBuilder = new UnitXCTypeBuilder<>(this,result,(p,v) -> {});
|
||||||
|
typeBuilder
|
||||||
|
.setId(unitType.getId()+unitIdPostfix)
|
||||||
|
.setName(unitNamePrefix+unitType.getName())
|
||||||
|
.addTypeFlags(unitType.getTypeFlags());
|
||||||
|
|
||||||
|
for (int i=0;i<exponent;i++) {
|
||||||
|
typeBuilder.addToBaseConverterStep(new UnitXCConverterStepReference(unitType,true));
|
||||||
|
typeBuilder.addFromBaseConverterStep(new UnitXCConverterStepReference(unitType,false));
|
||||||
|
}
|
||||||
|
typeBuilder.build();
|
||||||
|
result.setUnitGroup(this);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the exponent
|
||||||
|
*/
|
||||||
|
public int getExponent() {
|
||||||
|
return exponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the unitIdPostfix
|
||||||
|
*/
|
||||||
|
public String getUnitIdPostfix() {
|
||||||
|
return unitIdPostfix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param unitIdPostfix the unitIdPostfix to set
|
||||||
|
*/
|
||||||
|
public void setUnitIdPostfix(String unitIdPostfix) {
|
||||||
|
this.unitIdPostfix = unitIdPostfix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the unitNamePrefix
|
||||||
|
*/
|
||||||
|
public String getUnitNamePrefix() {
|
||||||
|
return unitNamePrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param unitNamePrefix the unitNamePrefix to set
|
||||||
|
*/
|
||||||
|
public void setUnitNamePrefix(String unitNamePrefix) {
|
||||||
|
this.unitNamePrefix = unitNamePrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the parentGroup
|
||||||
|
*/
|
||||||
|
public UnitXCGroup getParentGroup() {
|
||||||
|
return parentGroup;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,181 @@
|
||||||
|
/*
|
||||||
|
* 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 UnitXCGroupCompoundPair extends AbstractUnitXCGroup {
|
||||||
|
|
||||||
|
public static final String PER_ID = "/";
|
||||||
|
public static final String PER_NAME = " per ";
|
||||||
|
|
||||||
|
private final UnitXCGroup parentGroup;
|
||||||
|
private final UnitXCGroup parentPerGroup;
|
||||||
|
|
||||||
|
public UnitXCGroupCompoundPair(UnitXCResourceBundle bundle, String id,UnitXCGroup parentGroup,UnitXCGroup parentPerGroup) {
|
||||||
|
super(bundle, id);
|
||||||
|
this.parentGroup = Validate.notNull(parentGroup);
|
||||||
|
this.parentPerGroup = Validate.notNull(parentPerGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long localUnitTypeSize() {
|
||||||
|
return getParentGroup().getUnitTypeSize()*getParentPerGroup().getUnitTypeSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<String> localUnitTypeIds() {
|
||||||
|
Iterator<String> groupIt = getParentGroup().getUnitTypeIds();
|
||||||
|
return new Iterator<String>() {
|
||||||
|
|
||||||
|
String groupId2;
|
||||||
|
Iterator<String> 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<units.length;i++) {
|
||||||
|
StringBuilder idGroup = new StringBuilder();
|
||||||
|
StringBuilder idGroupPer = new StringBuilder();
|
||||||
|
|
||||||
|
for (int ii=0;ii<i;ii++) {
|
||||||
|
idGroup.append(units[ii]);
|
||||||
|
if (ii+1<i) {
|
||||||
|
idGroup.append(PER_ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String checkExponent = null;
|
||||||
|
boolean checkExponentUse = false;
|
||||||
|
for (int ii=i;ii<units.length;ii++) {
|
||||||
|
if (checkExponent!=null && !checkExponent.equals(units[ii])) {
|
||||||
|
checkExponentUse = true;
|
||||||
|
}
|
||||||
|
checkExponent = units[ii];
|
||||||
|
|
||||||
|
idGroupPer.append(units[ii]);
|
||||||
|
if (ii+1<units.length) {
|
||||||
|
idGroupPer.append(PER_ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (checkExponentUse) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
UnitXCType result = getUnitType(id,idGroup.toString(),idGroupPer.toString());
|
||||||
|
if (result != null) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
//String idGroup = id.substring(0,id.lastIndexOf(PER_ID)); // FIXME parse correctly see newton
|
||||||
|
//String idGroupPer = id.substring(id.lastIndexOf(PER_ID)+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private UnitXCType getUnitType(String id,String idGroup,String idGroupPer) {
|
||||||
|
// System.out.println("checking: "+idGroup+" and "+idGroupPer);
|
||||||
|
UnitXCType unitType = getParentGroup().getUnitType(idGroup);
|
||||||
|
if (unitType == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
UnitXCType perUnitType = getParentPerGroup().getUnitType(idGroupPer);
|
||||||
|
if (perUnitType == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return createUnitType(id, unitType, perUnitType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private UnitXCType createUnitType(String id,UnitXCType unitType,UnitXCType perUnitType) {
|
||||||
|
// TODO: add name/name alias
|
||||||
|
DefaultUnitXCType result = new DefaultUnitXCType();
|
||||||
|
UnitXCTypeBuilder<Object> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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<UnitXConverterStep> getToGroupConverterSteps();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the jumpParameters
|
||||||
|
*/
|
||||||
|
List<UnitXCGroupJumpParameter> getJumpParameters();
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
|
@ -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<String> getDerivedFrom();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the totalUnitTypes
|
||||||
|
*/
|
||||||
|
long getUnitTypeSize();
|
||||||
|
|
||||||
|
Iterator<String> getUnitTypeIds();
|
||||||
|
|
||||||
|
UnitXCType getUnitType(String id);
|
||||||
|
}
|
|
@ -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();
|
||||||
|
// }
|
||||||
|
}
|
|
@ -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<String,Map<String,String>> data = new HashMap<>();
|
||||||
|
|
||||||
|
// FIXME: not public or interface or x
|
||||||
|
public void addData(String language,String key,String value) {
|
||||||
|
Map<String,String> ld = data.get(language);
|
||||||
|
if (ld == null) {
|
||||||
|
ld = new HashMap<>();
|
||||||
|
data.put(language, ld);
|
||||||
|
}
|
||||||
|
ld.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getLanguages() {
|
||||||
|
return new ArrayList<>(data.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getValueLanguages(String key) {
|
||||||
|
List<String> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<String> getLanguages();
|
||||||
|
|
||||||
|
String getValue(String language);
|
||||||
|
}
|
|
@ -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 */
|
||||||
|
}
|
|
@ -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<UnitXConverterStep> getToBaseConverterSteps();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the fromBaseConverterSteps
|
||||||
|
*/
|
||||||
|
List<UnitXConverterStep> getFromBaseConverterSteps();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the typeFlags
|
||||||
|
*/
|
||||||
|
List<String> getTypeFlags();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the weblink
|
||||||
|
*/
|
||||||
|
String getWebLink();
|
||||||
|
}
|
|
@ -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<UnitXConverterResultStep> getResultSteps();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the resultValue
|
||||||
|
*/
|
||||||
|
Double getResultValue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the convertTime
|
||||||
|
*/
|
||||||
|
Long getConvertTime();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the startTypeId
|
||||||
|
*/
|
||||||
|
String getStartTypeId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the resultTypeId
|
||||||
|
*/
|
||||||
|
String getResultTypeId();
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
|
@ -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;
|
|
@ -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<String> stepReasons;
|
||||||
|
|
||||||
|
protected AbstractUnitXConverterStep() {
|
||||||
|
this.stepReasons = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractUnitXConverterStep buildReason(String reason) {
|
||||||
|
addStepReason(reason);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final List<String> getStepReasons() {
|
||||||
|
return stepReasons;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setStepReasons(List<String> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<UnitXConverterStep> 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<UnitXConverterStep> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package net.forwardfire.unitxc.model.step;
|
||||||
|
|
||||||
|
public enum RuleStepCodeStyle {
|
||||||
|
ENGLISH,
|
||||||
|
JAVASCRIPT
|
||||||
|
;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<UnitXConverterStep> 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<RuleStepConditionExpression> expressions*/) {
|
||||||
|
printer.appendJS(" ( ");
|
||||||
|
getEquality().toRuleCode(printer, operandA, operandB);
|
||||||
|
printer.appendJS(" ) ");
|
||||||
|
|
||||||
|
// Iterator<RuleStepConditionExpression> 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<UnitXConverterStep> getConditionalSteps() {
|
||||||
|
return conditionalSteps;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param conditionalSteps the conditionalSteps to set
|
||||||
|
*/
|
||||||
|
public void setConditionalSteps(List<UnitXConverterStep> conditionalSteps) {
|
||||||
|
this.conditionalSteps.clear();
|
||||||
|
this.conditionalSteps.addAll(conditionalSteps);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<Double,Double,Boolean> opertionDouble; // TODO: convert to IntPredicate
|
||||||
|
private final BiFunction<Integer,Integer,Boolean> opertionInteger;
|
||||||
|
private final BiFunction<String,String,Boolean> opertionString;
|
||||||
|
|
||||||
|
private UnitXCConverterStepConditionEquality(String jsCode, BiFunction<Double,Double,Boolean> opertionDouble,BiFunction<Integer,Integer,Boolean> opertionInteger,BiFunction<String,String,Boolean> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<Double> opertionDouble;
|
||||||
|
private final BinaryOperator<Integer> opertionInteger;
|
||||||
|
private final BinaryOperator<String> opertionString;
|
||||||
|
|
||||||
|
private UnitXCConverterStepOperationOperator(String jsCode, BinaryOperator<Double> opertionDouble,BinaryOperator<Integer> opertionInteger,BinaryOperator<String> 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;i<r;i++) {
|
||||||
|
l = l * l;
|
||||||
|
}
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object 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()) {
|
||||||
|
printer.append(enCode," ");
|
||||||
|
operandA.toRuleCodeRead(printer);
|
||||||
|
printer.append(" and ");
|
||||||
|
operandB.toRuleCodeRead(printer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (POWER.equals(this)) {
|
||||||
|
printer.append(jsCode,"(");
|
||||||
|
operandA.toRuleCodeRead(printer);
|
||||||
|
printer.append(", ");
|
||||||
|
operandB.toRuleCodeRead(printer);
|
||||||
|
printer.append(")");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
operandA.toRuleCodeRead(printer);
|
||||||
|
printer.appendSpace();
|
||||||
|
printer.append(jsCode);
|
||||||
|
printer.appendSpace();
|
||||||
|
operandB.toRuleCodeRead(printer);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,163 @@
|
||||||
|
/*
|
||||||
|
* 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 UnitXCConverterStepPowerOfTen extends AbstractUnitXConverterStep {
|
||||||
|
|
||||||
|
private UnitXConverterStepValueRead operand;
|
||||||
|
private UnitXConverterStepValueReadWrite result;
|
||||||
|
private int exponent;
|
||||||
|
private boolean exponentReverse;
|
||||||
|
|
||||||
|
public UnitXCConverterStepPowerOfTen() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitXCConverterStepPowerOfTen(int exponent,boolean exponentReverse,UnitXConverterStepValueRead operand,UnitXConverterStepValueReadWrite result) {
|
||||||
|
this();
|
||||||
|
setExponent(exponent);
|
||||||
|
setExponentReverse(exponentReverse);
|
||||||
|
setOperand(operand);
|
||||||
|
setResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runStep(UnitXConverterStepContext ctx) {
|
||||||
|
result.valueWrite(ctx, convert((Double)operand.valueRead(ctx)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toRuleCode(RuleStepCodePrinter printer) {
|
||||||
|
if (printer.isEnglish()) {
|
||||||
|
printer.lineStart("Update ");
|
||||||
|
getResult().toRuleCodeWrite(printer);
|
||||||
|
printer.append(" with value from ");
|
||||||
|
printer.append(" * ");
|
||||||
|
if (exponentReverse) {
|
||||||
|
printer.append(" -1? "); // TODO: fix reverse
|
||||||
|
}
|
||||||
|
printer.append(" 10^", Integer.toString(exponent));
|
||||||
|
printer.lineEnd(".");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printer.lineStart();
|
||||||
|
getResult().toRuleCodeWrite(printer);
|
||||||
|
printer.append(" = ");
|
||||||
|
getOperand().toRuleCodeRead(printer);
|
||||||
|
printer.append(" * ");
|
||||||
|
if (exponentReverse) {
|
||||||
|
printer.append(" -1? "); // TODO: fix reverse
|
||||||
|
}
|
||||||
|
printer.append(" 10^", Integer.toString(exponent));
|
||||||
|
printer.lineEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double convert(double value) {
|
||||||
|
int exponentShift = exponent<0?0-exponent:exponent;
|
||||||
|
for (int i=0;i<exponentShift;i++) {
|
||||||
|
value = shiftDotStatic(value,exponentReverse?!(exponent>0):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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<UnitXConverterStep> 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;
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue