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.russound.internal.rio.models;
15 import java.util.concurrent.atomic.AtomicReference;
17 import org.eclipse.jdt.annotation.Nullable;
20 * Simple model of a RIO Bank and it's attributes. Please note this class is used to serialize/deserialize to JSON.
22 * @author Tim Roberts - Initial contribution
24 public class RioBank {
33 private final AtomicReference<String> name = new AtomicReference<>(null);
36 * Create the object from the given ID (using the default name of "Bank" + id)
38 * @param id a bank identifier between 1 and 6
39 * @throws IllegalArgumentException if id is < 1 or > 6
41 public RioBank(int id) {
46 * Create the object from the given ID and given name. If the name is empty or null, the name will default to ("Bank
49 * @param id a bank identifier between 1 and 6
50 * @param name a possibly null, possibly empty bank name (null or empty will result in a bank name of "Bank "+ id)
51 * @throws IllegalArgumentException if id is < 1 or > 6
53 public RioBank(int id, @Nullable String name) {
54 if (id < 1 || id > 6) {
55 throw new IllegalArgumentException("Bank ID can only be between 1 and 6");
58 this.name.set(name == null || name.isEmpty() ? "Bank " + id : name);
62 * Returns the bank identifier
64 * @return the bank identifier between 1 and 6
71 * Returns the bank name
73 * @return a non-null, non-empty bank name
75 public String getName() {
80 * Sets the bank name. If empty or a null, name defaults to "Bank " + getId()
82 * @param bankName a possibly null, possibly empty bank name
84 public void setName(@Nullable String bankName) {
85 name.set(bankName == null || bankName.isEmpty() ? "Bank " + getId() : bankName);