From 56b6d8a681cdbff21c71de877425b49cd352a820 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Sat, 29 Jan 2022 12:48:53 +0100 Subject: [PATCH] Added valueOfTone lookup to terminator enums --- .../demo4d/base2t/T02PartBinary.java | 11 +++++++++++ .../demo4d/base2t/T03PartTrit.java | 11 +++++++++++ .../demo4d/base2t/T04PartQuad.java | 11 +++++++++++ .../demo4d/base2t/T05PartPental.java | 11 +++++++++++ .../demo4d/base2t/T06PartSeximal.java | 11 +++++++++++ .../demo4d/base2t/T08PartOctal.java | 14 ++++++++++++-- .../demo4d/base2t/T12PartUncial.java | 11 +++++++++++ .../demo4d/base2t/T16PartHex.java | 11 +++++++++++ .../demo4d/base2t/T20PartScore.java | 11 +++++++++++ 9 files changed, 100 insertions(+), 2 deletions(-) diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T02PartBinary.java b/core/src/love/distributedrebirth/demo4d/base2t/T02PartBinary.java index 81d66076..4938a491 100644 --- a/core/src/love/distributedrebirth/demo4d/base2t/T02PartBinary.java +++ b/core/src/love/distributedrebirth/demo4d/base2t/T02PartBinary.java @@ -1,6 +1,10 @@ package love.distributedrebirth.demo4d.base2t; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; import java.util.function.Consumer; +import java.util.stream.Collectors; /** * @@ -17,6 +21,9 @@ public enum T02PartBinary implements BasePartIdentifier { private final String identifierTone; private final String identifierLetter; + private static final Map TONE_MAP = Collections.unmodifiableMap( + Arrays.asList(values()).stream().collect(Collectors.toMap(v -> v.getIdentifierTone(), v -> v))); + private T02PartBinary(String identifierTone, String identifierLetter) { this.identifierTone = identifierTone; this.identifierLetter = identifierLetter; @@ -37,4 +44,8 @@ public enum T02PartBinary implements BasePartIdentifier { consumer.accept(value); } } + + public static T02PartBinary valueOfTone(String identifierTone) { + return TONE_MAP.get(identifierTone); + } } diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T03PartTrit.java b/core/src/love/distributedrebirth/demo4d/base2t/T03PartTrit.java index f16d95b9..2850d936 100644 --- a/core/src/love/distributedrebirth/demo4d/base2t/T03PartTrit.java +++ b/core/src/love/distributedrebirth/demo4d/base2t/T03PartTrit.java @@ -1,6 +1,10 @@ package love.distributedrebirth.demo4d.base2t; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; import java.util.function.Consumer; +import java.util.stream.Collectors; /** * @@ -18,6 +22,9 @@ public enum T03PartTrit implements BasePartIdentifier { private final String identifierTone; private final String identifierLetter; + private static final Map TONE_MAP = Collections.unmodifiableMap( + Arrays.asList(values()).stream().collect(Collectors.toMap(v -> v.getIdentifierTone(), v -> v))); + private T03PartTrit(String identifierTone, String identifierLetter) { this.identifierTone = identifierTone; this.identifierLetter = identifierLetter; @@ -38,4 +45,8 @@ public enum T03PartTrit implements BasePartIdentifier { consumer.accept(value); } } + + public static T03PartTrit valueOfTone(String identifierTone) { + return TONE_MAP.get(identifierTone); + } } diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T04PartQuad.java b/core/src/love/distributedrebirth/demo4d/base2t/T04PartQuad.java index f6418411..d04e0985 100644 --- a/core/src/love/distributedrebirth/demo4d/base2t/T04PartQuad.java +++ b/core/src/love/distributedrebirth/demo4d/base2t/T04PartQuad.java @@ -1,6 +1,10 @@ package love.distributedrebirth.demo4d.base2t; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; import java.util.function.Consumer; +import java.util.stream.Collectors; /** * @@ -19,6 +23,9 @@ public enum T04PartQuad implements BasePartIdentifierAlt { private final String identifierTone; private final String identifierLetter; private final String identifierAlt; + + private static final Map TONE_MAP = Collections.unmodifiableMap( + Arrays.asList(values()).stream().collect(Collectors.toMap(v -> v.getIdentifierTone(), v -> v))); private static final BasePartIdentifierAltInfo ALT_INFO = new BasePartIdentifierAltInfo( "Cardinal direction","https://simple.wikipedia.org/wiki/Cardinal_direction"); @@ -57,4 +64,8 @@ public enum T04PartQuad implements BasePartIdentifierAlt { consumer.accept(value); } } + + public static T04PartQuad valueOfTone(String identifierTone) { + return TONE_MAP.get(identifierTone); + } } diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T05PartPental.java b/core/src/love/distributedrebirth/demo4d/base2t/T05PartPental.java index 56c0d39e..9ce0f862 100644 --- a/core/src/love/distributedrebirth/demo4d/base2t/T05PartPental.java +++ b/core/src/love/distributedrebirth/demo4d/base2t/T05PartPental.java @@ -1,6 +1,10 @@ package love.distributedrebirth.demo4d.base2t; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; import java.util.function.Consumer; +import java.util.stream.Collectors; /** * @@ -20,6 +24,9 @@ public enum T05PartPental implements BasePartIdentifierAlt { private final String identifierTone; private final String identifierLetter; private final String identifierAlt; // FIXME: escaped to keep normal line height in IDE + + private static final Map TONE_MAP = Collections.unmodifiableMap( + Arrays.asList(values()).stream().collect(Collectors.toMap(v -> v.getIdentifierTone(), v -> v))); private static final BasePartIdentifierAltInfo ALT_INFO = new BasePartIdentifierAltInfo( "Wuxing","https://en.wikipedia.org/wiki/Wuxing_(Chinese_philosophy)"); @@ -54,4 +61,8 @@ public enum T05PartPental implements BasePartIdentifierAlt { consumer.accept(value); } } + + public static T05PartPental valueOfTone(String identifierTone) { + return TONE_MAP.get(identifierTone); + } } diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T06PartSeximal.java b/core/src/love/distributedrebirth/demo4d/base2t/T06PartSeximal.java index dd10fa82..b60f10e0 100644 --- a/core/src/love/distributedrebirth/demo4d/base2t/T06PartSeximal.java +++ b/core/src/love/distributedrebirth/demo4d/base2t/T06PartSeximal.java @@ -1,6 +1,10 @@ package love.distributedrebirth.demo4d.base2t; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; import java.util.function.Consumer; +import java.util.stream.Collectors; /** * @@ -21,6 +25,9 @@ public enum T06PartSeximal implements BasePartIdentifierAlt { private final String identifierTone; private final String identifierLetter; private final String identifierAlt; + + private static final Map TONE_MAP = Collections.unmodifiableMap( + Arrays.asList(values()).stream().collect(Collectors.toMap(v -> v.getIdentifierTone(), v -> v))); private static final BasePartIdentifierAltInfo ALT_INFO = new BasePartIdentifierAltInfo( "ADFGVX cipher","https://en.wikipedia.org/wiki/ADFGVX_cipher"); @@ -63,4 +70,8 @@ public enum T06PartSeximal implements BasePartIdentifierAlt { consumer.accept(value); } } + + public static T06PartSeximal valueOfTone(String identifierTone) { + return TONE_MAP.get(identifierTone); + } } diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T08PartOctal.java b/core/src/love/distributedrebirth/demo4d/base2t/T08PartOctal.java index a5b50d17..5a045cbd 100644 --- a/core/src/love/distributedrebirth/demo4d/base2t/T08PartOctal.java +++ b/core/src/love/distributedrebirth/demo4d/base2t/T08PartOctal.java @@ -1,6 +1,10 @@ package love.distributedrebirth.demo4d.base2t; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; import java.util.function.Consumer; +import java.util.stream.Collectors; /** * @@ -24,9 +28,11 @@ public enum T08PartOctal implements BasePartIdentifierAlt { private static final byte BITMASK = 0x07; private final String identifierTone; // absolute private final String identifierLetter; - private final String identifierAlt; // relative - + private final String identifierAlt; // relative private final int shiftBits; + + private static final Map TONE_MAP = Collections.unmodifiableMap( + Arrays.asList(values()).stream().collect(Collectors.toMap(v -> v.getIdentifierTone(), v -> v))); private static final BasePartIdentifierAltInfo ALT_INFO = new BasePartIdentifierAltInfo( "Tone Letters","https://en.wikipedia.org/wiki/Tone_letter"); @@ -78,4 +84,8 @@ public enum T08PartOctal implements BasePartIdentifierAlt { consumer.accept(value); } } + + public static T08PartOctal valueOfTone(String identifierTone) { + return TONE_MAP.get(identifierTone); + } } diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T12PartUncial.java b/core/src/love/distributedrebirth/demo4d/base2t/T12PartUncial.java index 446af3cf..05356cfc 100644 --- a/core/src/love/distributedrebirth/demo4d/base2t/T12PartUncial.java +++ b/core/src/love/distributedrebirth/demo4d/base2t/T12PartUncial.java @@ -1,6 +1,10 @@ package love.distributedrebirth.demo4d.base2t; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; import java.util.function.Consumer; +import java.util.stream.Collectors; /** * @@ -28,6 +32,9 @@ public enum T12PartUncial implements BasePartIdentifierAlt { private final String identifierTone; private final String identifierLetter; private final String identifierAlt; + + private static final Map TONE_MAP = Collections.unmodifiableMap( + Arrays.asList(values()).stream().collect(Collectors.toMap(v -> v.getIdentifierTone(), v -> v))); private static final BasePartIdentifierAltInfo ALT_INFO = new BasePartIdentifierAltInfo( "Transdecimal symbols","https://en.wikipedia.org/wiki/Duodecimal#Transdecimal_symbols"); @@ -62,4 +69,8 @@ public enum T12PartUncial implements BasePartIdentifierAlt { consumer.accept(value); } } + + public static T12PartUncial valueOfTone(String identifierTone) { + return TONE_MAP.get(identifierTone); + } } diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T16PartHex.java b/core/src/love/distributedrebirth/demo4d/base2t/T16PartHex.java index 7e897ec8..dd9bc0b1 100644 --- a/core/src/love/distributedrebirth/demo4d/base2t/T16PartHex.java +++ b/core/src/love/distributedrebirth/demo4d/base2t/T16PartHex.java @@ -1,6 +1,10 @@ package love.distributedrebirth.demo4d.base2t; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; import java.util.function.Consumer; +import java.util.stream.Collectors; /** * @@ -31,6 +35,9 @@ public enum T16PartHex implements BasePartIdentifierAlt { private final String identifierTone; private final String identifierLetter; private final String identifierAlt; + + private static final Map TONE_MAP = Collections.unmodifiableMap( + Arrays.asList(values()).stream().collect(Collectors.toMap(v -> v.getIdentifierTone(), v -> v))); private static final BasePartIdentifierAltInfo ALT_INFO = new BasePartIdentifierAltInfo( "Dual-tone multi-frequency signaling","https://en.wikipedia.org/wiki/Dual-tone_multi-frequency_signaling"); @@ -69,4 +76,8 @@ public enum T16PartHex implements BasePartIdentifierAlt { consumer.accept(value); } } + + public static T16PartHex valueOfTone(String identifierTone) { + return TONE_MAP.get(identifierTone); + } } diff --git a/core/src/love/distributedrebirth/demo4d/base2t/T20PartScore.java b/core/src/love/distributedrebirth/demo4d/base2t/T20PartScore.java index 58040831..5b0b3543 100644 --- a/core/src/love/distributedrebirth/demo4d/base2t/T20PartScore.java +++ b/core/src/love/distributedrebirth/demo4d/base2t/T20PartScore.java @@ -1,6 +1,10 @@ package love.distributedrebirth.demo4d.base2t; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; import java.util.function.Consumer; +import java.util.stream.Collectors; /** * @@ -36,6 +40,9 @@ public enum T20PartScore implements BasePartIdentifierAlt { private final String identifierTone; private final String identifierLetter; private final String identifierAlt; + + private static final Map TONE_MAP = Collections.unmodifiableMap( + Arrays.asList(values()).stream().collect(Collectors.toMap(v -> v.getIdentifierTone(), v -> v))); private static final BasePartIdentifierAltInfo ALT_INFO = new BasePartIdentifierAltInfo( "Open Location Code","https://en.wikipedia.org/wiki/Open_Location_Code"); @@ -70,4 +77,8 @@ public enum T20PartScore implements BasePartIdentifierAlt { consumer.accept(value); } } + + public static T20PartScore valueOfTone(String identifierTone) { + return TONE_MAP.get(identifierTone); + } }