2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.bluetooth;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
19 * The {@link BluetoothAddress} class defines a bluetooth address
21 * @author Chris Jackson - Initial contribution
24 public class BluetoothAddress {
26 public static final int BD_ADDRESS_LENGTH = 17;
28 private final String address;
31 * The default constructor
33 * @param address the device address
35 public BluetoothAddress(@Nullable String address) {
36 if (address == null || address.length() != BD_ADDRESS_LENGTH) {
37 throw new IllegalArgumentException("BT Address cannot be null and must be in format XX:XX:XX:XX:XX:XX");
39 for (int i = 0; i < BD_ADDRESS_LENGTH; i++) {
40 char c = address.charAt(i);
42 // Check address - 2 bytes should be hex, and then a colon
44 case 0: // fall through
46 if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) {
49 throw new IllegalArgumentException("BT Address must contain upper case hex values only");
54 throw new IllegalArgumentException("BT Address bytes must be separated with colon");
58 this.address = address;
62 public int hashCode() {
65 result = prime * result + address.hashCode();
70 public boolean equals(@Nullable Object obj) {
77 if (getClass() != obj.getClass()) {
80 BluetoothAddress other = (BluetoothAddress) obj;
82 return address.equals(other.address);
86 public String toString() {