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

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

The newest version!
package org.bidib.wizard.model.status;

import org.bidib.jbidibc.messages.enums.SwitchPortEnum;

public enum SwitchPortStatus implements BidibStatus {
    // @formatter:off
    ON(SwitchPortEnum.ON, "on"), OFF(SwitchPortEnum.OFF, "off"), TEST(SwitchPortEnum.TEST, "test");
    // @formatter:on

    private final SwitchPortEnum type;

    private final String key;

    SwitchPortStatus(SwitchPortEnum type, String key) {
        this.type = type;
        this.key = key;
    }

    @Override
    public SwitchPortEnum getType() {
        return type;
    }

    @Override
    public String getKey() {
        return key;
    }

    public static SwitchPortStatus valueOf(SwitchPortEnum type) {
        SwitchPortStatus result = null;

        for (SwitchPortStatus e : values()) {
            if (e.type == type) {
                result = e;
                break;
            }
        }
        if (result == null) {
            throw new IllegalArgumentException("cannot map " + type + " to a switch port status");
        }
        return result;
    }

    public static SwitchPortStatus fromString(String type) {
        SwitchPortStatus result = null;

        for (SwitchPortStatus e : values()) {
            if (e.key.equalsIgnoreCase(type)) {
                result = e;
                break;
            }
        }
        if (result == null) {
            throw new IllegalArgumentException("cannot map " + type + " to a switch port status");
        }
        return result;
    }

    @Override
    public SwitchPortStatus[] getValues() {
        return new SwitchPortStatus[] { ON, OFF, TEST };
    }

    @Override
    public SwitchPortStatus[] getMacroValues() {
        return new SwitchPortStatus[] { ON, OFF };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy