My question is, how to write this in python? Is something like this possible?
How it should work: I'm getting data from an algorithm that will decide which letter to output. If there are certain conditions in the data that should not apply to one character, the conditions should be checked for another character. The data and the conditions are of course more complex than shown here.
Why enums: Because only this small main method has to be written in the algorithm file (iterable). And the conditions of the letters are encapsulated in another file and clearly structured.
enum Letter {
A () {
public boolean condition(int[] args) {
if (args[0] > args[1]) return false;
if (args[1] > args[2]) return false;
return true;
}
},
B () {
public boolean condition(int[] args) {
if (args[0] > args[1]) return false;
if (args[1] < args[2]) return false;
return true;
}
},
C () {
public boolean condition(int[] args) {
if (args[0] < args[1]) return false;
if (args[1] < args[2]) return false;
return true;
}
};
public abstract boolean condition(int[] args);
}
public class Alphabet {
public static void main(String[] args) {
int[] arr = {1, 2, 3};
//int[] arr = {1, 2, 1};
//int[] arr = {3, 2, 1};
for (Letter l : Letter.values()) {
if (l.condition(arr)) {
System.out.println(l);
break;
}
}
}
}