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

net.yudichev.jiotty.appliance.ApplianceStatus Maven / Gradle / Ivy

package net.yudichev.jiotty.appliance;

import com.google.common.collect.ImmutableMap;

import java.util.Map;

public enum ApplianceStatus {
    ON {
        @Override
        public boolean matches(Command command) {
            return command == PowerCommand.ON;
        }
    },
    OFF {
        @Override
        public boolean matches(Command command) {
            return command == PowerCommand.OFF;
        }
    },
    IN_TRANSITION {
        @Override
        public boolean matches(Command command) {
            return false;
        }
    };

    private static final Map COMMAND_TO_STATUS = ImmutableMap.of(PowerCommand.ON, ON, PowerCommand.OFF, OFF);

    public static ApplianceStatus forCommand(Command command) {
        return command.acceptOrFail((PowerCommand.Visitor) COMMAND_TO_STATUS::get);
    }

    public abstract boolean matches(Command command);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy