T
- the payload of each node@NotThreadSafe public class DirectedAcyclicGraph<T> extends Object
Constructor and Description |
---|
DirectedAcyclicGraph()
A Directed Acyclic Graph (DAG).
|
Modifier and Type | Method and Description |
---|---|
void |
add(T payload,
List<T> parents)
Adds a node to the DAG, that takes the given payload and depends on the specified parents.
|
boolean |
contains(T payload)
Checks if a node with the given payload is in the DAG.
|
void |
deleteLeaf(T payload)
Deletes a leaf DAG node that carries the given payload.
|
List<T> |
getAllInTopologicalOrder()
Gets all payloads of the DAG in the topological order.
|
List<T> |
getChildren(T payload)
Gets the payloads for the children of the given node.
|
List<T> |
getParents(T payload)
Gets the payloads for the given nodes parents.
|
List<T> |
getRoots()
Gets the payloads of all the root nodes of the DAG.
|
boolean |
isRoot(T payload)
Checks if a given payload is in a root of the DAG.
|
List<T> |
sortTopologically(Set<T> payloads)
Sorts a given set of payloads topologically based on the DAG.
|
public DirectedAcyclicGraph()
public void add(T payload, List<T> parents)
payload
- the payloadparents
- the parents of the created nodepublic void deleteLeaf(T payload)
payload
- the payload of the node to deletepublic boolean contains(T payload)
payload
- the payload of the node to checkpublic List<T> getChildren(T payload)
payload
- the payload of the parent nodepublic List<T> getParents(T payload)
payload
- the payload of the children nodepublic boolean isRoot(T payload)
payload
- the payload to check for rootpublic List<T> getRoots()
public List<T> sortTopologically(Set<T> payloads)
payloads
- the set of input payloadsCopyright © 2023. All Rights Reserved.