Redone hewbrew char lookup

This commit is contained in:
Willem Cazander 2022-01-29 12:39:43 +01:00
parent 887399e49c
commit 577cc68a61
3 changed files with 22 additions and 16 deletions

View file

@ -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));
}

View file

@ -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<Character, HebrewDigitLetter> 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);
}
}

View file

@ -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<Character, HebrewDigitVowel> 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);
}
}