From 3acc28dbbf5e4d20252dc4918aeda32198d86d34 Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 13 Oct 2022 14:38:07 +0200 Subject: [PATCH] Cached length --- .../app/calculator/CalculatorComponent.java | 2 +- .../app/glyphdemo/GlyphDemoComponent.java | 2 +- .../apps/DemoUnitConverterDeskApp.java | 11 ++-- .../bassboonyd/BãßBȍőnInitMarkerʸᴰ.java | 5 ++ .../bassboonyd/DefaultEnumSetʸᴰ.java | 8 --- .../bassboonyd/DefaultInitMethodʸᴰ.java | 53 +++++++++++++++++-- .../base2t/part/BãßBȍőnPartKeyʸᴰ.java | 1 + .../numberxd/base2t/part/BãßBȍőnPartʸᴰ.java | 43 +++++++++++---- .../gdxapp4d/tos4/GDXAppTos4Activator.java | 1 - 9 files changed, 97 insertions(+), 29 deletions(-) create mode 100644 gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboonyd/BãßBȍőnInitMarkerʸᴰ.java diff --git a/gdxapp4d-app-calculator/src/main/java/love/distributedrebirth/gdxapp4d/app/calculator/CalculatorComponent.java b/gdxapp4d-app-calculator/src/main/java/love/distributedrebirth/gdxapp4d/app/calculator/CalculatorComponent.java index 87ba5607..cfe1aa77 100644 --- a/gdxapp4d-app-calculator/src/main/java/love/distributedrebirth/gdxapp4d/app/calculator/CalculatorComponent.java +++ b/gdxapp4d-app-calculator/src/main/java/love/distributedrebirth/gdxapp4d/app/calculator/CalculatorComponent.java @@ -31,7 +31,7 @@ public class CalculatorComponent { private final DeskAppLauncher launcher; public CalculatorComponent() { - launcher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Calculator", () -> new CalculatorDeskApp(createBundle())); + launcher = new DeskAppLauncher(DeskAppMenuSection.SCIENCE, "Calculator", () -> new CalculatorDeskApp(createBundle())); } private ResourceBundle createBundle() { diff --git a/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/GlyphDemoComponent.java b/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/GlyphDemoComponent.java index e14d6535..382f0221 100644 --- a/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/GlyphDemoComponent.java +++ b/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/GlyphDemoComponent.java @@ -49,7 +49,7 @@ public class GlyphDemoComponent { unicodeLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Unicode Plane", () -> new DemoUnicodePlaneDeskApp(createBundle(), unicode4DService)); baseGlyphLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Glyph Set", () -> new DemoGlyphSetDeskApp(createBundle())); basePartLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Number Parts", () -> new DemoNumberPartDeskApp(createBundle())); - unitConverterLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Unitˣᶜ Converter", () -> new DemoUnitConverterDeskApp(unitManager)); + unitConverterLauncher = new DeskAppLauncher(DeskAppMenuSection.SCIENCE, "Unitˣᶜ Converter", () -> new DemoUnitConverterDeskApp(unitManager)); } private ResourceBundle createBundle() { diff --git a/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/apps/DemoUnitConverterDeskApp.java b/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/apps/DemoUnitConverterDeskApp.java index 32103bae..8e9d08de 100644 --- a/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/apps/DemoUnitConverterDeskApp.java +++ b/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/apps/DemoUnitConverterDeskApp.java @@ -1,5 +1,6 @@ package love.distributedrebirth.gdxapp4d.app.glyphdemo.apps; +import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -16,6 +17,8 @@ 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 love.distributedrebirth.numberxd.base2t.part.T10PartDecimal; +import love.distributedrebirth.numberxd.base2t.part.T16PartHex; import net.forwardfire.unitxc.UnitXCManager; import net.forwardfire.unitxc.model.UnitXCGroup; import net.forwardfire.unitxc.model.UnitXCType; @@ -34,7 +37,7 @@ public class DemoUnitConverterDeskApp extends AbstractDeskApp implements DeskApp private final ImInt convertFromType = new ImInt(); private final ImInt unitTypeLimit = new ImInt(5432); private final List convertFromTypes; - private final long totalUnits; + private final BigInteger totalUnits; private String[] convertFromTypeNames; public DemoUnitConverterDeskApp(UnitXCManager unitManager) { @@ -60,7 +63,7 @@ public class DemoUnitConverterDeskApp extends AbstractDeskApp implements DeskApp long tc = typeGroup.getUnitTypeSize(); ts += tc; } - this.totalUnits = ts; + this.totalUnits = BigInteger.valueOf(ts); // TODO: goto DEC144 for counting unit types updateConvertFromType(); updateUnitType(); @@ -73,7 +76,9 @@ public class DemoUnitConverterDeskApp extends AbstractDeskApp implements DeskApp @Override public void render() { - ImGui.text("Total units loaded: "+totalUnits); + String amount10 = totalUnits.toString(T10PartDecimal.DEFAULT.BãßĦǿɇṽḝę̃ɬḪễïđ()); + String amount16 = totalUnits.toString(T16PartHex.DEFAULT.BãßĦǿɇṽḝę̃ɬḪễïđ()); + ImGui.text("Total units loaded: "+amount10+" ("+amount16+")"); // TODO: don't do update on render thread if (ImGui.inputDouble("ConvertValue", convertValue)) { diff --git a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboonyd/BãßBȍőnInitMarkerʸᴰ.java b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboonyd/BãßBȍőnInitMarkerʸᴰ.java new file mode 100644 index 00000000..22a9428a --- /dev/null +++ b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboonyd/BãßBȍőnInitMarkerʸᴰ.java @@ -0,0 +1,5 @@ +package love.distributedrebirth.bassboonyd; + +@BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") +public interface BãßBȍőnInitMarkerʸᴰ { +} diff --git a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboonyd/DefaultEnumSetʸᴰ.java b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboonyd/DefaultEnumSetʸᴰ.java index d2aadb0e..28f5ef1b 100644 --- a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboonyd/DefaultEnumSetʸᴰ.java +++ b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboonyd/DefaultEnumSetʸᴰ.java @@ -18,14 +18,6 @@ public interface DefaultEnumSetʸᴰ extends DefaultEnumBaseʸᴰ { return ordinal() + 1; } - default int LENGTH() { - return BãßĦǿɇṽḝę̃ɬḪễïđ(); - } - - default int BãßĦǿɇṽḝę̃ɬḪễïđ() { - return BãßInstances().length; - } - default List BãßInstancesList() { return Arrays.asList(BãßInstances()); } diff --git a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboonyd/DefaultInitMethodʸᴰ.java b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboonyd/DefaultInitMethodʸᴰ.java index ae13a11c..82efec23 100644 --- a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboonyd/DefaultInitMethodʸᴰ.java +++ b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboonyd/DefaultInitMethodʸᴰ.java @@ -1,20 +1,63 @@ package love.distributedrebirth.bassboonyd; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.LinkedHashSet; +import java.util.Set; @BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") @BãßBȍőnAnnotationInfoʸᴰ(required = {}) public interface DefaultInitMethodʸᴰ { default void BOON_INIT(Object boon) { - try { - for (Method m:boon.getClass().getMethods()) { - if (m.isAnnotationPresent(BãßBȍőnInitMethodʸᴰ.class)) { - m.invoke(boon, this); + + final class InitScanner { + + public void scanInterfaces(Object boon, Object bbc) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + for (Class interfaceClass:walkInterfaces(boon.getClass(), new LinkedHashSet<>())) { + for (Class declaredClass:((Class) interfaceClass).getDeclaredClasses()) { + initStaticMarker(declaredClass, bbc); + } } } + + public void scanClass(Object boon, Object bbc) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + for (Class declaredClass:boon.getClass().getDeclaredClasses()) { + initStaticMarker(declaredClass, bbc); + } + } + + private void initStaticMarker(Class declaredClass, Object bbc) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + if (!BãßBȍőnInitMarkerʸᴰ.class.isAssignableFrom(declaredClass)) { + return; + } + for (Method m:declaredClass.getDeclaredMethods()) { + if (m.isAnnotationPresent(BãßBȍőnInitMethodʸᴰ.class)) { + m.setAccessible(true); + m.invoke(null, bbc); + } + } + } + + private Set> walkInterfaces(Class clazz, Set> result) { + while (clazz != null) { + for (Class next : clazz.getInterfaces()) { + if (result.add(next)) { + return walkInterfaces(next, result); + } + } + clazz = clazz.getSuperclass(); + } + return result; + } + } + + InitScanner init = new InitScanner(); + try { + init.scanInterfaces(boon, this); + init.scanClass(boon, this); } catch (Exception e) { throw new RuntimeException(e); - } + } } } diff --git a/gdxapp4d-lib-numberxd/src/main/java/love/distributedrebirth/numberxd/base2t/part/BãßBȍőnPartKeyʸᴰ.java b/gdxapp4d-lib-numberxd/src/main/java/love/distributedrebirth/numberxd/base2t/part/BãßBȍőnPartKeyʸᴰ.java index a55b27d3..5cb969e2 100644 --- a/gdxapp4d-lib-numberxd/src/main/java/love/distributedrebirth/numberxd/base2t/part/BãßBȍőnPartKeyʸᴰ.java +++ b/gdxapp4d-lib-numberxd/src/main/java/love/distributedrebirth/numberxd/base2t/part/BãßBȍőnPartKeyʸᴰ.java @@ -13,6 +13,7 @@ public enum BãßBȍőnPartKeyʸᴰ implements BãßBȍőnCoffinStoreKeyʸᴰ { MAP_TONE, MAP_CHINA, + MAP_CACHE, ALT_1_VALUE, ALT_2_VALUE, diff --git a/gdxapp4d-lib-numberxd/src/main/java/love/distributedrebirth/numberxd/base2t/part/BãßBȍőnPartʸᴰ.java b/gdxapp4d-lib-numberxd/src/main/java/love/distributedrebirth/numberxd/base2t/part/BãßBȍőnPartʸᴰ.java index e58a26c8..14493de4 100644 --- a/gdxapp4d-lib-numberxd/src/main/java/love/distributedrebirth/numberxd/base2t/part/BãßBȍőnPartʸᴰ.java +++ b/gdxapp4d-lib-numberxd/src/main/java/love/distributedrebirth/numberxd/base2t/part/BãßBȍőnPartʸᴰ.java @@ -5,22 +5,13 @@ import java.util.Map; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.bassboonyd.BãßBȍőnCoffinOpenʸᴰ; import love.distributedrebirth.bassboonyd.BãßBȍőnCoffinStoreʸᴰ; +import love.distributedrebirth.bassboonyd.BãßBȍőnInitMarkerʸᴰ; import love.distributedrebirth.bassboonyd.DefaultEnumSetʸᴰ; import love.distributedrebirth.bassboonyd.BãßBȍőnInitMethodʸᴰ; @BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") public interface BãßBȍőnPartʸᴰ> extends DefaultEnumSetʸᴰ, BãßBȍőnCoffinStoreʸᴰ { - @BãßBȍőnInitMethodʸᴰ - default void initMapTone(BãßBȍőnCoffinOpenʸᴰ BBC) { - BBC.PUT_MAP(BãßBȍőnPartKeyʸᴰ.MAP_TONE); - } - - @BãßBȍőnInitMethodʸᴰ - default void initMapChina(BãßBȍőnCoffinOpenʸᴰ BBC) { - BBC.PUT_MAP(BãßBȍőnPartKeyʸᴰ.MAP_CHINA); - } - default String BȍőnDialTone() { return GET_BBC().GET_STR(BãßBȍőnPartKeyʸᴰ.DIAL_TONE); } @@ -50,4 +41,36 @@ public interface BãßBȍőnPartʸᴰ> extends } return (T) mapChina.get(chinaKey); } + + public static class Init implements BãßBȍőnInitMarkerʸᴰ { + + @BãßBȍőnInitMethodʸᴰ + private static void initMapTone(BãßBȍőnCoffinOpenʸᴰ BBC) { + BBC.PUT_MAP(BãßBȍőnPartKeyʸᴰ.MAP_TONE); + } + + @BãßBȍőnInitMethodʸᴰ + private static void initMapChina(BãßBȍőnCoffinOpenʸᴰ BBC) { + BBC.PUT_MAP(BãßBȍőnPartKeyʸᴰ.MAP_CHINA); + } + + @BãßBȍőnInitMethodʸᴰ + private static void initMapCache(BãßBȍőnCoffinOpenʸᴰ BBC) { + BBC.PUT_MAP(BãßBȍőnPartKeyʸᴰ.MAP_CACHE); + } + } + + public static class MapCacheKey { + private static final String LENGTH = "length"; + } + + default int BãßĦǿɇṽḝę̃ɬḪễïđ() { + Map mapCache = GET_BBC().GET_MAP_OBJ(BãßBȍőnPartKeyʸᴰ.MAP_CACHE); + Integer length = Integer.class.cast(mapCache.get(MapCacheKey.LENGTH)); + if (length == null) { + length = BãßInstances().length; + mapCache.put(MapCacheKey.LENGTH, length); + } + return length; + } } diff --git a/gdxapp4d-tos4/src/main/java/love/distributedrebirth/gdxapp4d/tos4/GDXAppTos4Activator.java b/gdxapp4d-tos4/src/main/java/love/distributedrebirth/gdxapp4d/tos4/GDXAppTos4Activator.java index 3a35036f..e5aaec85 100644 --- a/gdxapp4d-tos4/src/main/java/love/distributedrebirth/gdxapp4d/tos4/GDXAppTos4Activator.java +++ b/gdxapp4d-tos4/src/main/java/love/distributedrebirth/gdxapp4d/tos4/GDXAppTos4Activator.java @@ -208,7 +208,6 @@ public class GDXAppTos4Activator implements BundleActivator { } bootScreen.bootLine("gdx-font: "+parameter.characters.length()+" glyphs loaded."); - context.registerService(SystemGdxFont.class.getName(), new SystemGdxFontImpl(gdxFont), new Hashtable()); context.registerService(SystemGdxLog.class.getName(), systemGdxLog, new Hashtable()); context.registerService(SystemGdxBootArgs.class.getName(), new SystemGdxBootArgsImpl(), new Hashtable());