]> git.basschouten.com Git - openhab-addons.git/blob
bef446642cd8dda6335737122c29b6851561cd08
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.elerotransmitterstick.internal.stick;
14
15 import java.util.Arrays;
16 import java.util.concurrent.Delayed;
17 import java.util.concurrent.TimeUnit;
18
19 /**
20  * @author Volker Bier - Initial contribution
21  */
22 public class Command implements Delayed {
23     public static final int TIMED_PRIORITY = 30;
24     public static final int COMMAND_PRIORITY = 20;
25     public static final int FAST_INFO_PRIORITY = 10;
26     public static final int INFO_PRIORITY = 0;
27
28     private Integer[] channelId;
29     private CommandType commandType;
30
31     protected int priority = COMMAND_PRIORITY;
32
33     public Command(final CommandType cmd, final Integer... channels) {
34         channelId = channels;
35         commandType = cmd;
36     }
37
38     protected Command(final CommandType cmd, int priority, final Integer... channels) {
39         this(cmd, channels);
40
41         this.priority = priority;
42     }
43
44     @Override
45     public String toString() {
46         return "Command " + commandType + " on channels " + Arrays.toString(channelId) + " with priority " + priority;
47     }
48
49     @Override
50     public int compareTo(Delayed delayed) {
51         if (delayed == this) {
52             return 0;
53         }
54
55         return Long.compare(0, delayed.getDelay(TimeUnit.MILLISECONDS));
56     }
57
58     @Override
59     public long getDelay(TimeUnit unit) {
60         return 0;
61     }
62
63     public int getPriority() {
64         return priority;
65     }
66
67     public Integer[] getChannelIds() {
68         return channelId;
69     }
70
71     public CommandType getCommandType() {
72         return commandType;
73     }
74 }