2 * Copyright (c) 2010-2023 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.digitalstrom.internal.lib.structure.impl;
15 import java.util.LinkedList;
16 import java.util.List;
18 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.constants.JSONApiResponseKeysEnum;
19 import org.openhab.binding.digitalstrom.internal.lib.structure.DetailedGroupInfo;
21 import com.google.gson.JsonArray;
22 import com.google.gson.JsonObject;
25 * The {@link JSONDetailedGroupInfoImpl} is the implementation of the {@link DetailedGroupInfo}.
27 * @author Alexander Betker - Initial contribution
28 * @author Michael Ochel - change from SimpleJSON to GSON
29 * @author Matthias Siegele - change from SimpleJSON to GSON
31 public class JSONDetailedGroupInfoImpl implements DetailedGroupInfo {
34 private short groupId = 0;
35 private final List<String> deviceList;
38 * Creates a new {@link JSONDetailedGroupInfoImpl} through the {@link JsonObject}.
40 * @param jObject of the server response, must not be null
42 public JSONDetailedGroupInfoImpl(JsonObject jObject) {
43 this.deviceList = new LinkedList<>();
44 if (jObject.get(JSONApiResponseKeysEnum.NAME.getKey()) != null) {
45 name = jObject.get(JSONApiResponseKeysEnum.NAME.getKey()).getAsString();
47 if (jObject.get(JSONApiResponseKeysEnum.ID.getKey()) != null) {
48 this.groupId = jObject.get(JSONApiResponseKeysEnum.ID.getKey()).getAsShort();
50 if (jObject.get(JSONApiResponseKeysEnum.DEVICES.getKey()) instanceof JsonArray) {
51 JsonArray array = (JsonArray) jObject.get(JSONApiResponseKeysEnum.DEVICES.getKey());
53 for (int i = 0; i < array.size(); i++) {
54 if (array.get(i) != null) {
55 deviceList.add(array.get(i).getAsString());
62 public short getGroupID() {
67 public String getGroupName() {
72 public List<String> getDeviceList() {
77 public boolean equals(Object obj) {
78 if (obj instanceof DetailedGroupInfo) {
79 DetailedGroupInfo group = (DetailedGroupInfo) obj;
80 return group.getGroupID() == this.getGroupID();