Top Description Inners Fields Constructors Methods
org.testng.internal

public Class Graph<T>

extends Object
Class Inheritance
Imports
java.util.ArrayDeque, .ArrayList, .Collection, .Comparator, .Deque, .HashSet, .List, .Map, .Set, java.util.function.Function, .Supplier, java.util.stream.Collectors, org.testng.TestNGException, org.testng.collections.Lists, .Maps, org.testng.log4testng.Logger

Simple graph class to implement topological sort (used to sort methods based on what groups they depend on).
Author
Cedric Beust, Aug 19, 2004

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private final Comparator<Graph.Node<T>>
private Map<T, Graph.Node<T>>
private final Map<T, Graph.Node<T>>
private List<T>

Constructor Summary

AccessConstructor and Description
public
Graph(Comparator<Graph.Node<T>> comparator)

Method Summary

Modifier and TypeMethod and Description
public void
addNode(T tm)

public void
addPredecessor(T tm, T predecessor)

private void
private Graph.Node<T>
findNode(T object)

private Graph.Node<T>
public List<T>

Returns:

A list of all the predecessors for o
findPredecessors
(T
- The predecessor
o
)

public Set<T>

Returns:

All the nodes that don't have any order with each other.
getIndependentNodes
()

private Collection<Graph.Node<T>>
public Set<T>
public List<T>

Returns:

All the nodes that have an order with each other, sorted in one of the valid sorts.
getStrictlySortedNodes
()

private void
public boolean
isIndependent(T object)

private static void
private static void
private void
removeFromNodes(List<Graph.Node<T>> nodes, Graph.Node<T> node)

Remove a node from a list of nodes and update the list of predecessors for all the remaining nodes.

public void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

comparatorback to summary
private final Comparator<Graph.Node<T>> comparator
m_independentNodesback to summary
private Map<T, Graph.Node<T>> m_independentNodes
m_nodesback to summary
private final Map<T, Graph.Node<T>> m_nodes
m_strictlySortedNodesback to summary
private List<T> m_strictlySortedNodes

Constructor Detail

Graphback to summary
public Graph(Comparator<Graph.Node<T>> comparator)

Method Detail

addNodeback to summary
public void addNode(T tm)
addPredecessorback to summary
public void addPredecessor(T tm, T predecessor)
dumpSortedNodesback to summary
private void dumpSortedNodes()
findNodeback to summary
private Graph.Node<T> findNode(T object)
findNodeWithNoPredecessorsback to summary
private Graph.Node<T> findNodeWithNoPredecessors(List<Graph.Node<T>> nodes)
findPredecessorsback to summary
public List<T> findPredecessors(T o)
Parameters
o:T

- The predecessor

Returns:List<T>

A list of all the predecessors for o

getIndependentNodesback to summary
public Set<T> getIndependentNodes()
Returns:Set<T>

All the nodes that don't have any order with each other.

getNodesback to summary
private Collection<Graph.Node<T>> getNodes()
getPredecessorsback to summary
public Set<T> getPredecessors(T node)
getStrictlySortedNodesback to summary
public List<T> getStrictlySortedNodes()
Returns:List<T>

All the nodes that have an order with each other, sorted in one of the valid sorts.

initializeIndependentNodesback to summary
private void initializeIndependentNodes()
isIndependentback to summary
public boolean isIndependent(T object)
logback to summary
private static void log(String s)
logback to summary
private static void log(Supplier<String> s)
removeFromNodesback to summary
private void removeFromNodes(List<Graph.Node<T>> nodes, Graph.Node<T> node)

Remove a node from a list of nodes and update the list of predecessors for all the remaining nodes.

topologicalSortback to summary
public void topologicalSort()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
org.testng.internal back to summary

public Class Graph.Node<T>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final T
private final Map<T, T>

Constructor Summary

AccessConstructor and Description
public
Node(T tm)

Method Summary

Modifier and TypeMethod and Description
public void
public Graph.Node<T>
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
public T
public Map<T, T>
public boolean
public boolean

Returns:

true if this predecessor was found and removed
removePredecessor
(T
The predecessor to remove
o
)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

m_objectback to summary
private final T m_object
m_predecessorsback to summary
private final Map<T, T> m_predecessors

Constructor Detail

Nodeback to summary
public Node(T tm)

Method Detail

addPredecessorback to summary
public void addPredecessor(T tm)
cloneback to summary
public Graph.Node<T> clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Graph.Node<T>

a clone of this instance.

Annotations
@Override
getObjectback to summary
public T getObject()
getPredecessorsback to summary
public Map<T, T> getPredecessors()
hasPredecessorsback to summary
public boolean hasPredecessors()
removePredecessorback to summary
public boolean removePredecessor(T o)
Parameters
o:T

The predecessor to remove

Returns:boolean

true if this predecessor was found and removed

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override