From f51a97f44964a21e8ba2f8eb7b21cb7ad6cbc90b Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Fri, 28 Jan 2022 11:19:52 +0100 Subject: [PATCH] Added base2 terminator code. --- .../demo4d/base2t/Base2Terminator.java | 97 +++++++++++++++++++ .../demo4d/base2t/BaseAppender.java | 6 ++ .../demo4d/base2t/BaseNumber.java | 17 ++++ .../demo4d/base2t/BaseNumberTyte.java | 6 ++ .../demo4d/base2t/BasePartIdentifier.java | 6 ++ .../demo4d/base2t/BasePartIdentifierAlt.java | 8 ++ .../base2t/BasePartIdentifierAltInfo.java | 20 ++++ .../demo4d/base2t/BasePartIdentifierTone.java | 6 ++ .../demo4d/base2t/T02PartBinary.java | 35 +++++++ .../demo4d/base2t/T03PartTrit.java | 36 +++++++ .../demo4d/base2t/T04PartQuad.java | 55 +++++++++++ .../demo4d/base2t/T05PartPental.java | 52 ++++++++++ .../demo4d/base2t/T06PartSeximal.java | 61 ++++++++++++ .../demo4d/base2t/T08PartOctal.java | 74 ++++++++++++++ .../base2t/T08PartOctalBaseAppender.java | 17 ++++ .../demo4d/base2t/T08PartOctalIterator.java | 22 +++++ .../demo4d/base2t/T12PartUncial.java | 52 ++++++++++ .../demo4d/base2t/T16PartHex.java | 67 +++++++++++++ .../demo4d/base2t/T20PartScore.java | 60 ++++++++++++ .../demo4d/base2t/V003Timble.java | 36 +++++++ .../demo4d/base2t/V006Tixte.java | 37 +++++++ .../demo4d/base2t/V009Tyte.java | 47 +++++++++ .../demo4d/base2t/V009TyteBaseAppender.java | 17 ++++ .../demo4d/base2t/V009TyteIterator.java | 22 +++++ .../demo4d/base2t/V018Tord.java | 54 +++++++++++ .../demo4d/base2t/V027Temvig.java | 47 +++++++++ .../demo4d/base2t/V036Teger.java | 56 +++++++++++ .../demo4d/base2t/V072Tong.java | 46 +++++++++ .../demo4d/base2t/V144Tocta.java | 72 ++++++++++++++ 29 files changed, 1131 insertions(+) create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/Base2Terminator.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/BaseAppender.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/BaseNumber.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/BaseNumberTyte.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifier.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifierAlt.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifierAltInfo.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifierTone.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/T02PartBinary.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/T03PartTrit.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/T04PartQuad.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/T05PartPental.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/T06PartSeximal.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/T08PartOctal.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/T08PartOctalBaseAppender.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/T08PartOctalIterator.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/T12PartUncial.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/T16PartHex.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/T20PartScore.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/V003Timble.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/V006Tixte.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/V009Tyte.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/V009TyteBaseAppender.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/V009TyteIterator.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/V018Tord.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/V027Temvig.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/V036Teger.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/V072Tong.java create mode 100644 core/src/love/distributedrebirth/demo4d/base2t/V144Tocta.java diff --git a/core/src/love/distributedrebirth/demo4d/base2t/Base2Terminator.java b/core/src/love/distributedrebirth/demo4d/base2t/Base2Terminator.java new file mode 100644 index 00000000..0023d628 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/Base2Terminator.java @@ -0,0 +1,97 @@ +package love.distributedrebirth.demo4d.base2t; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class Base2Terminator { + private static final int STREAM_EOF = -1; + private static final int BLOCK_TONG_SIZE = 18; + private static final int BLOCK_TOCTA_SIZE = 18; + private static final int SHIFT_8 = 8; + private static final int SHIFT_16 = 16; + + public int base2ReadTong(InputStream input, List output) throws IOException { + int totalBytes = 0; + byte[] data = new byte[BLOCK_TONG_SIZE]; + int readDataSize = 0; // per 9 bytes we have 24 octals for one V072Tong number + while ((readDataSize = input.read(data, 0, data.length)) != STREAM_EOF) { + base2ReadCheckSize(readDataSize, BLOCK_TONG_SIZE); + int v0 = data[0] + (data[1] << SHIFT_8) + (data[2] << SHIFT_16); + int v1 = data[3] + (data[4] << SHIFT_8) + (data[5] << SHIFT_16); + int v2 = data[6] + (data[7] << SHIFT_8) + (data[8] << SHIFT_16); + List octals = base2ReadOctals(v0, v1, v2); + output.add(new V072Tong(new T08PartOctalIterator(octals.iterator()))); + totalBytes += BLOCK_TONG_SIZE; + } + return totalBytes; + } + + public int base2ReadTocta(InputStream input, List output) throws IOException { + int totalBytes = 0; + byte[] data = new byte[BLOCK_TOCTA_SIZE]; + int readDataSize = 0; // per 18 bytes we have 48 octals for one V144Tocta number + while ((readDataSize = input.read(data, 0, data.length)) != STREAM_EOF) { + base2ReadCheckSize(readDataSize, BLOCK_TOCTA_SIZE); + int v0 = data[0] + (data[1] << SHIFT_8) + (data[2] << SHIFT_16); + int v1 = data[3] + (data[4] << SHIFT_8) + (data[5] << SHIFT_16); + int v2 = data[6] + (data[7] << SHIFT_8) + (data[8] << SHIFT_16); + int v3 = data[9] + (data[10] << SHIFT_8) + (data[11] << SHIFT_16); + int v4 = data[12] + (data[13] << SHIFT_8) + (data[14] << SHIFT_16); + int v5 = data[15] + (data[16] << SHIFT_8) + (data[17] << SHIFT_16); + List octals = base2ReadOctals(v0, v1, v2, v3, v4, v5); + output.add(new V144Tocta(new T08PartOctalIterator(octals.iterator()))); + totalBytes += BLOCK_TOCTA_SIZE; + } + return totalBytes; + } + + private void base2ReadCheckSize(int readDataSize, int expectedSize) throws IOException { + if (readDataSize < expectedSize) { + throw new IOException("Expected "+expectedSize+" bytes, got: "+readDataSize); + } + } + + private List base2ReadOctals(int...values) { + List octals = new ArrayList<>(); + for (int value:values) { + T08PartOctal.forEach(v -> octals.add(T08PartOctal.indexOf(v, value))); + } + return octals; + } + + public int base2WriteTong(List data, OutputStream output) throws IOException { + return base2Write(data, output); + } + + public int base2WriteTocta(List data, OutputStream output) throws IOException { + return base2Write(data, output); + } + + private > int base2Write(List data, OutputStream output) throws IOException { + int totalBytes = 0; // per 8 octa's is 3 bytes + List octals = new ArrayList<>(); + T08PartOctalBaseAppender appender = new T08PartOctalBaseAppender(octals); + data.forEach(v -> v.fillOctalValues(appender)); + Iterator read = octals.iterator(); + while (read.hasNext()) { + int byteTriplet = 0; + byteTriplet += read.next().ordinalOf(T08PartOctal.PART_1); + byteTriplet += read.next().ordinalOf(T08PartOctal.PART_2); + byteTriplet += read.next().ordinalOf(T08PartOctal.PART_3); + byteTriplet += read.next().ordinalOf(T08PartOctal.PART_4); + byteTriplet += read.next().ordinalOf(T08PartOctal.PART_5); + byteTriplet += read.next().ordinalOf(T08PartOctal.PART_6); + byteTriplet += read.next().ordinalOf(T08PartOctal.PART_7); + byteTriplet += read.next().ordinalOf(T08PartOctal.PART_8); + output.write(byteTriplet); + output.write(byteTriplet >> SHIFT_8); + output.write(byteTriplet >> SHIFT_16); + totalBytes += 3; + } + return totalBytes; + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/BaseAppender.java b/core/src/love/distributedrebirth/demo4d/base2t/BaseAppender.java new file mode 100644 index 00000000..91a8087f --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/BaseAppender.java @@ -0,0 +1,6 @@ +package love.distributedrebirth.demo4d.base2t; + +public interface BaseAppender { + + void add(T value); +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/BaseNumber.java b/core/src/love/distributedrebirth/demo4d/base2t/BaseNumber.java new file mode 100644 index 00000000..53af3a11 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/BaseNumber.java @@ -0,0 +1,17 @@ +package love.distributedrebirth.demo4d.base2t; + +import java.util.ArrayList; +import java.util.List; + +public interface BaseNumber> { + + V toClone(); + + void fillOctalValues(T08PartOctalBaseAppender appender); + + default T08PartOctalIterator cloneIterator() { + List octals = new ArrayList<>(); + fillOctalValues(new T08PartOctalBaseAppender(octals)); + return new T08PartOctalIterator(octals.iterator()); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/BaseNumberTyte.java b/core/src/love/distributedrebirth/demo4d/base2t/BaseNumberTyte.java new file mode 100644 index 00000000..ff993f41 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/BaseNumberTyte.java @@ -0,0 +1,6 @@ +package love.distributedrebirth.demo4d.base2t; + +public interface BaseNumberTyte> extends BaseNumber { + + void fillTyteValues(V009TyteBaseAppender appender); +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifier.java b/core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifier.java new file mode 100644 index 00000000..9429d460 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifier.java @@ -0,0 +1,6 @@ +package love.distributedrebirth.demo4d.base2t; + +public interface BasePartIdentifier { + + String getIdentifier(); +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifierAlt.java b/core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifierAlt.java new file mode 100644 index 00000000..e09b0075 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifierAlt.java @@ -0,0 +1,8 @@ +package love.distributedrebirth.demo4d.base2t; + +public interface BasePartIdentifierAlt extends BasePartIdentifier { + + String getIdentifierAlt(); + + BasePartIdentifierAltInfo getIdentifierAltInfo(); +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifierAltInfo.java b/core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifierAltInfo.java new file mode 100644 index 00000000..6fa28755 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifierAltInfo.java @@ -0,0 +1,20 @@ +package love.distributedrebirth.demo4d.base2t; + +public class BasePartIdentifierAltInfo { + + private final String altName; + private final String altWiki; + + public BasePartIdentifierAltInfo(String altName, String altWiki) { + this.altName = altName; + this.altWiki = altWiki; + } + + public String getAltName() { + return altName; + } + + public String getAltWiki() { + return altWiki; + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifierTone.java b/core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifierTone.java new file mode 100644 index 00000000..18256ec7 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/BasePartIdentifierTone.java @@ -0,0 +1,6 @@ +package love.distributedrebirth.demo4d.base2t; + +public interface BasePartIdentifierTone extends BasePartIdentifier { + + String getIdentifierTone(); +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T02PartBinary.java b/core/src/love/distributedrebirth/demo4d/base2t/T02PartBinary.java new file mode 100644 index 00000000..3481724b --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/T02PartBinary.java @@ -0,0 +1,35 @@ +package love.distributedrebirth.demo4d.base2t; + +import java.util.function.Consumer; + +public enum T02PartBinary implements BasePartIdentifierTone { + + PART_1("0","˥"), + PART_2("1","˩"), + ; + + public static int LENGTH = 2; + private final String identifier; + private final String identifierTone; + + private T02PartBinary(String identifier, String identifierTone) { + this.identifier = identifier; + this.identifierTone = identifierTone; + } + + @Override + public String getIdentifier() { + return identifier; + } + + @Override + public String getIdentifierTone() { + return identifierTone; + } + + public static void forEach(Consumer consumer) { + for (T02PartBinary value:values()) { + consumer.accept(value); + } + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T03PartTrit.java b/core/src/love/distributedrebirth/demo4d/base2t/T03PartTrit.java new file mode 100644 index 00000000..74c0e33b --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/T03PartTrit.java @@ -0,0 +1,36 @@ +package love.distributedrebirth.demo4d.base2t; + +import java.util.function.Consumer; + +public enum T03PartTrit implements BasePartIdentifierTone { + + PART_1("0","˦"), + PART_2("1","˧"), + PART_3("2","˨"), + ; + + public static int LENGTH = 3; + private final String identifier; + private final String identifierTone; + + private T03PartTrit(String identifier, String identifierTone) { + this.identifier = identifier; + this.identifierTone = identifierTone; + } + + @Override + public String getIdentifier() { + return identifier; + } + + @Override + public String getIdentifierTone() { + return identifierTone; + } + + public static void forEach(Consumer consumer) { + for (T03PartTrit value:values()) { + consumer.accept(value); + } + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T04PartQuad.java b/core/src/love/distributedrebirth/demo4d/base2t/T04PartQuad.java new file mode 100644 index 00000000..8eaeaa4c --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/T04PartQuad.java @@ -0,0 +1,55 @@ +package love.distributedrebirth.demo4d.base2t; + +import java.util.function.Consumer; + +public enum T04PartQuad implements BasePartIdentifierAlt,BasePartIdentifierTone { + + PART_1("0","N","˥"), + PART_2("1","E","˦"), + PART_3("2","W","˨"), + PART_4("3","S","˩"), + ; + + public static int LENGTH = 4; + private final String identifier; + private final String identifierAlt; + private final String identifierTone; + private static final BasePartIdentifierAltInfo ALT_INFO = new BasePartIdentifierAltInfo( + "Cardinal direction","https://simple.wikipedia.org/wiki/Cardinal_direction"); + + private T04PartQuad(String identifier, String identifierAlt, String identifierTone) { + this.identifier = identifier; + this.identifierAlt = identifierAlt; + this.identifierTone = identifierTone; + } + + @Override + public String getIdentifier() { + return identifier; + } + + @Override + public String getIdentifierAlt() { + return identifierAlt; + } + + @Override + public String getIdentifierTone() { + return identifierTone; + } + + @Override + public BasePartIdentifierAltInfo getIdentifierAltInfo() { + return ALT_INFO; + } + + public T02PartBinary splitPartBinary(T02PartBinary part) { + return T02PartBinary.values()[(ordinal() >> part.ordinal()) & 1]; + } + + public static void forEach(Consumer consumer) { + for (T04PartQuad value:values()) { + consumer.accept(value); + } + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T05PartPental.java b/core/src/love/distributedrebirth/demo4d/base2t/T05PartPental.java new file mode 100644 index 00000000..b7009810 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/T05PartPental.java @@ -0,0 +1,52 @@ +package love.distributedrebirth.demo4d.base2t; + +import java.util.function.Consumer; + +public enum T05PartPental implements BasePartIdentifierAlt,BasePartIdentifierTone { + + PART_1("0","\u706b","˥"), + PART_2("1","\u571f","˦"), + PART_3("2","\u91d1","˧"), + PART_4("3","\u6c34","˨"), + PART_5("4","\u6728","˩"), + ; + + public static int LENGTH = 5; + private final String identifier; + private final String identifierAlt; // escaped to keep normal line height in IDE + private final String identifierTone; + private static final BasePartIdentifierAltInfo ALT_INFO = new BasePartIdentifierAltInfo( + "Wuxing","https://en.wikipedia.org/wiki/Wuxing_(Chinese_philosophy)"); + + private T05PartPental(String identifier, String identifierAlt, String identifierTone) { + this.identifier = identifier; + this.identifierAlt = identifierAlt; + this.identifierTone = identifierTone; + } + + @Override + public String getIdentifier() { + return identifier; + } + + @Override + public String getIdentifierAlt() { + return identifierAlt; + } + + @Override + public String getIdentifierTone() { + return identifierTone; + } + + @Override + public BasePartIdentifierAltInfo getIdentifierAltInfo() { + return ALT_INFO; + } + + public static void forEach(Consumer consumer) { + for (T05PartPental value:values()) { + consumer.accept(value); + } + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T06PartSeximal.java b/core/src/love/distributedrebirth/demo4d/base2t/T06PartSeximal.java new file mode 100644 index 00000000..67c66867 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/T06PartSeximal.java @@ -0,0 +1,61 @@ +package love.distributedrebirth.demo4d.base2t; + +import java.util.function.Consumer; + +public enum T06PartSeximal implements BasePartIdentifierAlt,BasePartIdentifierTone { + + PART_1("0","A","˧˥"), + PART_2("1","D","˧˩"), + PART_3("2","F","˨˦"), + PART_4("3","G","˦˨"), + PART_5("4","V","˩˧"), + PART_6("5","X","˥˧"), + ; + + public static int LENGTH = 6; + private final String identifier; + private final String identifierAlt; + private final String identifierTone; + private static final BasePartIdentifierAltInfo ALT_INFO = new BasePartIdentifierAltInfo( + "ADFGVX cipher","https://en.wikipedia.org/wiki/ADFGVX_cipher"); + + private T06PartSeximal(String identifier, String identifierAlt, String identifierTone) { + this.identifier = identifier; + this.identifierAlt = identifierAlt; + this.identifierTone = identifierTone; + } + + @Override + public String getIdentifier() { + return identifier; + } + + @Override + public String getIdentifierAlt() { + return identifierAlt; + } + + @Override + public String getIdentifierTone() { + return identifierTone; + } + + @Override + public BasePartIdentifierAltInfo getIdentifierAltInfo() { + return ALT_INFO; + } + + public T02PartBinary splitPartBinary() { + return T02PartBinary.values()[ordinal() & 1]; + } + + public T03PartTrit splitPartTrit() { + return T03PartTrit.values()[ordinal() >> 1]; + } + + public static void forEach(Consumer consumer) { + for (T06PartSeximal value:values()) { + consumer.accept(value); + } + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T08PartOctal.java b/core/src/love/distributedrebirth/demo4d/base2t/T08PartOctal.java new file mode 100644 index 00000000..86ffdc0e --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/T08PartOctal.java @@ -0,0 +1,74 @@ +package love.distributedrebirth.demo4d.base2t; + +import java.util.function.Consumer; + +public enum T08PartOctal implements BasePartIdentifierAlt, BasePartIdentifierTone { + + PART_1("0","˧˥˩","˥˩˧", 0), + PART_2("1","˧˩˥","˩˥˧", 3), + PART_3("2","˧˥˦","˥˦˧", 6), + PART_4("3","˧˩˨","˩˨˧", 9), + PART_5("4","˧˦˦","˦˦˧", 12), + PART_6("5","˧˨˨","˨˨˧", 15), + PART_7("6","˧˥˥","˥˥˧", 18), + PART_8("7","˧˩˩","˩˩˧", 21), + ; + + public static int LENGTH = 8; + private static final byte BITMASK = 0x07; + private final String identifier; + private final String identifierAlt; // absolute + private final String identifierTone; // relative + private final int shiftBits; + private static final BasePartIdentifierAltInfo ALT_INFO = new BasePartIdentifierAltInfo( + "Tone Letters","https://en.wikipedia.org/wiki/Tone_letter"); + + private T08PartOctal(String identifier, String identifierAlt, String identifierTone, int shiftBits) { + this.identifier = identifier; + this.identifierAlt = identifierAlt; + this.identifierTone = identifierTone; + this.shiftBits = shiftBits; + } + + @Override + public String getIdentifier() { + return identifier; + } + + @Override + public String getIdentifierAlt() { + return identifierAlt; + } + + @Override + public String getIdentifierTone() { + return identifierTone; + } + + @Override + public BasePartIdentifierAltInfo getIdentifierAltInfo() { + return ALT_INFO; + } + + public int getShiftBits() { + return shiftBits; + } + + public int ordinalOf(T08PartOctal group) { + return ordinal() << group.getShiftBits(); + } + + public static T08PartOctal indexOf(T08PartOctal group, int value) { + return T08PartOctal.values()[(value >> group.getShiftBits()) & BITMASK]; + } + + public T02PartBinary splitPartBinary(T03PartTrit part) { + return T02PartBinary.values()[(ordinal() >> part.ordinal()) & 1]; + } + + public static void forEach(Consumer consumer) { + for (T08PartOctal value:values()) { + consumer.accept(value); + } + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T08PartOctalBaseAppender.java b/core/src/love/distributedrebirth/demo4d/base2t/T08PartOctalBaseAppender.java new file mode 100644 index 00000000..d60a8267 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/T08PartOctalBaseAppender.java @@ -0,0 +1,17 @@ +package love.distributedrebirth.demo4d.base2t; + +import java.util.Collection; + +public final class T08PartOctalBaseAppender implements BaseAppender { + + private final Collection collection; + + public T08PartOctalBaseAppender(Collection collection) { + this.collection = collection; + } + + @Override + public void add(T08PartOctal value) { + collection.add(value); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T08PartOctalIterator.java b/core/src/love/distributedrebirth/demo4d/base2t/T08PartOctalIterator.java new file mode 100644 index 00000000..61a7f0f5 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/T08PartOctalIterator.java @@ -0,0 +1,22 @@ +package love.distributedrebirth.demo4d.base2t; + +import java.util.Iterator; + +public final class T08PartOctalIterator implements Iterator { + + private final Iterator iterator; + + public T08PartOctalIterator(Iterator iterator) { + this.iterator = iterator; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public T08PartOctal next() { + return iterator.next(); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T12PartUncial.java b/core/src/love/distributedrebirth/demo4d/base2t/T12PartUncial.java new file mode 100644 index 00000000..39b3f254 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/T12PartUncial.java @@ -0,0 +1,52 @@ +package love.distributedrebirth.demo4d.base2t; + +import java.util.function.Consumer; + +public enum T12PartUncial implements BasePartIdentifierAlt { + + PART_1("0","0"), + PART_2("1","1"), + PART_3("2","2"), + PART_4("3","3"), + PART_5("4","4"), + PART_6("5","5"), + PART_7("6","6"), + PART_8("7","7"), + PART_9("8","8"), + PART_10("9","9"), + PART_11("A","\u218a"), // TURNED DIGIT TWO + PART_12("B","\u218b"), // TURNED DIGIT THREE + ; + + public static int LENGTH = 12; + private final String identifier; + private final String identifierAlt; + private static final BasePartIdentifierAltInfo ALT_INFO = new BasePartIdentifierAltInfo( + "Transdecimal symbols","https://en.wikipedia.org/wiki/Duodecimal#Transdecimal_symbols"); + + private T12PartUncial(String identifier, String identifierAlt) { + this.identifier = identifier; + this.identifierAlt = identifierAlt; + } + + @Override + public String getIdentifier() { + return identifier; + } + + @Override + public String getIdentifierAlt() { + return identifierAlt; + } + + @Override + public BasePartIdentifierAltInfo getIdentifierAltInfo() { + return ALT_INFO; + } + + public static void forEach(Consumer consumer) { + for (T12PartUncial value:values()) { + consumer.accept(value); + } + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T16PartHex.java b/core/src/love/distributedrebirth/demo4d/base2t/T16PartHex.java new file mode 100644 index 00000000..a3a97002 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/T16PartHex.java @@ -0,0 +1,67 @@ +package love.distributedrebirth.demo4d.base2t; + +import java.util.function.Consumer; + +public enum T16PartHex implements BasePartIdentifierAlt, BasePartIdentifierTone { + + PART_1("0","1","˧˥˩"), + PART_2("1","2","˧˩˥"), + PART_3("2","3","˧˥˦"), + PART_4("3","A","˧˩˨"), + PART_5("4","4","˧˦˦"), + PART_6("5","5","˧˨˨"), + PART_7("6","6","˧˥˥"), + PART_8("7","B","˧˩˩"), + PART_9("8","7","˥˩˧"), + PART_10("9","8","˩˥˧"), + PART_11("A","9","˥˦˧"), + PART_12("B","C","˩˨˧"), + PART_13("C","*","˦˦˧"), + PART_14("D","0","˨˨˧"), + PART_15("E","#","˥˥˧"), + PART_16("F","D","˩˩˧"), + ; + + public static int LENGTH = 16; + private final String identifier; + private final String identifierAlt; + private final String identifierTone; + private static final BasePartIdentifierAltInfo ALT_INFO = new BasePartIdentifierAltInfo( + "Dual-tone multi-frequency signaling","https://en.wikipedia.org/wiki/Dual-tone_multi-frequency_signaling"); + + private T16PartHex(String identifier, String identifierAlt, String identifierTone) { + this.identifier = identifier; + this.identifierAlt = identifierAlt; + this.identifierTone = identifierTone; + } + + @Override + public String getIdentifier() { + return identifier; + } + + @Override + public String getIdentifierAlt() { + return identifierAlt; + } + + @Override + public String getIdentifierTone() { + return identifierTone; + } + + @Override + public BasePartIdentifierAltInfo getIdentifierAltInfo() { + return ALT_INFO; + } + + public T02PartBinary splitPartBinary(T04PartQuad part) { + return T02PartBinary.values()[(ordinal() >> part.ordinal()) & 1]; + } + + public static void forEach(Consumer consumer) { + for (T16PartHex value:values()) { + consumer.accept(value); + } + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T20PartScore.java b/core/src/love/distributedrebirth/demo4d/base2t/T20PartScore.java new file mode 100644 index 00000000..0b057f19 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/T20PartScore.java @@ -0,0 +1,60 @@ +package love.distributedrebirth.demo4d.base2t; + +import java.util.function.Consumer; + +public enum T20PartScore implements BasePartIdentifierAlt { + + PART_1("0","2"), + PART_2("1","3"), + PART_3("2","4"), + PART_4("3","5"), + PART_5("4","6"), + PART_6("5","7"), + PART_7("6","8"), + PART_8("7","9"), + PART_9("8","C"), + PART_10("9","F"), + PART_11("A","G"), + PART_12("B","H"), + PART_13("C","J"), + PART_14("D","M"), + PART_15("E","P"), + PART_16("F","Q"), + PART_17("G","R"), + PART_18("H","V"), + PART_19("I","W"), + PART_20("J","X"), + ; + + public static int LENGTH = 20; + private final String identifier; + private final String identifierAlt; + private static final BasePartIdentifierAltInfo ALT_INFO = new BasePartIdentifierAltInfo( + "Open Location Code","https://en.wikipedia.org/wiki/Open_Location_Code"); + + private T20PartScore(String identifier, String identifierAlt) { + this.identifier = identifier; + this.identifierAlt = identifierAlt; + } + + @Override + public String getIdentifier() { + return identifier; + } + + @Override + public String getIdentifierAlt() { + return identifierAlt; + } + + @Override + public BasePartIdentifierAltInfo getIdentifierAltInfo() { + return ALT_INFO; + } + + public static void forEach(Consumer consumer) { + for (T20PartScore value:values()) { + consumer.accept(value); + } + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/V003Timble.java b/core/src/love/distributedrebirth/demo4d/base2t/V003Timble.java new file mode 100644 index 00000000..43ab7322 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/V003Timble.java @@ -0,0 +1,36 @@ +package love.distributedrebirth.demo4d.base2t; + +public final class V003Timble implements BaseNumber { + + private T08PartOctal value; + + public V003Timble() { + this(T08PartOctal.PART_1); + } + + public V003Timble(T08PartOctalIterator values) { + this(values.next()); + } + + public V003Timble(T08PartOctal value) { + setValue(value); + } + + public void setValue(T08PartOctal value) { + this.value = value; + } + + public T08PartOctal getValue() { + return value; + } + + @Override + public V003Timble toClone() { + return new V003Timble(getValue()); + } + + @Override + public void fillOctalValues(T08PartOctalBaseAppender appender) { + appender.add(getValue()); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/V006Tixte.java b/core/src/love/distributedrebirth/demo4d/base2t/V006Tixte.java new file mode 100644 index 00000000..d3974973 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/V006Tixte.java @@ -0,0 +1,37 @@ +package love.distributedrebirth.demo4d.base2t; + +public final class V006Tixte implements BaseNumber { + + private V003Timble[] values = new V003Timble[T02PartBinary.LENGTH]; + + public V006Tixte() { + this(new V003Timble(), new V003Timble()); + } + + public V006Tixte(T08PartOctalIterator values) { + this(new V003Timble(values), new V003Timble(values)); + } + + public V006Tixte(V003Timble valueHigh, V003Timble valueLow) { + setValue(T02PartBinary.PART_1, valueHigh); + setValue(T02PartBinary.PART_2, valueLow); + } + + public V003Timble getValue(T02PartBinary part) { + return values[part.ordinal()]; + } + + public void setValue(T02PartBinary part, V003Timble value) { + values[part.ordinal()] = value; + } + + @Override + public V006Tixte toClone() { + return new V006Tixte(cloneIterator()); + } + + @Override + public void fillOctalValues(T08PartOctalBaseAppender appender) { + T02PartBinary.forEach(v -> getValue(v).fillOctalValues(appender)); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/V009Tyte.java b/core/src/love/distributedrebirth/demo4d/base2t/V009Tyte.java new file mode 100644 index 00000000..08add87c --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/V009Tyte.java @@ -0,0 +1,47 @@ +package love.distributedrebirth.demo4d.base2t; + +public final class V009Tyte implements BaseNumberTyte { + + private V003Timble[] values = new V003Timble[T03PartTrit.LENGTH]; + + public V009Tyte() { + this(new V003Timble(), new V003Timble(), new V003Timble()); + } + + public V009Tyte(T08PartOctalIterator values) { + this(new V003Timble(values), new V003Timble(values), new V003Timble(values)); + } + + public V009Tyte(T08PartOctal valueHigh, T08PartOctal valueMedium, T08PartOctal valueLow) { + this(new V003Timble(valueHigh), new V003Timble(valueMedium), new V003Timble(valueLow)); + } + + public V009Tyte(V003Timble valueHigh, V003Timble valueMedium, V003Timble valueLow) { + setValue(T03PartTrit.PART_1, valueHigh); + setValue(T03PartTrit.PART_2, valueMedium); + setValue(T03PartTrit.PART_3, valueLow); + } + + public V003Timble getValue(T03PartTrit part) { + return values[part.ordinal()]; + } + + public void setValue(T03PartTrit part, V003Timble value) { + values[part.ordinal()] = value; + } + + @Override + public V009Tyte toClone() { + return new V009Tyte(cloneIterator()); + } + + @Override + public void fillOctalValues(T08PartOctalBaseAppender appender) { + T03PartTrit.forEach(v -> getValue(v).fillOctalValues(appender)); + } + + @Override + public void fillTyteValues(V009TyteBaseAppender appender) { + appender.add(this); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/V009TyteBaseAppender.java b/core/src/love/distributedrebirth/demo4d/base2t/V009TyteBaseAppender.java new file mode 100644 index 00000000..5771b7c1 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/V009TyteBaseAppender.java @@ -0,0 +1,17 @@ +package love.distributedrebirth.demo4d.base2t; + +import java.util.Collection; + +public final class V009TyteBaseAppender implements BaseAppender { + + private final Collection collection; + + public V009TyteBaseAppender(Collection collection) { + this.collection = collection; + } + + @Override + public void add(V009Tyte value) { + collection.add(value); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/V009TyteIterator.java b/core/src/love/distributedrebirth/demo4d/base2t/V009TyteIterator.java new file mode 100644 index 00000000..de6ab6f5 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/V009TyteIterator.java @@ -0,0 +1,22 @@ +package love.distributedrebirth.demo4d.base2t; + +import java.util.Iterator; + +public final class V009TyteIterator implements Iterator { + + private final Iterator iterator; + + public V009TyteIterator(Iterator iterator) { + this.iterator = iterator; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public V009Tyte next() { + return iterator.next(); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/V018Tord.java b/core/src/love/distributedrebirth/demo4d/base2t/V018Tord.java new file mode 100644 index 00000000..3da89b85 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/V018Tord.java @@ -0,0 +1,54 @@ +package love.distributedrebirth.demo4d.base2t; + +public final class V018Tord implements BaseNumberTyte { + + private V009Tyte[] values = new V009Tyte[T02PartBinary.LENGTH]; + + public V018Tord() { + this(new V009Tyte(), new V009Tyte()); + } + + public V018Tord(T08PartOctalIterator values) { + this(new V009Tyte(values), new V009Tyte(values)); + } + + public V018Tord(V009TyteIterator values) { + this(values.next(), values.next()); + } + + public V018Tord(V009Tyte valueHigh, V009Tyte valueLow) { + setValue(T02PartBinary.PART_1, valueHigh); + setValue(T02PartBinary.PART_2, valueLow); + } + + public V009Tyte getValue(T02PartBinary part) { + return values[part.ordinal()]; + } + + public void setValue(T02PartBinary part, V009Tyte value) { + values[part.ordinal()] = value; + } + + public V003Timble getTimblePart(T06PartSeximal part) { + return getValue(part.splitPartBinary()).getValue(part.splitPartTrit()); + } + + public void setTimblePart(T06PartSeximal part, V003Timble value) { + getValue(part.splitPartBinary()).setValue(part.splitPartTrit(), value);; + } + + @Override + public V018Tord toClone() { + return new V018Tord(cloneIterator()); + } + + @Override + public void fillOctalValues(T08PartOctalBaseAppender appender) { + T02PartBinary.forEach(v -> getValue(v).fillOctalValues(appender)); + } + + @Override + public void fillTyteValues(V009TyteBaseAppender appender) { + T02PartBinary.forEach(v -> getValue(v).fillTyteValues(appender)); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/V027Temvig.java b/core/src/love/distributedrebirth/demo4d/base2t/V027Temvig.java new file mode 100644 index 00000000..bab77a3a --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/V027Temvig.java @@ -0,0 +1,47 @@ +package love.distributedrebirth.demo4d.base2t; + +public final class V027Temvig implements BaseNumberTyte { + + private V009Tyte[] values = new V009Tyte[T03PartTrit.LENGTH]; + + public V027Temvig() { + this(new V009Tyte(), new V009Tyte(), new V009Tyte()); + } + + public V027Temvig(T08PartOctalIterator values) { + this(new V009Tyte(values), new V009Tyte(values), new V009Tyte(values)); + } + + public V027Temvig(V009TyteIterator values) { + this(values.next(), values.next(), values.next()); + } + + public V027Temvig(V009Tyte valueHigh, V009Tyte valueMedium, V009Tyte valueLow) { + setValue(T03PartTrit.PART_1, valueHigh); + setValue(T03PartTrit.PART_2, valueMedium); + setValue(T03PartTrit.PART_3, valueLow); + } + + public V009Tyte getValue(T03PartTrit part) { + return values[part.ordinal()]; + } + + public void setValue(T03PartTrit part, V009Tyte value) { + values[part.ordinal()] = value; + } + + @Override + public V027Temvig toClone() { + return new V027Temvig(cloneIterator()); + } + + @Override + public void fillOctalValues(T08PartOctalBaseAppender appender) { + T03PartTrit.forEach(v -> getValue(v).fillOctalValues(appender)); + } + + @Override + public void fillTyteValues(V009TyteBaseAppender appender) { + T03PartTrit.forEach(v -> getValue(v).fillTyteValues(appender)); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/V036Teger.java b/core/src/love/distributedrebirth/demo4d/base2t/V036Teger.java new file mode 100644 index 00000000..7c42f758 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/V036Teger.java @@ -0,0 +1,56 @@ +package love.distributedrebirth.demo4d.base2t; + +public final class V036Teger implements BaseNumberTyte { + + private V018Tord[] values = new V018Tord[T02PartBinary.LENGTH]; + + public V036Teger() { + this(new V018Tord(), new V018Tord()); + } + + public V036Teger(T08PartOctalIterator values) { + this(new V018Tord(values), new V018Tord(values)); + } + + public V036Teger(V009TyteIterator values) { + this(new V018Tord(values), new V018Tord(values)); + } + + public V036Teger(V018Tord valueHigh, V018Tord valueLow) { + setValue(T02PartBinary.PART_1, valueHigh); + setValue(T02PartBinary.PART_2, valueLow); + } + + public V018Tord getValue(T02PartBinary part) { + return values[part.ordinal()]; + } + + public void setValue(T02PartBinary part, V018Tord value) { + values[part.ordinal()] = value; + } + + public V009Tyte getTytePart(T04PartQuad part) { + return getValue(part.splitPartBinary(T02PartBinary.PART_1)) + .getValue(part.splitPartBinary(T02PartBinary.PART_2)); + } + + public void setTytePart(T04PartQuad part, V009Tyte value) { + getValue(part.splitPartBinary(T02PartBinary.PART_1)) + .setValue(part.splitPartBinary(T02PartBinary.PART_2), value); + } + + @Override + public V036Teger toClone() { + return new V036Teger(cloneIterator()); + } + + @Override + public void fillOctalValues(T08PartOctalBaseAppender appender) { + T02PartBinary.forEach(v -> getValue(v).fillOctalValues(appender)); + } + + @Override + public void fillTyteValues(V009TyteBaseAppender appender) { + T02PartBinary.forEach(v -> getValue(v).fillTyteValues(appender)); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/V072Tong.java b/core/src/love/distributedrebirth/demo4d/base2t/V072Tong.java new file mode 100644 index 00000000..aa5e789a --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/V072Tong.java @@ -0,0 +1,46 @@ +package love.distributedrebirth.demo4d.base2t; + +public final class V072Tong implements BaseNumberTyte { + + private V036Teger[] values = new V036Teger[T02PartBinary.LENGTH]; + + public V072Tong() { + this(new V036Teger(), new V036Teger()); + } + + public V072Tong(T08PartOctalIterator values) { + this(new V036Teger(values), new V036Teger(values)); + } + + public V072Tong(V009TyteIterator values) { + this(new V036Teger(values), new V036Teger(values)); + } + + public V072Tong(V036Teger valueHigh, V036Teger valueLow) { + setValue(T02PartBinary.PART_1, valueHigh); + setValue(T02PartBinary.PART_2, valueLow); + } + + public V036Teger getValue(T02PartBinary part) { + return values[part.ordinal()]; + } + + public void setValue(T02PartBinary part, V036Teger value) { + values[part.ordinal()] = value; + } + + @Override + public V072Tong toClone() { + return new V072Tong(cloneIterator()); + } + + @Override + public void fillOctalValues(T08PartOctalBaseAppender appender) { + T02PartBinary.forEach(v -> getValue(v).fillOctalValues(appender)); + } + + @Override + public void fillTyteValues(V009TyteBaseAppender appender) { + T02PartBinary.forEach(v -> getValue(v).fillTyteValues(appender)); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/base2t/V144Tocta.java b/core/src/love/distributedrebirth/demo4d/base2t/V144Tocta.java new file mode 100644 index 00000000..39f1c6d6 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/base2t/V144Tocta.java @@ -0,0 +1,72 @@ +package love.distributedrebirth.demo4d.base2t; + +public final class V144Tocta implements BaseNumberTyte { + + private V072Tong[] values = new V072Tong[T02PartBinary.LENGTH]; + + public V144Tocta() { + this(new V072Tong(), new V072Tong()); + } + + public V144Tocta(T08PartOctalIterator values) { + this(new V072Tong(values), new V072Tong(values)); + } + + public V144Tocta(V009TyteIterator values) { + this(new V072Tong(values), new V072Tong(values)); + } + + public V144Tocta(V072Tong valueHigh, V072Tong valueLow) { + setValue(T02PartBinary.PART_1, valueHigh); + setValue(T02PartBinary.PART_2, valueLow); + } + + public V072Tong getValue(T02PartBinary part) { + return values[part.ordinal()]; + } + + public void setValue(T02PartBinary part, V072Tong value) { + values[part.ordinal()] = value; + } + + public V009Tyte getTytePart(T16PartHex part) { + return getValue(part.splitPartBinary(T04PartQuad.PART_1)) + .getValue(part.splitPartBinary(T04PartQuad.PART_2)) + .getValue(part.splitPartBinary(T04PartQuad.PART_3)) + .getValue(part.splitPartBinary(T04PartQuad.PART_4)); + } + + public void setTytePart(T16PartHex part, V009Tyte value) { + getValue(part.splitPartBinary(T04PartQuad.PART_1)) + .getValue(part.splitPartBinary(T04PartQuad.PART_2)) + .getValue(part.splitPartBinary(T04PartQuad.PART_3)) + .setValue(part.splitPartBinary(T04PartQuad.PART_4), value); + } + + public V018Tord getTordPart(T08PartOctal part) { + return getValue(part.splitPartBinary(T03PartTrit.PART_1)) + .getValue(part.splitPartBinary(T03PartTrit.PART_2)) + .getValue(part.splitPartBinary(T03PartTrit.PART_3)); + } + + public void setTordPart(T08PartOctal part, V018Tord value) { + getValue(part.splitPartBinary(T03PartTrit.PART_1)) + .getValue(part.splitPartBinary(T03PartTrit.PART_2)) + .setValue(part.splitPartBinary(T03PartTrit.PART_3), value); + } + + @Override + public V144Tocta toClone() { + return new V144Tocta(cloneIterator()); + } + + @Override + public void fillOctalValues(T08PartOctalBaseAppender appender) { + T02PartBinary.forEach(v -> getValue(v).fillOctalValues(appender)); + } + + @Override + public void fillTyteValues(V009TyteBaseAppender appender) { + T02PartBinary.forEach(v -> getValue(v).fillTyteValues(appender)); + } +}