org.bidib.wizard.model.status.DirectionStatus Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bidibwizard-model Show documentation
Show all versions of bidibwizard-model Show documentation
jBiDiB BiDiB Wizard Model POM
The newest version!
package org.bidib.wizard.model.status;
import org.bidib.jbidibc.messages.enums.AddressTypeEnum;
import org.bidib.jbidibc.messages.enums.DirectionEnum;
public enum DirectionStatus implements BidibStatus {
// @formatter:off
FORWARD(DirectionEnum.FORWARD, "forward"), BACKWARD(DirectionEnum.BACKWARD, "backward");
// @formatter:on
private final DirectionEnum type;
private final String key;
DirectionStatus(DirectionEnum type, String key) {
this.type = type;
this.key = key;
}
@Override
public DirectionEnum getType() {
return type;
}
@Override
public String getKey() {
return key;
}
public static DirectionStatus valueOf(DirectionEnum type) {
DirectionStatus result = null;
for (DirectionStatus e : values()) {
if (e.type == type) {
result = e;
break;
}
}
if (result == null) {
throw new IllegalArgumentException("cannot map " + type + " to a direction");
}
return result;
}
public static DirectionStatus valueOf(AddressTypeEnum type) {
DirectionStatus result = null;
switch (type) {
case LOCOMOTIVE_BACKWARD:
result = BACKWARD;
break;
case LOCOMOTIVE_FORWARD:
result = FORWARD;
break;
default:
throw new IllegalArgumentException("cannot map " + type + " to a direction");
}
return result;
}
@Override
public DirectionStatus[] getValues() {
return new DirectionStatus[] { FORWARD, BACKWARD };
}
}