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