Skip to content

Commit

Permalink
Add Topology classes
Browse files Browse the repository at this point in the history
  • Loading branch information
khalidzahra committed Sep 28, 2021
1 parent 343fe62 commit c836f1e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main/java/com/github/khalidzahra/topology/Topology.java
Original file line number Diff line number Diff line change
@@ -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<Component> components;

public Topology(String id) {
this.id = id;
this.components = new ArrayList<>();
}

public Topology(String id, List<Component> componentList) {
this.id = id;
this.components = componentList;
}

public List<Component> 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<Component> getComponents() {
return components;
}
}
Original file line number Diff line number Diff line change
@@ -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<Topology> 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<Topology> getTopologyList() {
return topologyList;
}
}

0 comments on commit c836f1e

Please sign in to comment.