2 * Copyright (c) 2010-2022 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.AtomicBoolean;
16 import java.util.concurrent.atomic.AtomicReference;
18 import org.eclipse.jdt.annotation.Nullable;
21 * Simple model of a RIO Favorite (both system and zone) and it's attributes. Please note this class is used to
22 * serialize/deserialize to JSON.
24 * @author Tim Roberts - Initial contribution
26 public class RioFavorite {
33 * Whether the favorite is valid or not
35 private final AtomicBoolean valid = new AtomicBoolean(false);
40 private final AtomicReference<String> name = new AtomicReference<>(null);
43 * Simply creates the favorite from the given ID. The favorite will not be valid and the name will default to
46 * @param id a favorite ID between 1 and 32
47 * @throws IllegalArgumentException if id < 1 or > 32
49 public RioFavorite(int id) {
50 this(id, false, null);
54 * Creates the favorite from the given ID, validity and name. If the name is empty or null, it will default to
57 * @param id a favorite ID between 1 and 32
58 * @param isValid true if the favorite is valid, false otherwise
59 * @param name a possibly null, possibly empty favorite name
60 * @throws IllegalArgumentException if id < 1 or > 32
62 public RioFavorite(int id, boolean isValid, @Nullable String name) {
63 if (id < 1 || id > 32) {
64 throw new IllegalArgumentException("Favorite ID must be between 1 and 32");
68 this.valid.set(isValid);
69 this.name.set(name == null || name.isEmpty() ? "Favorite " + id : name);
73 * Returns the favorite identifier
75 * @return a favorite id between 1 and 32
82 * Returns true if the favorite is valid, false otherwise
84 * @return true if valid, false otherwise
86 public boolean isValid() {
91 * Sets whether the favorite is valid or not
93 * @param favValid true if valid, false otherwise
95 public void setValid(boolean favValid) {
100 * Set's the favorite name. If null or empty, will default to "Favorite " + getId()
102 * @param favName a possibly null, possibly empty favorite name
104 public void setName(@Nullable String favName) {
105 name.set(favName == null || favName.isEmpty() ? "Favorite " + getId() : favName);
109 * Returns the favorite name
111 * @return a non-null, non-empty favorite name
113 public String getName() {