org.bidib.wizard.model.status.CommandStationStatus Maven / Gradle / Ivy
package org.bidib.wizard.model.status;
import org.bidib.jbidibc.messages.enums.CommandStationState;
public enum CommandStationStatus implements BidibStatus {
// @formatter:off
OFF(CommandStationState.OFF, "off"),
STOP(CommandStationState.STOP, "stop"),
SOFTSTOP(CommandStationState.SOFTSTOP, "softstop"),
GO(CommandStationState.GO, "go"),
PROG(CommandStationState.PROG, "prog"),
PROGBUSY(CommandStationState.PROGBUSY, "progbusy"),
BUSY(CommandStationState.BUSY, "busy"),
QUERY(CommandStationState.QUERY, "query"),
GO_IGN_WD(CommandStationState.GO_IGN_WD, "go-ign-wd");
// @formatter:on
private final CommandStationState commandStationState;
private final String key;
CommandStationStatus(CommandStationState commandStationState, String key) {
this.commandStationState = commandStationState;
this.key = key;
}
public CommandStationState getCommandStationState() {
return commandStationState;
}
@Override
public CommandStationState getType() {
return commandStationState;
}
@Override
public String getKey() {
return key;
}
public static CommandStationStatus valueOf(CommandStationState commandStationState) {
CommandStationStatus result = null;
for (CommandStationStatus e : values()) {
if (e.commandStationState == commandStationState) {
result = e;
break;
}
}
if (result == null) {
throw new IllegalArgumentException("cannot map " + commandStationState + " to a command station status");
}
return result;
}
public static CommandStationStatus fromString(String commandStationState) {
CommandStationStatus result = null;
for (CommandStationStatus e : values()) {
if (e.key.equalsIgnoreCase(commandStationState)) {
result = e;
break;
}
}
if (result == null) {
throw new IllegalArgumentException("cannot map " + commandStationState + " to a command station status");
}
return result;
}
@Override
public CommandStationStatus[] getValues() {
return new CommandStationStatus[] { OFF, STOP, SOFTSTOP, GO, PROG, PROGBUSY, BUSY, QUERY, GO_IGN_WD };
}
public static boolean isOnState(CommandStationStatus commandStationState) {
return !isPtProgState(commandStationState) && !isOffState(commandStationState);
}
public static boolean isOffState(CommandStationStatus commandStationState) {
if (commandStationState == null) {
// Cannot check if command station if off because the commandStationState is null but assuming it's off.
return true;
}
boolean isOffState = false;
switch (commandStationState) {
case OFF:
case STOP:
case SOFTSTOP:
isOffState = true;
break;
default:
break;
}
return isOffState;
}
public static boolean isPtProgState(CommandStationStatus commandStationState) {
boolean isPtProgState = false;
switch (commandStationState) {
case PROG:
case PROGBUSY:
isPtProgState = true;
break;
default:
break;
}
return isPtProgState;
}
}