]> git.basschouten.com Git - openhab-addons.git/blob
36001a2c2b32dc2d0a94663d6f7a9bc0dcb8c432
[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.russound.internal.rio.models;
14
15 import java.util.concurrent.atomic.AtomicReference;
16
17 import org.eclipse.jdt.annotation.Nullable;
18
19 /**
20  * Simple model of a RIO Bank and it's attributes. Please note this class is used to serialize/deserialize to JSON.
21  *
22  * @author Tim Roberts - Initial contribution
23  */
24 public class RioBank {
25     /**
26      * The Bank ID
27      */
28     private final int id;
29
30     /**
31      * The Bank Name
32      */
33     private final AtomicReference<String> name = new AtomicReference<>(null);
34
35     /**
36      * Create the object from the given ID (using the default name of "Bank" + id)
37      *
38      * @param id a bank identifier between 1 and 6
39      * @throws IllegalArgumentException if id is < 1 or > 6
40      */
41     public RioBank(int id) {
42         this(id, null);
43     }
44
45     /**
46      * Create the object from the given ID and given name. If the name is empty or null, the name will default to ("Bank
47      * " + id)
48      *
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
52      */
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");
56         }
57         this.id = id;
58         this.name.set(name == null || name.isEmpty() ? "Bank " + id : name);
59     }
60
61     /**
62      * Returns the bank identifier
63      *
64      * @return the bank identifier between 1 and 6
65      */
66     public int getId() {
67         return id;
68     }
69
70     /**
71      * Returns the bank name
72      *
73      * @return a non-null, non-empty bank name
74      */
75     public String getName() {
76         return name.get();
77     }
78
79     /**
80      * Sets the bank name. If empty or a null, name defaults to "Bank " + getId()
81      *
82      * @param bankName a possibly null, possibly empty bank name
83      */
84     public void setName(@Nullable String bankName) {
85         name.set(bankName == null || bankName.isEmpty() ? "Bank " + getId() : bankName);
86     }
87 }