Class Validator

java.lang.Object
org.graph4j.util.Validator

public class Validator extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    checkNumEdges(long m)
    Checks if the specified number is valid as the number of edges for a graph, i.e. non-negative.
    static void
    Checks if the specified number is valid as the number of vertices for a graph, i.e. non-negative.
    static void
    checkProbability(double p)
    Checks if the specified number is in the range [0,1].
    static void
    checkRange(double first, double last)
    Checks if the range of values is valid.
    static void
    checkVertexIndex(Graph graph, int index)
    Checks if a specified integer is a valid index in a graph, i.e. it is in the range 0 to graph.numVertices()-1.
    static void
    checkVertexOrdering(Graph graph, int[] ordering)
    Checks if a specified ordering is valid, meaning it is a permutation of the vertices of the graph.
    static void
    checkVertexRange(int first, int last)
    Checks if the numbers in the specified range are valid as the vertices for a graph.
    static void
    checkVertices(int[] vertices)
    Checks if the numbers in the specified array are valid as the vertices for a graph.
    static void
    containsEdge(Graph graph, int v, int u)
    Checks if a graph contains an edge.
    static void
    containsEdge(Graph graph, Edge e)
    Checks if a graph contains an edge.
    static void
    containsVertex(Graph graph, int v)
    Checks if a graph contains a vertex.
    static void
    containsVertices(Graph graph, int... vertices)
    Checks if a graph contains an array of vertices.
    static void
    hasNoDuplicates(int... values)
    Checks if an array of integers has no duplicate values.
    static void
    hasNoDuplicateVertices(int... vertices)
    Checks if an array of vertex numbers has no duplicates.
    static void
    Checks if the vertex sets of two graphs are disjoint.
    static void
    Checks that the specified graph is not empty.
    static void
    Checks if a graph is simple, i.e. undirected, does not allow multiple edges and does not allow self loops.
    static void
    Checks if a graph is undirected.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Validator

      public Validator()
  • Method Details

    • requireNonEmpty

      public static void requireNonEmpty(Graph graph)
      Checks that the specified graph is not empty.
      Parameters:
      graph - the graph this check is performed on.
      Throws:
      IllegalArgumentException - if graph is empty.
    • requireUndirected

      public static void requireUndirected(Graph graph)
      Checks if a graph is undirected.
      Parameters:
      graph - the graph this check is performed on.
      Throws:
      IllegalArgumentException - if graph is directed.
    • requireSimple

      public static void requireSimple(Graph graph)
      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 - if graph is 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 - if n is 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

      public static void checkVertexIndex(Graph graph, int index)
      Checks if a specified integer is a valid index in a graph, i.e. it is in the range 0 to graph.numVertices()-1.
      Parameters:
      graph - the graph this check is performed on.
      index - an integer representing an index.
      Throws:
      IllegalArgumentException - if index is 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 - if m is 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 - if p is 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

      public static void haveDisjointVertices(Graph g1, Graph g2)
      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

      public static void containsVertex(Graph graph, int v)
      Checks if a graph contains a vertex.
      Parameters:
      graph - the graph this check is performed on.
      v - a vertex number.
      Throws:
      IllegalArgumentException - if graph does not contain v.
    • containsEdge

      public static void containsEdge(Graph graph, int v, int u)
      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 - if graph does not contain the edge vu.
    • containsEdge

      public static void containsEdge(Graph graph, Edge e)
      Checks if a graph contains an edge.
      Parameters:
      graph - the graph this check is performed on.
      e - an edge of the graph.
      Throws:
      IllegalArgumentException - if graph does not contain the edge e.
    • containsVertices

      public static void containsVertices(Graph graph, int... vertices)
      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 - if graph does not contain vertices.
    • 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

      public static void checkVertexOrdering(Graph graph, int[] ordering)
      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.