]> git.basschouten.com Git - openhab-addons.git/blob
21e2d00113b951b8183529db21530553ce1deb8f
[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 Devices (serialize/deserialize json use only).
23  *
24  * @author Tim Roberts - Initial contribution
25  */
26 @NonNullByDefault
27 public class NeeoDevices {
28
29     /** The devices. */
30     private final NeeoDevice @Nullable [] devices;
31
32     /**
33      * Instantiates a new neeo devices.
34      *
35      * @param devices the devices
36      */
37     NeeoDevices(NeeoDevice[] devices) {
38         Objects.requireNonNull(devices, "devices cannot be null");
39         this.devices = devices;
40     }
41
42     /**
43      * Gets the devices.
44      *
45      * @return the devices
46      */
47     public NeeoDevice[] getDevices() {
48         final NeeoDevice[] localDevices = devices;
49         return localDevices == null ? new NeeoDevice[0] : localDevices;
50     }
51
52     /**
53      * Gets the device.
54      *
55      * @param key the key
56      * @return the device
57      */
58     @Nullable
59     public NeeoDevice getDevice(String key) {
60         for (NeeoDevice device : getDevices()) {
61             if (key.equalsIgnoreCase(device.getKey())) {
62                 return device;
63             }
64         }
65         return null;
66     }
67
68     @Override
69     public String toString() {
70         return "NeeoDevice [devices=" + Arrays.toString(devices) + "]";
71     }
72 }