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];
}
public static Optional<FourCornerDotCake> valueFromCakePoint(int cakePoint) {
for (FourCornerDotCake cakeSlice : VALUES) {
if (cakeSlice.contains(cakePoint)) {
return Optional.of(cakeSlice);
public static Optional<FourCornerDotCake> valueFromCakePoint(final int cakePoint) {
final int valuesLength = VALUES.length;
for (int i = 0; i < valuesLength; i++) {
FourCornerDotCake cake = VALUES[i];
if (cake.contains(cakePoint)) {
return Optional.of(cake);
}
}
return Optional.empty();
}
static public List<FourCornerDotCake> valuesByTower(FourCornerDotCakeTower tower) {
List<FourCornerDotCake> result = new ArrayList<>();
for (int i = 0; i < VALUES.length; i++) {
static public List<FourCornerDotCake> valuesByTower(final FourCornerDotCakeTower tower) {
final List<FourCornerDotCake> result = new ArrayList<>();
final int valuesLength = VALUES.length;
for (int i = 0; i < valuesLength; i++) {
FourCornerDotCake cake = VALUES[i];
if (cake.tower().equals(tower)) {
result.add(cake);

View file

@ -38,7 +38,7 @@ public enum FourCornerDotCakeTower {
TXT_KODES("Special koder words"),
TXT_EMBEDS("Embedded data words"),
;
private static final FourCornerDotCakeTower[] VALUES = values();
private final String nameNice;
private final String description;
@ -54,4 +54,12 @@ public enum FourCornerDotCakeTower {
public String 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) {
for (FourCornerDotColleCLKParler lookup : clockParlers()) {
if (lookup.parlerMerde() == merde) {
if (lookup.parlerEau() == merde) {
return Optional.of(lookup);
}
}

View file

@ -30,7 +30,7 @@ package org.x4o.fc18.cake2;
*/
public interface FourCornerDotColleCLKParler {
FourCornerDotColleCLKParlerEau parlerMerde();
FourCornerDotColleCLKParlerEau parlerEau();
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
//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() {
this.parlerToken = name().toLowerCase();
}
@Override
public FourCornerDotColleCLKParlerEau parlerMerde() {
public FourCornerDotColleCLKParlerEau parlerEau() {
return FourCornerDotColleCLKParlerEau.this;
}
@Override
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.
public FourCornerDotColleCLKParler parlerJeton(String token) {
public FourCornerDotColleCLKParler parlerJeton(final String token) {
Objects.requireNonNull(token);
return new FourCornerDotColleCLKParler() {
@Override
public FourCornerDotColleCLKParlerEau parlerMerde() {
public FourCornerDotColleCLKParlerEau parlerEau() {
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_R40,
;
private static final FourCornerX00PetitVideCoinCarneFrapperRetrait[] VALUES = values();
private FourCornerX00PetitVideCoinCarneFrapperRetrait() {
}
static public int valuesLength() {
return VALUES.length;
}
static public FourCornerX00PetitVideCoinCarneFrapperRetrait valueOf(int idx) {
return VALUES[idx];
}
static public FourCornerX00PetitVideCoinCarneFrapperRetrait valueNone() {
return NONE;
}