]> git.basschouten.com Git - openhab-addons.git/blob
08abf06d923ebe6549a6a6af969878e7527bdb48
[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.echonetlite.internal;
14
15 import static java.util.Objects.requireNonNull;
16 import static org.openhab.binding.echonetlite.internal.HexUtil.hex;
17
18 import java.net.InetSocketAddress;
19 import java.util.Objects;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23
24 /**
25  * @author Michael Barker - Initial contribution
26  */
27 @NonNullByDefault
28 public class InstanceKey {
29     final InetSocketAddress address;
30     final EchonetClass klass;
31     final int instance;
32
33     public InstanceKey(final InetSocketAddress address, final EchonetClass klass, final int instance) {
34         this.address = requireNonNull(address);
35         this.klass = requireNonNull(klass);
36         this.instance = instance;
37     }
38
39     @Override
40     public String toString() {
41         return "InstanceKey{" + "address=" + address + ", klass=" + klass + ", instance=" + instance + '}';
42     }
43
44     public String representationProperty() {
45         return address.getAddress().getHostAddress() + "_" + hex(klass.groupCode()) + ":" + hex(klass.classCode()) + ":"
46                 + hex(instance);
47     }
48
49     @Override
50     public boolean equals(@Nullable final Object o) {
51         if (this == o) {
52             return true;
53         }
54         if (o == null || getClass() != o.getClass()) {
55             return false;
56         }
57         final InstanceKey that = (InstanceKey) o;
58         return instance == that.instance && address.equals(that.address) && klass == that.klass;
59     }
60
61     @Override
62     public int hashCode() {
63         return Objects.hash(address, klass, instance);
64     }
65 }