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