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