2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.neeo.internal.models;
15 import java.util.Arrays;
16 import java.util.Objects;
18 import org.apache.commons.lang.StringUtils;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
23 * The model representing Neeo Recipes (serialize/deserialize json use only).
25 * @author Tim Roberts - Initial contribution
28 public class NeeoRecipes {
31 private NeeoRecipe @Nullable [] recipes;
34 * Creates the recipes from the given recipes
36 * @param recipes the recipes
38 NeeoRecipes(NeeoRecipe[] recipes) {
39 Objects.requireNonNull(recipes, "recipes cannot be null");
40 this.recipes = recipes;
48 public NeeoRecipe[] getRecipes() {
49 final NeeoRecipe[] localRecipes = recipes;
50 return localRecipes == null ? new NeeoRecipe[0] : localRecipes;
54 * Gets the recipe by key
57 * @return the recipe or null if none found
60 public NeeoRecipe getRecipe(String key) {
61 if (recipes == null || StringUtils.isEmpty(key)) {
65 for (NeeoRecipe recipe : getRecipes()) {
66 if (StringUtils.equalsIgnoreCase(key, recipe.getKey())) {
74 * Gets the recipe by a scenario key and recipe type
77 * @param type the recipe type
78 * @return the recipe or null if none found
81 public NeeoRecipe getRecipeByScenarioKey(String key, String type) {
82 if (recipes == null || StringUtils.isEmpty(key)) {
86 for (NeeoRecipe recipe : getRecipes()) {
87 if (StringUtils.equalsIgnoreCase(key, recipe.getScenarioKey())
88 && StringUtils.equalsIgnoreCase(type, recipe.getType())) {
96 * Gets the recipe by name
98 * @param name the recipe name
99 * @return the recipe or null if none found
102 public NeeoRecipe getRecipeByName(String name) {
103 if (recipes == null || StringUtils.isEmpty(name)) {
107 for (NeeoRecipe recipe : getRecipes()) {
108 if (StringUtils.equalsIgnoreCase(name, recipe.getName())) {
116 public String toString() {
117 return "NeeoRecipes [recipes=" + Arrays.toString(recipes) + "]";