]> git.basschouten.com Git - openhab-addons.git/blob
d65d0772d6ce51aaa5135c1fba86f442385ccc7d
[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.neeo.internal.models;
14
15 import java.util.Arrays;
16 import java.util.Objects;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 /**
22  * The model representing Neeo Rooms (serialize/deserialize json use only).
23  *
24  * @author Tim Roberts - Initial contribution
25  */
26 @NonNullByDefault
27 public class NeeoRooms {
28
29     /** The rooms. */
30     private final NeeoRoom @Nullable [] rooms;
31
32     /**
33      * Instantiates a new neeo rooms.
34      *
35      * @param rooms the rooms
36      */
37     NeeoRooms(NeeoRoom[] rooms) {
38         Objects.requireNonNull(rooms, "rooms cannot be null");
39         this.rooms = rooms;
40     }
41
42     /**
43      * Gets the rooms.
44      *
45      * @return the rooms
46      */
47     public NeeoRoom[] getRooms() {
48         final NeeoRoom @Nullable [] localRooms = rooms;
49         return localRooms == null ? new NeeoRoom[0] : localRooms;
50     }
51
52     /**
53      * Gets the room.
54      *
55      * @param key the key
56      * @return the room
57      */
58     NeeoRoom getRoom(String key) {
59         for (NeeoRoom room : getRooms()) {
60             if (key.equalsIgnoreCase(room.getKey())) {
61                 return room;
62             }
63         }
64         return new NeeoRoom();
65     }
66
67     @Override
68     public String toString() {
69         return "NeeoRooms [rooms=" + Arrays.toString(rooms) + "]";
70     }
71 }