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;
16 * The {@link BluetoothAddress} class defines a bluetooth address
18 * @author Chris Jackson - Initial contribution
20 public class BluetoothAddress {
22 public static final int BD_ADDRESS_LENGTH = 17;
24 private final String address;
27 * The default constructor
29 * @param address the device address
31 public BluetoothAddress(String address) {
32 if (address == null || address.length() != BD_ADDRESS_LENGTH) {
33 throw new IllegalArgumentException("BT Address cannot be null and must be in format XX:XX:XX:XX:XX:XX");
35 for (int i = 0; i < BD_ADDRESS_LENGTH; i++) {
36 char c = address.charAt(i);
38 // Check address - 2 bytes should be hex, and then a colon
40 case 0: // fall through
42 if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) {
45 throw new IllegalArgumentException("BT Address must contain upper case hex values only");
50 throw new IllegalArgumentException("BT Address bytes must be separated with colon");
54 this.address = address;
58 public int hashCode() {
61 result = prime * result + ((address == null) ? 0 : address.hashCode());
66 public boolean equals(Object obj) {
73 if (getClass() != obj.getClass()) {
76 BluetoothAddress other = (BluetoothAddress) obj;
77 if (address == null) {
78 if (other.address != null) {
81 } else if (!address.equals(other.address)) {
88 public String toString() {