diff --git a/core/src/love/distributedrebirth/demo4d/fraction4d/Gê̄ldGetậl.java b/core/src/love/distributedrebirth/demo4d/fraction4d/Gê̄ldGetậl.java index 64d45ff6..cbb22778 100644 --- a/core/src/love/distributedrebirth/demo4d/fraction4d/Gê̄ldGetậl.java +++ b/core/src/love/distributedrebirth/demo4d/fraction4d/Gê̄ldGetậl.java @@ -61,7 +61,7 @@ public class Gê̄ldGetậl { continue; } if (geldDigit != null) { - HebrewDigitVowel vowel = HebrewDigitVowel.valueOf(codePoint); + HebrewDigitVowel vowel = HebrewDigitVowel.valueOfCharacter(codePoint); if (!HebrewDigitVowel.NONE.equals(vowel)) { geldDigit.setVowel(vowel); result.add(geldDigit); @@ -71,7 +71,7 @@ public class Gê̄ldGetậl { result.add(geldDigit); } } - HebrewDigitLetter letter = HebrewDigitLetter.valueOf(codePoint); + HebrewDigitLetter letter = HebrewDigitLetter.valueOfCharacter(codePoint); if (HebrewDigitLetter.NONE.equals(letter)) { throw new IllegalArgumentException("Unknown fraction codepoint: 0x"+Integer.toHexString(codePoint)); } diff --git a/core/src/love/distributedrebirth/demo4d/fraction4d/HebrewDigitLetter.java b/core/src/love/distributedrebirth/demo4d/fraction4d/HebrewDigitLetter.java index 89babc63..042fb2d5 100644 --- a/core/src/love/distributedrebirth/demo4d/fraction4d/HebrewDigitLetter.java +++ b/core/src/love/distributedrebirth/demo4d/fraction4d/HebrewDigitLetter.java @@ -1,5 +1,10 @@ package love.distributedrebirth.demo4d.fraction4d; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; +import java.util.stream.Collectors; + /** * * @author willemtsade ©Δ∞ 仙上主天 @@ -75,6 +80,9 @@ public enum HebrewDigitLetter { private final int decimal; private final char character; + private static final Map CHAR_MAP = Collections.unmodifiableMap( + Arrays.asList(values()).stream().collect(Collectors.toMap(v -> v.getCharacter(), v -> v))); + private HebrewDigitLetter(int decimal, char character) { this.decimal = decimal; this.character = character; @@ -92,12 +100,7 @@ public enum HebrewDigitLetter { return values()[index & BITMASK]; } - public static HebrewDigitLetter valueOf(char codePoint) { - for (HebrewDigitLetter vowel:values()) { - if (vowel.getCharacter() == codePoint) { - return vowel; - } - } - return HebrewDigitLetter.NONE; + public static HebrewDigitLetter valueOfCharacter(char codePoint) { + return CHAR_MAP.getOrDefault(codePoint, HebrewDigitLetter.NONE); } } diff --git a/core/src/love/distributedrebirth/demo4d/fraction4d/HebrewDigitVowel.java b/core/src/love/distributedrebirth/demo4d/fraction4d/HebrewDigitVowel.java index 69a33d96..31542b45 100644 --- a/core/src/love/distributedrebirth/demo4d/fraction4d/HebrewDigitVowel.java +++ b/core/src/love/distributedrebirth/demo4d/fraction4d/HebrewDigitVowel.java @@ -1,5 +1,10 @@ package love.distributedrebirth.demo4d.fraction4d; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; +import java.util.stream.Collectors; + /** * * @author willemtsade ©Δ∞ 仙上主天 @@ -28,6 +33,9 @@ public enum HebrewDigitVowel { private final int fractionOffset; private final char character; + private static final Map CHAR_MAP = Collections.unmodifiableMap( + Arrays.asList(values()).stream().collect(Collectors.toMap(v -> v.getCharacter(), v -> v))); + private HebrewDigitVowel(int fractionOffset, char character) { this.fractionOffset = fractionOffset; this.character = character; @@ -45,12 +53,7 @@ public enum HebrewDigitVowel { return values()[index & BITMASK]; } - public static HebrewDigitVowel valueOf(char codePoint) { - for (HebrewDigitVowel vowel:values()) { - if (vowel.getCharacter() == codePoint) { - return vowel; - } - } - return HebrewDigitVowel.NONE; + public static HebrewDigitVowel valueOfCharacter(char codePoint) { + return CHAR_MAP.getOrDefault(codePoint, HebrewDigitVowel.NONE); } }