]> git.basschouten.com Git - openhab-addons.git/blob
1006293266b010f2cbec538dd6cd29a8413fe6a1
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.tacmi.internal.coe;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.tacmi.internal.message.MessageType;
18
19 /**
20  * This class defines a key for POD identification
21  *
22  * @author Christian Niessner - Initial contribution
23  */
24 @NonNullByDefault
25 public final class PodIdentifier {
26     public final MessageType messageType;
27     public final byte podId;
28     public final boolean outgoing;
29
30     /**
31      * Create new AnalogValue with specified value and type
32      */
33     public PodIdentifier(MessageType messageType, byte podId, boolean outgoing) {
34         this.messageType = messageType;
35         if (podId < 0) {
36             throw new ArrayIndexOutOfBoundsException(podId);
37         }
38         switch (messageType) {
39             case ANALOG:
40                 if (podId < 1 || podId > 8) {
41                     throw new ArrayIndexOutOfBoundsException(podId);
42                 }
43                 break;
44             case DIGITAL:
45                 if (podId != 0 && podId != 9) {
46                     throw new ArrayIndexOutOfBoundsException(podId);
47                 }
48                 break;
49         }
50         this.podId = podId;
51         this.outgoing = outgoing;
52     }
53
54     @Override
55     public int hashCode() {
56         return (this.messageType.ordinal() << 8) | podId | (outgoing ? 0x10000 : 0);
57     }
58
59     @Override
60     public boolean equals(@Nullable Object o) {
61         if (!(o instanceof PodIdentifier)) {
62             return false;
63         }
64         PodIdentifier po = (PodIdentifier) o;
65         return this.messageType == po.messageType && this.podId == po.podId && this.outgoing == po.outgoing;
66     }
67 }