Package jetbrains.buildServer.util.graph
Class DAG<T>
- java.lang.Object
-
- jetbrains.buildServer.util.graph.DAG<T>
-
- Direct Known Subclasses:
BaseModificationDAG
,GenericDAG
public abstract class DAG<T> extends Object
Directed acyclic graph- Author:
- dmitry.neverov
-
-
Constructor Summary
Constructors Constructor Description DAG()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
breadthFirstSearch(Set<T> starts, BFSVisitor<T> visitor)
abstract void
breadthFirstSearch(T start, BFSVisitor<T> visitor)
Run breadth-first search from the specified start nodeabstract boolean
containsNode(T node)
Check if graph contains specified nodevoid
depthFirstSearch(T start, DFSVisitor<T> visitor)
Run depth-first search from the specified start nodeprotected void
ensureContainsNode(T node)
DAG<T>
exclude(Collection<T> nodesToExclude)
Returns DAG which doesn't contain nodes in the specified collectionprotected abstract void
fillSelfChildren(T node, List<T> accumulator)
DAG<T>
filter(Filter<T> filter)
Returns filtered DAG which contains only nodes accepted by specified filter, same as calling {@link #filter(jetbrains.buildServer.util.filters.Filter, false)}DAG<T>
filter(Filter<T> filter, boolean includeAcceptedNodeParents)
Returns filtered DAG which contains only nodes accepted by specified filter and, if includeAcceptedNodeParents is set to true, their parentsabstract DAG<T>
filter(Filter<T> filter, boolean includeAcceptedNodeParents, boolean extrapolateEdges)
abstract Set<T>
getAllNodes()
List<T>
getChildren(T node)
Get children of the specified nodeabstract List<T>
getCommonAncestors(List<T> nodes)
Get list of common ancestors for collection of graph nodesList<T>
getCommonAncestors(T... nodes)
abstract DepthFirstSearch<T>
getDepthFirstSearch(T start, DFSVisitor<T> visitor)
Returns depth-first search from the specified start nodeSet<T>
getNodesWithMissingParents()
Returns nodes where some parent nodes are missing.abstract List<T>
getNodesWithoutChildren()
Returns nodes without childrenabstract List<T>
getNodesWithoutParents()
Returns nodes without parentsabstract List<T>
getParents(T node)
Get parents of the specified nodeabstract DepthFirstSearch<T>
getReverseDepthFirstSearch(T start, DFSVisitor<T> visitor)
protected abstract List<T>
getSelfParents(T node)
boolean
hasParents(T node)
Returns true if the given node has parentsDAG<T>
include(Collection<T> nodesToInclude)
Returns DAG which contains only nodes in the specified collectionDAG<T>
include(Collection<T> nodesToInclude, boolean extrapolateEdges)
boolean
isEmpty()
DAGIterator<T>
iterator()
Get iterator through the nodes of the graph.DAGIterator<T>
iterator(Collection<T> startNodes)
Get iterator through the nodes of the graphDAGIterator<T>
iterator(T startNode)
Get iterator through the nodes of the graphprotected abstract void
processNodesWithoutChildren(ItemProcessor<T> nodesProcessor)
Passes nodes without children to the specified processor.abstract void
reverseBreadthFirstSearch(Set<T> starts, BFSVisitor<T> visitor)
abstract void
reverseBreadthFirstSearch(T start, BFSVisitor<T> visitor)
abstract int
size()
Returns number of nodes in the graphList<DAG<T>>
splitIsolatedDAGs()
abstract List<T>
toposort()
Get topologically sorted list of graph nodes (parents go before children)
-
-
-
Method Detail
-
toposort
@NotNull public abstract List<T> toposort()
Get topologically sorted list of graph nodes (parents go before children)- Returns:
- see above
-
getCommonAncestors
@NotNull public List<T> getCommonAncestors(@NotNull T... nodes)
- See Also:
getCommonAncestors(java.util.List)
-
getCommonAncestors
@NotNull public abstract List<T> getCommonAncestors(@NotNull List<T> nodes)
Get list of common ancestors for collection of graph nodes- Parameters:
nodes
- nodes of interest, they should be presented in the graph- Returns:
- least common ancestors or empty list if collection of nodes is empty or if there is no common ancestor between nodes.
-
getParents
@NotNull public abstract List<T> getParents(@NotNull T node)
Get parents of the specified node- Parameters:
node
- node of interest- Returns:
- see above
-
hasParents
public boolean hasParents(@NotNull T node)
Returns true if the given node has parents- Parameters:
node
- node of interest- Returns:
- see above
-
getChildren
@NotNull public List<T> getChildren(@NotNull T node)
Get children of the specified node- Parameters:
node
- node of interest- Returns:
- see above
-
fillSelfChildren
protected abstract void fillSelfChildren(@NotNull T node, @NotNull List<T> accumulator)
-
iterator
@NotNull public DAGIterator<T> iterator()
Get iterator through the nodes of the graph. Same as iterator(getNodesWithoutChildren())- Returns:
- see above
- See Also:
iterator(java.util.Collection)
-
iterator
@NotNull public DAGIterator<T> iterator(@NotNull T startNode)
Get iterator through the nodes of the graph- Parameters:
startNode
- start node for iteration- Returns:
- see above
-
iterator
@NotNull public DAGIterator<T> iterator(@NotNull Collection<T> startNodes)
Get iterator through the nodes of the graph- Parameters:
startNodes
- start nodes for iteration- Returns:
- see above
-
exclude
@NotNull public DAG<T> exclude(@NotNull Collection<T> nodesToExclude)
Returns DAG which doesn't contain nodes in the specified collection- Parameters:
nodesToExclude
- collection of nodes resulting DAG should not have- Returns:
- see above
-
include
@NotNull public DAG<T> include(@NotNull Collection<T> nodesToInclude)
Returns DAG which contains only nodes in the specified collection- Parameters:
nodesToInclude
- collection of nodes resulting DAG should have- Returns:
- see above
-
include
@NotNull public DAG<T> include(@NotNull Collection<T> nodesToInclude, boolean extrapolateEdges)
-
filter
@NotNull public DAG<T> filter(@NotNull Filter<T> filter)
Returns filtered DAG which contains only nodes accepted by specified filter, same as calling {@link #filter(jetbrains.buildServer.util.filters.Filter, false)}- Parameters:
filter
- filter of interest- Returns:
- see above
-
filter
public DAG<T> filter(@NotNull Filter<T> filter, boolean includeAcceptedNodeParents)
Returns filtered DAG which contains only nodes accepted by specified filter and, if includeAcceptedNodeParents is set to true, their parents- Parameters:
filter
- filter of interestincludeAcceptedNodeParents
- if set to true - all parents of accepted nodes are included into result, if set to false - parents will be filtered and result will include only accepted parents- Returns:
- see above
-
filter
public abstract DAG<T> filter(@NotNull Filter<T> filter, boolean includeAcceptedNodeParents, boolean extrapolateEdges)
-
containsNode
public abstract boolean containsNode(@NotNull T node)
Check if graph contains specified node- Parameters:
node
- node to check- Returns:
- true if graph contains node, false otherwise
-
getNodesWithoutParents
@NotNull public abstract List<T> getNodesWithoutParents()
Returns nodes without parents- Returns:
- see above
-
getNodesWithMissingParents
public Set<T> getNodesWithMissingParents()
Returns nodes where some parent nodes are missing. UnlikegetNodesWithoutParents()
also returns nodes where some parents are present and other parents are missing.- Since:
- 2017.2.2
-
getNodesWithoutChildren
@NotNull public abstract List<T> getNodesWithoutChildren()
Returns nodes without children- Returns:
- see above
-
depthFirstSearch
public void depthFirstSearch(@NotNull T start, @NotNull DFSVisitor<T> visitor)
Run depth-first search from the specified start node- Parameters:
start
- start node for the searchvisitor
- visitor
-
breadthFirstSearch
public abstract void breadthFirstSearch(@NotNull T start, @NotNull BFSVisitor<T> visitor)
Run breadth-first search from the specified start node- Parameters:
start
- start node for the searchvisitor
- visitor
-
breadthFirstSearch
public abstract void breadthFirstSearch(@NotNull Set<T> starts, @NotNull BFSVisitor<T> visitor)
-
reverseBreadthFirstSearch
public abstract void reverseBreadthFirstSearch(@NotNull T start, @NotNull BFSVisitor<T> visitor)
-
reverseBreadthFirstSearch
public abstract void reverseBreadthFirstSearch(@NotNull Set<T> starts, @NotNull BFSVisitor<T> visitor)
-
getDepthFirstSearch
public abstract DepthFirstSearch<T> getDepthFirstSearch(@NotNull T start, @NotNull DFSVisitor<T> visitor)
Returns depth-first search from the specified start node- Parameters:
start
- start node for the searchvisitor
- visitor- Returns:
- see above
-
getReverseDepthFirstSearch
public abstract DepthFirstSearch<T> getReverseDepthFirstSearch(@NotNull T start, @NotNull DFSVisitor<T> visitor)
-
size
public abstract int size()
Returns number of nodes in the graph- Returns:
- see above
-
isEmpty
public boolean isEmpty()
-
ensureContainsNode
protected void ensureContainsNode(@NotNull T node)
-
processNodesWithoutChildren
protected abstract void processNodesWithoutChildren(@NotNull ItemProcessor<T> nodesProcessor)
Passes nodes without children to the specified processor.- Since:
- 2019.1.3
-
-