Is there a way to create an enum abstraction with different values based on enum names?
Here is a class where I would find something like abstract enum useful:
public class StatusUpdater {
public foo(bool one, bool two, bool three, AbstractEnum status) {
if (one) {
caseOne(status);
}
if (two) {
caseTwo(status);
}
if (three) {
caseThree(status);
}
}
private void caseOne(CaseOneEnum status) {
status.getValue(); //return case one value + case one implementation
}
private void caseTwo(CaseTwoEnum status) {
status.getValue(); //return case two value + case two implementation
}
private void caseThree(CaseThreeEnum status) {
status.getValue(); //return case three value + case three implementation
}
}
One Of the concrete implementation of enum looks like this:
public enum CaseOneEnum {
STATUS_ONE("one"),
STATUS_TWO("two");
private final String status;
CaseOneEnum(final String status) {
this.status = status;
}
@Override
String getValue(){return status;}
Another implementation will have same enum names, but different values:
public enum CaseTwoEnum {
STATUS_ONE("oneTwo"),
STATUS_TWO("twoTwo");
private final String status;
CaseTwoEnum(final String status) {
this.status = status;
}
@Override
String getValue(){return status;}
Calling the main method should look something like this:
updater.foo(true, true, false, AbstractEnum.STATUS_ONE);
Is there a way where I could create some "abstract" enum which i could pass to foo() and after checking the case take the concrete implementation of this enum. Enum names for all the concrete enums will stay the same, but values will differ. I would imagine an "abstract" enum something like this:
public enum AbstractEnum {
STATUS_ONE,
STATUS_TWO;
@Override
String getValue();
Is there a way of achieving something like that in a neat way?