Class CheckerGraph<N,E extends Number>
java.lang.Object
util.AbstractChecker<Graph<N,E>,CheckerGraph<N,E>>
specialized_checkers.collection.CheckerGraph<N,E>
- Type Parameters:
N
- the type of nodes in the graphE
- the type of edge weights (must extendNumber
)
- All Implemented Interfaces:
InterfaceChecker<AbstractChecker<Graph<N,
E>, CheckerGraph<N, E>>, Graph<N, E>>
A specialized checker for validating properties and constraints on graph data structures.
The CheckerGraph
class provides a fluent API for asserting various conditions
on graphs, such as connectivity, acyclicity, node and edge existence, and more.
It supports both directed and undirected graphs, as well as weighted edges.
Example usage:
Graph<String, Integer> graph = ...;
CheckerGraph.check(graph)
.isConnected()
.minNodes(3)
.hasCycle();
- See Also:
-
Field Summary
Fields inherited from class util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CheckerGraph
(Graph<N, E> graph, String name) Constructs a newCheckerGraph
with the specified underlying graph and name. -
Method Summary
Modifier and TypeMethodDescriptionallEdgesMatch
(Predicate<Graph.Edge<N, E>> condition) Checks if all edges in the graph match the given condition.allNodesMatch
(Predicate<N> condition) Checks if all nodes in the graph match the given condition.anyEdgesMatch
(Predicate<Graph.Edge<N, E>> condition) Checks if any edge in the graph matches the given condition.anyNodesMatch
(Predicate<N> condition) Checks if any node in the graph matches the given condition.static <N,
E extends Number>
CheckerGraph<N, E> check
(Collection<N> nodes, Collection<Graph.Edge<N, E>> edges) Creates a CheckerGraph from a collection of nodes and edges with a default name.static <N,
E extends Number>
CheckerGraph<N, E> check
(Collection<N> nodes, Collection<Graph.Edge<N, E>> edges, boolean directed) Creates a CheckerGraph from a collection of nodes and edges, specifying if the graph is directed, with a default name.static <N,
E extends Number>
CheckerGraph<N, E> check
(Collection<N> nodes, Collection<Graph.Edge<N, E>> edges, boolean directed, String name) Creates a CheckerGraph from a collection of nodes and edges, specifying if the graph is directed, and assigns a name.static <N,
E extends Number>
CheckerGraph<N, E> check
(Collection<N> nodes, Collection<Graph.Edge<N, E>> edges, String name) Creates a CheckerGraph from a collection of nodes and edges, and assigns a name.static <N,
E extends Number>
CheckerGraph<N, E> check
(Collection<Graph.Edge<N, E>> edges) Creates a CheckerGraph from a collection of edges with a default name.static <N,
E extends Number>
CheckerGraph<N, E> check
(Collection<Graph.Edge<N, E>> edges, boolean directed) Creates a CheckerGraph from a collection of edges, specifying if the graph is directed, with a default name.static <N,
E extends Number>
CheckerGraph<N, E> check
(Collection<Graph.Edge<N, E>> edges, boolean directed, String name) Creates a CheckerGraph from a collection of edges, specifying if the graph is directed, and assigns a name.static <N,
E extends Number>
CheckerGraph<N, E> check
(Collection<Graph.Edge<N, E>> edges, String name) Creates a CheckerGraph from a collection of edges and assigns a name.static <N,
E extends Number>
CheckerGraph<N, E> Creates a CheckerGraph for the given graph with a default name.static <N,
E extends Number>
CheckerGraph<N, E> Creates a CheckerGraph for the given graph and assigns a custom name.containsEdge
(N from, N to) Checks if the graph contains an edge from one node to another.containsEdge
(Graph.Edge<N, E> edge) Checks if the graph contains the specified edge.containsNode
(N node) Checks if the graph contains the specified node.hasCycle()
Checks if the graph contains at least one cycle.Checks if there is a path between two nodes in the graph.inRangeEdges
(int min, int max) Checks if the number of edges in the graph is within the specified range (inclusive).inRangeNodes
(int min, int max) Checks if the number of nodes in the graph is within the specified range (inclusive).inRangeWeight
(double min, double max) Checks if all edge weights in the graph are within the specified range (inclusive).Checks if the graph is a binary tree (each node has at most two children).Checks if the graph is connected (there is a path between every pair of nodes).Checks if the graph is directed.isEmpty()
Checks if the graph is empty (contains no nodes).isTree()
Checks if the graph is a tree (connected and acyclic).maxEdges
(int max) Checks if the graph has at most the specified maximum number of edges.maxNodes
(int max) Checks if the graph has at most the specified maximum number of nodes.maxWeight
(double max) Checks if all edge weights in the graph are at most the specified maximum value.minEdges
(int min) Checks if the graph has at least the specified minimum number of edges.minNodes
(int min) Checks if the graph has at least the specified minimum number of nodes.minWeight
(double min) Checks if all edge weights in the graph are at least the specified minimum value.protected CheckerGraph
<N, E> self()
Returns this instance (for fluent API).Methods inherited from class util.AbstractChecker
checkProperty, checkProperty, checkProperty, end, getMethod, getObject, getProperty, hasErrors, hasNotErrors, is, is, isEqual, isNonNull, isNot, isNot, isNull, notSaveErrors, saveErrors, show, showNotThrownException, showThrownException, stop
-
Constructor Details
-
CheckerGraph
-
-
Method Details
-
check
Creates a CheckerGraph for the given graph and assigns a custom name.- Type Parameters:
N
- the type of nodes in the graphE
- the type of edge weights (must extend Number)- Parameters:
graph
- the graph to checkname
- the name to assign to this checker- Returns:
- a CheckerGraph instance for the given graph
-
check
public static <N,E extends Number> CheckerGraph<N,E> check(Collection<Graph.Edge<N, E>> edges, boolean directed, String name) Creates a CheckerGraph from a collection of edges, specifying if the graph is directed, and assigns a name.- Type Parameters:
N
- the type of nodes in the graphE
- the type of edge weights (must extend Number)- Parameters:
edges
- the collection of edges to build the graphdirected
- true if the graph is directed, false otherwisename
- the name to assign to this checker- Returns:
- a CheckerGraph instance for the constructed graph
-
check
public static <N,E extends Number> CheckerGraph<N,E> check(Collection<Graph.Edge<N, E>> edges, String name) Creates a CheckerGraph from a collection of edges and assigns a name. The graph will be undirected by default.- Type Parameters:
N
- the type of nodes in the graphE
- the type of edge weights (must extend Number)- Parameters:
edges
- the collection of edges to build the graphname
- the name to assign to this checker- Returns:
- a CheckerGraph instance for the constructed graph
-
check
public static <N,E extends Number> CheckerGraph<N,E> check(Collection<N> nodes, Collection<Graph.Edge<N, E>> edges, String name) Creates a CheckerGraph from a collection of nodes and edges, and assigns a name.- Type Parameters:
N
- the type of nodes in the graphE
- the type of edge weights (must extend Number)- Parameters:
nodes
- the collection of nodes in the graphedges
- the collection of edges in the graphname
- the name to assign to this checker- Returns:
- a CheckerGraph instance for the constructed graph
-
check
public static <N,E extends Number> CheckerGraph<N,E> check(Collection<N> nodes, Collection<Graph.Edge<N, E>> edges, boolean directed, String name) Creates a CheckerGraph from a collection of nodes and edges, specifying if the graph is directed, and assigns a name.- Type Parameters:
N
- the type of nodes in the graphE
- the type of edge weights (must extend Number)- Parameters:
nodes
- the collection of nodes in the graphedges
- the collection of edges in the graphdirected
- true if the graph is directed, false otherwisename
- the name to assign to this checker- Returns:
- a CheckerGraph instance for the constructed graph
-
check
Creates a CheckerGraph for the given graph with a default name.- Type Parameters:
N
- the type of nodes in the graphE
- the type of edge weights (must extend Number)- Parameters:
graph
- the graph to check- Returns:
- a CheckerGraph instance for the given graph
-
check
public static <N,E extends Number> CheckerGraph<N,E> check(Collection<Graph.Edge<N, E>> edges, boolean directed) Creates a CheckerGraph from a collection of edges, specifying if the graph is directed, with a default name.- Type Parameters:
N
- the type of nodes in the graphE
- the type of edge weights (must extend Number)- Parameters:
edges
- the collection of edges to build the graphdirected
- true if the graph is directed, false otherwise- Returns:
- a CheckerGraph instance for the constructed graph
-
check
Creates a CheckerGraph from a collection of edges with a default name. The graph will be undirected by default.- Type Parameters:
N
- the type of nodes in the graphE
- the type of edge weights (must extend Number)- Parameters:
edges
- the collection of edges to build the graph- Returns:
- a CheckerGraph instance for the constructed graph
-
check
public static <N,E extends Number> CheckerGraph<N,E> check(Collection<N> nodes, Collection<Graph.Edge<N, E>> edges) Creates a CheckerGraph from a collection of nodes and edges with a default name.- Type Parameters:
N
- the type of nodes in the graphE
- the type of edge weights (must extend Number)- Parameters:
nodes
- the collection of nodes in the graphedges
- the collection of edges in the graph- Returns:
- a CheckerGraph instance for the constructed graph
-
check
public static <N,E extends Number> CheckerGraph<N,E> check(Collection<N> nodes, Collection<Graph.Edge<N, E>> edges, boolean directed) Creates a CheckerGraph from a collection of nodes and edges, specifying if the graph is directed, with a default name.- Type Parameters:
N
- the type of nodes in the graphE
- the type of edge weights (must extend Number)- Parameters:
nodes
- the collection of nodes in the graphedges
- the collection of edges in the graphdirected
- true if the graph is directed, false otherwise- Returns:
- a CheckerGraph instance for the constructed graph
-
self
Returns this instance (for fluent API).- Specified by:
self
in classAbstractChecker<Graph<N,
E extends Number>, CheckerGraph<N, E extends Number>> - Returns:
- this CheckerGraph instance
-
isEmpty
Checks if the graph is empty (contains no nodes).- Returns:
- this CheckerGraph instance
-
isTree
Checks if the graph is a tree (connected and acyclic).- Returns:
- this CheckerGraph instance
-
isBinaryTree
Checks if the graph is a binary tree (each node has at most two children).- Returns:
- this CheckerGraph instance
-
isDirected
Checks if the graph is directed.- Returns:
- this CheckerGraph instance
-
isConnected
Checks if the graph is connected (there is a path between every pair of nodes).- Returns:
- this CheckerGraph instance
-
hasCycle
Checks if the graph contains at least one cycle.- Returns:
- this CheckerGraph instance
-
containsNode
Checks if the graph contains the specified node.- Parameters:
node
- the node to check for- Returns:
- this CheckerGraph instance
-
containsEdge
Checks if the graph contains an edge from one node to another.- Parameters:
from
- the source nodeto
- the destination node- Returns:
- this CheckerGraph instance
-
containsEdge
Checks if the graph contains the specified edge.- Parameters:
edge
- the edge to check for- Returns:
- this CheckerGraph instance
-
anyNodesMatch
Checks if any node in the graph matches the given condition.- Parameters:
condition
- the predicate to test nodes- Returns:
- this CheckerGraph instance
-
allNodesMatch
Checks if all nodes in the graph match the given condition.- Parameters:
condition
- the predicate to test nodes- Returns:
- this CheckerGraph instance
-
anyEdgesMatch
Checks if any edge in the graph matches the given condition.- Parameters:
condition
- the predicate to test edges- Returns:
- this CheckerGraph instance
-
allEdgesMatch
Checks if all edges in the graph match the given condition.- Parameters:
condition
- the predicate to test edges- Returns:
- this CheckerGraph instance
-
hasPath
Checks if there is a path between two nodes in the graph.- Parameters:
start
- the starting nodeend
- the ending node- Returns:
- this CheckerGraph instance
-
minNodes
Checks if the graph has at least the specified minimum number of nodes.- Parameters:
min
- the minimum number of nodes- Returns:
- this CheckerGraph instance
-
maxNodes
Checks if the graph has at most the specified maximum number of nodes.- Parameters:
max
- the maximum number of nodes- Returns:
- this CheckerGraph instance
-
inRangeNodes
Checks if the number of nodes in the graph is within the specified range (inclusive).- Parameters:
min
- the minimum number of nodesmax
- the maximum number of nodes- Returns:
- this CheckerGraph instance
-
minEdges
Checks if the graph has at least the specified minimum number of edges.- Parameters:
min
- the minimum number of edges- Returns:
- this CheckerGraph instance
-
maxEdges
Checks if the graph has at most the specified maximum number of edges.- Parameters:
max
- the maximum number of edges- Returns:
- this CheckerGraph instance
-
inRangeEdges
Checks if the number of edges in the graph is within the specified range (inclusive).- Parameters:
min
- the minimum number of edgesmax
- the maximum number of edges- Returns:
- this CheckerGraph instance
-
minWeight
Checks if all edge weights in the graph are at least the specified minimum value.- Parameters:
min
- the minimum edge weight- Returns:
- this CheckerGraph instance
-
maxWeight
Checks if all edge weights in the graph are at most the specified maximum value.- Parameters:
max
- the maximum edge weight- Returns:
- this CheckerGraph instance
-
inRangeWeight
Checks if all edge weights in the graph are within the specified range (inclusive).- Parameters:
min
- the minimum edge weightmax
- the maximum edge weight- Returns:
- this CheckerGraph instance
-