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.asuswrt.internal.structures;
15 import java.util.ArrayList;
16 import java.util.Iterator;
17 import java.util.List;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import com.google.gson.JsonObject;
24 * The {@link AsuswrtInterfaceList} class stores a list of {@link AsuswrtIpInfo}.
26 * @author Christian Wild - Initial contribution
29 public class AsuswrtInterfaceList implements Iterable<AsuswrtIpInfo> {
30 private List<AsuswrtIpInfo> ipInfoList = new ArrayList<>();
32 public AsuswrtInterfaceList() {
36 public Iterator<AsuswrtIpInfo> iterator() {
37 return ipInfoList.iterator();
45 * Adds an {@link AsuswrtIpInfo} to the list.
47 private void addInterface(AsuswrtIpInfo ipInfo) {
48 ipInfoList.add(ipInfo);
52 * Sets the {@link AsuswrtInterfaceList} using a {@link JsonObject}.
54 public void setData(String ifName, JsonObject jsonObject) {
55 if (hasInterface(ifName)) {
56 getByName(ifName).setData(jsonObject);
58 addInterface(new AsuswrtIpInfo(ifName, jsonObject));
67 * Gets {@link AsuswrtIpInfo} from the list for an interface based on its name.
69 * @param ifName the name of the interface for which the info is returned
71 public AsuswrtIpInfo getByName(String ifName) {
72 for (AsuswrtIpInfo ipInfo : ipInfoList) {
73 if (ipInfo.getName().equals(ifName)) {
77 return new AsuswrtIpInfo();
81 * Gets {@link AsuswrtIpInfo} from the list for an interface based on its MAC address.
83 * @param ipInfoMAC the MAC address of the interface for which the info is returned
85 public AsuswrtIpInfo getByMAC(String ipInfoMAC) {
86 for (AsuswrtIpInfo ipInfo : ipInfoList) {
87 if (ipInfo.getMAC().equals(ipInfoMAC)) {
91 return new AsuswrtIpInfo();
95 * Gets {@link AsuswrtIpInfo} from the list for an interface based on its IP address.
97 * @param ipAddress the IP address of the interface for which the info is returned
99 public AsuswrtIpInfo getByIP(String ipAddress) {
100 for (AsuswrtIpInfo ipInfo : ipInfoList) {
101 if (ipInfo.getIpAddress().equals(ipAddress)) {
105 return new AsuswrtIpInfo();
109 * Checks if an interface with the given name is in the list.
111 * @param ifName the name of the interface
113 public boolean hasInterface(String ifName) {
114 for (AsuswrtIpInfo ipInfo : ipInfoList) {
115 if (ipInfo.getName().equals(ifName)) {