]> git.basschouten.com Git - openhab-addons.git/blob
c912c430f547172aaace60236364f2bb69481286
[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.heos.internal.json.payload;
14
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.stream.Collectors;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20
21 import com.google.gson.annotations.SerializedName;
22
23 /**
24  * Data class for response payloads when retrieving group (information)
25  *
26  * @author Martin van Wingerden - Initial contribution
27  */
28 @NonNullByDefault
29 public class Group {
30     @SerializedName("gid")
31     public String id = "";
32     public String name = "";
33     public List<Player> players = Collections.emptyList();
34
35     public String getGroupMemberIds() {
36         return players.stream().map(p -> p.id).collect(Collectors.joining(";"));
37     }
38
39     public String getLeaderId() {
40         return players.stream().filter(p -> p.role == GroupPlayerRole.LEADER).map(p -> p.id).findFirst()
41                 .orElseThrow(() -> new IllegalStateException("Every group should have a leader"));
42     }
43
44     public static class Player {
45         @SerializedName("pid")
46         public String id = "";
47         public String name = "";
48         public GroupPlayerRole role = GroupPlayerRole.MEMBER;
49     }
50 }