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