]> git.basschouten.com Git - openhab-addons.git/blob
1d6d57554506266a58ba6896e6d21cda0132dca7
[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.bticinosmarther.internal.api.dto;
14
15 import static org.openhab.binding.bticinosmarther.internal.SmartherBindingConstants.NAME_SEPARATOR;
16
17 import java.util.List;
18 import java.util.stream.Collectors;
19
20 import org.eclipse.jdt.annotation.Nullable;
21
22 /**
23  * The {@code Modules} class defines the dto for Smarther API list of modules.
24  *
25  * @author Fabio Possieri - Initial contribution
26  */
27 public class Modules {
28
29     private List<Module> modules;
30
31     /**
32      * Returns the list of modules contained in this object.
33      *
34      * @return the list of modules
35      */
36     public @Nullable List<Module> getModules() {
37         return modules;
38     }
39
40     /**
41      * Converts a list of {@link Module} objects into a string containing the module names, comma separated.
42      *
43      * @param modules
44      *            the list of module objects to be converted, may be {@code null}
45      *
46      * @return a string containing the comma separated module names, or {@code null} if the list is {@code null} or
47      *         empty.
48      */
49     public static @Nullable String toNameString(@Nullable List<Module> modules) {
50         if (modules == null || modules.isEmpty()) {
51             return null;
52         }
53         return modules.stream().map(a -> String.valueOf(a.getName())).collect(Collectors.joining(NAME_SEPARATOR));
54     }
55 }