All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bidib.wizard.model.status.DirectionStatus Maven / Gradle / Ivy

There is a newer version: 2.0.26
Show 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 };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy