Added more support for fast enums

This commit is contained in:
Willem Cazander 2025-01-25 16:14:59 +01:00
parent 814e6fe339
commit b245622119
6 changed files with 45 additions and 14 deletions

View file

@ -478,18 +478,21 @@ public enum FourCornerDotCake {
return VALUES[idx]; return VALUES[idx];
} }
public static Optional<FourCornerDotCake> valueFromCakePoint(int cakePoint) { public static Optional<FourCornerDotCake> valueFromCakePoint(final int cakePoint) {
for (FourCornerDotCake cakeSlice : VALUES) { final int valuesLength = VALUES.length;
if (cakeSlice.contains(cakePoint)) { for (int i = 0; i < valuesLength; i++) {
return Optional.of(cakeSlice); FourCornerDotCake cake = VALUES[i];
if (cake.contains(cakePoint)) {
return Optional.of(cake);
} }
} }
return Optional.empty(); return Optional.empty();
} }
static public List<FourCornerDotCake> valuesByTower(FourCornerDotCakeTower tower) { static public List<FourCornerDotCake> valuesByTower(final FourCornerDotCakeTower tower) {
List<FourCornerDotCake> result = new ArrayList<>(); final List<FourCornerDotCake> result = new ArrayList<>();
for (int i = 0; i < VALUES.length; i++) { final int valuesLength = VALUES.length;
for (int i = 0; i < valuesLength; i++) {
FourCornerDotCake cake = VALUES[i]; FourCornerDotCake cake = VALUES[i];
if (cake.tower().equals(tower)) { if (cake.tower().equals(tower)) {
result.add(cake); result.add(cake);

View file

@ -38,7 +38,7 @@ public enum FourCornerDotCakeTower {
TXT_KODES("Special koder words"), TXT_KODES("Special koder words"),
TXT_EMBEDS("Embedded data words"), TXT_EMBEDS("Embedded data words"),
; ;
private static final FourCornerDotCakeTower[] VALUES = values();
private final String nameNice; private final String nameNice;
private final String description; private final String description;
@ -54,4 +54,12 @@ public enum FourCornerDotCakeTower {
public String description() { public String description() {
return description; return description;
} }
static public int valuesLength() {
return VALUES.length;
}
static public FourCornerDotCakeTower valueOf(int idx) {
return VALUES[idx];
}
} }

View file

@ -37,7 +37,7 @@ public interface FourCornerDotColleCLK extends FourCornerX18CakePointDotIndex {
default Optional<FourCornerDotColleCLKParler> clockParlerEau(FourCornerDotColleCLKParlerEau merde) { default Optional<FourCornerDotColleCLKParler> clockParlerEau(FourCornerDotColleCLKParlerEau merde) {
for (FourCornerDotColleCLKParler lookup : clockParlers()) { for (FourCornerDotColleCLKParler lookup : clockParlers()) {
if (lookup.parlerMerde() == merde) { if (lookup.parlerEau() == merde) {
return Optional.of(lookup); return Optional.of(lookup);
} }
} }

View file

@ -30,7 +30,7 @@ package org.x4o.fc18.cake2;
*/ */
public interface FourCornerDotColleCLKParler { public interface FourCornerDotColleCLKParler {
FourCornerDotColleCLKParlerEau parlerMerde(); FourCornerDotColleCLKParlerEau parlerEau();
String parlerToken(); String parlerToken();
} }

View file

@ -48,27 +48,30 @@ public enum FourCornerDotColleCLKParlerEau implements FourCornerDotColleCLKParle
//FORTRAN // Leave out "openMP" junk because REAL computers have no shared memory model //FORTRAN // Leave out "openMP" junk because REAL computers have no shared memory model
//SQL // TODO: After (~full) SQL is added do cleanup of duplicate/abbr... CLK1K entries //SQL // TODO: After (~full) SQL is added do cleanup of duplicate/abbr... CLK1K entries
; ;
private static final FourCornerDotColleCLKParlerEau[] VALUES = values();
private final String parlerToken;
private FourCornerDotColleCLKParlerEau() { private FourCornerDotColleCLKParlerEau() {
this.parlerToken = name().toLowerCase();
} }
@Override @Override
public FourCornerDotColleCLKParlerEau parlerMerde() { public FourCornerDotColleCLKParlerEau parlerEau() {
return FourCornerDotColleCLKParlerEau.this; return FourCornerDotColleCLKParlerEau.this;
} }
@Override @Override
public String parlerToken() { public String parlerToken() {
return name().toLowerCase(); return parlerToken;
} }
/// NOTE this is not really for parsing, after moving to nether DB it gets full version-ed mapping per language and dialect. /// NOTE this is not really for parsing, after moving to nether DB it gets full version-ed mapping per language and dialect.
public FourCornerDotColleCLKParler parlerJeton(String token) { public FourCornerDotColleCLKParler parlerJeton(final String token) {
Objects.requireNonNull(token); Objects.requireNonNull(token);
return new FourCornerDotColleCLKParler() { return new FourCornerDotColleCLKParler() {
@Override @Override
public FourCornerDotColleCLKParlerEau parlerMerde() { public FourCornerDotColleCLKParlerEau parlerEau() {
return FourCornerDotColleCLKParlerEau.this; return FourCornerDotColleCLKParlerEau.this;
} }
@ -78,4 +81,12 @@ public enum FourCornerDotColleCLKParlerEau implements FourCornerDotColleCLKParle
} }
}; };
} }
static public int valuesLength() {
return VALUES.length;
}
static public FourCornerDotColleCLKParlerEau valueOf(int idx) {
return VALUES[idx];
}
} }

View file

@ -60,10 +60,19 @@ public enum FourCornerX00PetitVideCoinCarneFrapperRetrait {
BOTH_L40_R30, BOTH_L40_R30,
BOTH_L40_R40, BOTH_L40_R40,
; ;
private static final FourCornerX00PetitVideCoinCarneFrapperRetrait[] VALUES = values();
private FourCornerX00PetitVideCoinCarneFrapperRetrait() { private FourCornerX00PetitVideCoinCarneFrapperRetrait() {
} }
static public int valuesLength() {
return VALUES.length;
}
static public FourCornerX00PetitVideCoinCarneFrapperRetrait valueOf(int idx) {
return VALUES[idx];
}
static public FourCornerX00PetitVideCoinCarneFrapperRetrait valueNone() { static public FourCornerX00PetitVideCoinCarneFrapperRetrait valueNone() {
return NONE; return NONE;
} }