From c836f1ecb993d2245905afedf86989c82de7cfc2 Mon Sep 17 00:00:00 2001 From: TheMidgetWidget Date: Tue, 28 Sep 2021 14:55:14 +0200 Subject: [PATCH] Add Topology classes --- .../github/khalidzahra/topology/Topology.java | 41 +++++++++++++++++++ .../topology/TopologyRegistry.java | 29 +++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/main/java/com/github/khalidzahra/topology/Topology.java create mode 100644 src/main/java/com/github/khalidzahra/topology/TopologyRegistry.java diff --git a/src/main/java/com/github/khalidzahra/topology/Topology.java b/src/main/java/com/github/khalidzahra/topology/Topology.java new file mode 100644 index 0000000..b538081 --- /dev/null +++ b/src/main/java/com/github/khalidzahra/topology/Topology.java @@ -0,0 +1,41 @@ +package com.github.khalidzahra.topology; + +import com.github.khalidzahra.component.Component; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Khalid on 9/28/21. + */ +public class Topology { + + private String id; + private List components; + + public Topology(String id) { + this.id = id; + this.components = new ArrayList<>(); + } + + public Topology(String id, List componentList) { + this.id = id; + this.components = componentList; + } + + public List getComponentsConnectedToNode(String nodeId) { + return this.components.stream().filter(component -> component.getNetList().containsValue(nodeId)).toList(); + } + + public void addComponent(Component component) { + components.add(component); + } + + public String getId() { + return id; + } + + public List getComponents() { + return components; + } +} diff --git a/src/main/java/com/github/khalidzahra/topology/TopologyRegistry.java b/src/main/java/com/github/khalidzahra/topology/TopologyRegistry.java new file mode 100644 index 0000000..d8f52f0 --- /dev/null +++ b/src/main/java/com/github/khalidzahra/topology/TopologyRegistry.java @@ -0,0 +1,29 @@ +package com.github.khalidzahra.topology; + +import java.util.List; + +/** + * Created by Khalid on 9/28/21. + */ +public class TopologyRegistry { + + private static List topologyList; + + public static void registerTopology(Topology topology) { + topologyList.add(topology); + } + + public static Topology findTopology(String id) { + return topologyList.stream().filter(topology -> topology.getId().equals(id)).findAny().orElse(null); + } + + public static boolean deregisterTopology(String id) { + Topology topology = findTopology(id); + if (topology == null) return false; + return topologyList.remove(topology); + } + + public static List getTopologyList() { + return topologyList; + } +}