Package org.graph4j.util
Class Validator
java.lang.Object
org.graph4j.util.Validator
Utility class for performing various checks related to graphs. This class is
designed primarily for doing parameter validation in methods and
constructors.
- Author:
- Cristian Frăsinaru
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckNumEdges(long m) Checks if the specified number is valid as the number of edges for a graph, i.e. non-negative.static voidcheckNumVertices(int n) Checks if the specified number is valid as the number of vertices for a graph, i.e. non-negative.static voidcheckProbability(double p) Checks if the specified number is in the range[0,1].static voidcheckRange(double first, double last) Checks if the range of values is valid.static voidcheckVertexIndex(Graph graph, int index) Checks if a specified integer is a valid index in a graph, i.e. it is in the range0tograph.numVertices()-1.static voidcheckVertexOrdering(Graph graph, int[] ordering) Checks if a specified ordering is valid, meaning it is a permutation of the vertices of the graph.static voidcheckVertexRange(int first, int last) Checks if the numbers in the specified range are valid as the vertices for a graph.static voidcheckVertices(int[] vertices) Checks if the numbers in the specified array are valid as the vertices for a graph.static voidcontainsEdge(Graph graph, int v, int u) Checks if a graph contains an edge.static voidcontainsEdge(Graph graph, Edge e) Checks if a graph contains an edge.static voidcontainsVertex(Graph graph, int v) Checks if a graph contains a vertex.static voidcontainsVertices(Graph graph, int... vertices) Checks if a graph contains an array of vertices.static voidhasNoDuplicates(int... values) Checks if an array of integers has no duplicate values.static voidhasNoDuplicateVertices(int... vertices) Checks if an array of vertex numbers has no duplicates.static voidhaveDisjointVertices(Graph g1, Graph g2) Checks if the vertex sets of two graphs are disjoint.static voidrequireNonEmpty(Graph graph) Checks that the specified graph is not empty.static voidrequireSimple(Graph graph) Checks if a graph is simple, i.e. undirected, does not allow multiple edges and does not allow self loops.static voidrequireUndirected(Graph graph) Checks if a graph is undirected.
-
Constructor Details
-
Validator
public Validator()
-
-
Method Details
-
requireNonEmpty
Checks that the specified graph is not empty.- Parameters:
graph- the graph this check is performed on.- Throws:
IllegalArgumentException- ifgraphis empty.
-
requireUndirected
Checks if a graph is undirected.- Parameters:
graph- the graph this check is performed on.- Throws:
IllegalArgumentException- ifgraphis directed.
-
requireSimple
Checks if a graph is simple, i.e. undirected, does not allow multiple edges and does not allow self loops.- Parameters:
graph- the graph this check is performed on.- Throws:
IllegalArgumentException- ifgraphis not simple.
-
checkNumVertices
public static void checkNumVertices(int n) Checks if the specified number is valid as the number of vertices for a graph, i.e. non-negative.- Parameters:
n- the number of vertices.- Throws:
IllegalArgumentException- ifnis negative.
-
checkVertexRange
public static void checkVertexRange(int first, int last) Checks if the numbers in the specified range are valid as the vertices for a graph.- Parameters:
first- first number in the range.last- last number in the range.- Throws:
IllegalArgumentException- if the range is invalid.
-
checkVertices
public static void checkVertices(int[] vertices) Checks if the numbers in the specified array are valid as the vertices for a graph.- Parameters:
vertices- an array of vertex numbers.- Throws:
IllegalArgumentException- if the vertices are invalid.
-
checkVertexIndex
Checks if a specified integer is a valid index in a graph, i.e. it is in the range0tograph.numVertices()-1.- Parameters:
graph- the graph this check is performed on.index- an integer representing an index.- Throws:
IllegalArgumentException- ifindexis invalid.
-
checkNumEdges
public static void checkNumEdges(long m) Checks if the specified number is valid as the number of edges for a graph, i.e. non-negative.- Parameters:
m- the number of edges.- Throws:
IllegalArgumentException- ifmis negative.
-
checkProbability
public static void checkProbability(double p) Checks if the specified number is in the range[0,1].- Parameters:
p- the number representing a probability.- Throws:
IllegalArgumentException- ifpis not in the range[0,1].
-
checkRange
public static void checkRange(double first, double last) Checks if the range of values is valid.- Parameters:
first- first number in the range.last- last number in the range.- Throws:
IllegalArgumentException- if the range is invalid.
-
haveDisjointVertices
Checks if the vertex sets of two graphs are disjoint.- Parameters:
g1- a graph.g2- a graph.- Throws:
IllegalArgumentException- if the two graphs have a common vertex number.
-
containsVertex
Checks if a graph contains a vertex.- Parameters:
graph- the graph this check is performed on.v- a vertex number.- Throws:
IllegalArgumentException- ifgraphdoes not containv.
-
containsEdge
Checks if a graph contains an edge.- Parameters:
graph- the graph this check is performed on.v- a vertex number in the graph.u- a vertex number in the graph.- Throws:
IllegalArgumentException- ifgraphdoes not contain the edgevu.
-
containsEdge
Checks if a graph contains an edge.- Parameters:
graph- the graph this check is performed on.e- an edge of the graph.- Throws:
IllegalArgumentException- ifgraphdoes not contain the edgee.
-
containsVertices
Checks if a graph contains an array of vertices.- Parameters:
graph- the graph this check is performed on.vertices- an array of vertex numbers.- Throws:
IllegalArgumentException- ifgraphdoes not containvertices.
-
hasNoDuplicates
public static void hasNoDuplicates(int... values) Checks if an array of integers has no duplicate values.- Parameters:
values- an array of numbers.- Throws:
IllegalArgumentException- if there are duplicate values.
-
hasNoDuplicateVertices
public static void hasNoDuplicateVertices(int... vertices) Checks if an array of vertex numbers has no duplicates.- Parameters:
vertices- an array of vertex numbers.- Throws:
IllegalArgumentException- if there exist a duplicate vertex number.
-
checkVertexOrdering
Checks if a specified ordering is valid, meaning it is a permutation of the vertices of the graph.- Parameters:
graph- the input graph.ordering- a vertex ordering.
-