]> git.basschouten.com Git - openhab-addons.git/blob
82fb5b28a8f47b4270b36913e3b8587c55a7d0c0
[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.resources;
14
15 import java.util.Arrays;
16 import java.util.List;
17 import java.util.stream.Collectors;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.heos.internal.json.payload.Group;
21
22 /**
23  * The {@link HeosGroup} represents the group within the
24  * HEOS network
25  *
26  * @author Johannes Einig - Initial contribution
27  */
28 @NonNullByDefault
29 public class HeosGroup {
30     public static String calculateGroupMemberHash(Group group) {
31         List<String> sortedPlayerIds = group.players.stream().map(player -> player.id).sorted()
32                 .collect(Collectors.toList());
33
34         return sortedToString(sortedPlayerIds);
35     }
36
37     private static String sortedToString(List<String> sortedPlayerIds) {
38         return Integer.toUnsignedString(sortedPlayerIds.hashCode());
39     }
40
41     public static String calculateGroupMemberHash(String members) {
42         List<String> sortedPlayerIds = Arrays.stream(members.split(";")).sorted().collect(Collectors.toList());
43
44         return sortedToString(sortedPlayerIds);
45     }
46 }