Class Checker

All Implemented Interfaces:
InterfaceChecker<AbstractChecker<Object,Checker>,Object>

public class Checker extends AbstractChecker<Object,Checker>
Main entry point for object validation and type checking.

The Checker class provides a fluent API for validating and inspecting objects of various types. It supports type checks, collection checks, file and URI checks, number and matrix checks, and more. Specialized checkers are returned for specific types, enabling further type-specific validation.

Example usage:

     Checker.check(myList).isList(String.class).isNotEmpty();
     Checker.check(myFile).isFile().exists();
 
Checker is the main class for validating and inspecting objects of any type. It extends AbstractChecker and provides methods to check for type, structure, and content, returning specialized checkers for further validation when appropriate.
  • Constructor Details

    • Checker

      protected Checker(Object object, String name)
      Constructs a Checker for the given object and name.
      Parameters:
      object - the object to check
      name - the name or label for the object (used in error messages)
  • Method Details

    • self

      protected Checker self()
      Returns this Checker instance (for fluent API).
      Specified by:
      self in class AbstractChecker<Object,Checker>
      Returns:
      this Checker
    • check

      public static Checker check(Object object, String name)
      Creates a Checker for the given object and name.
      Parameters:
      object - the object to check
      name - the name or label for the object
      Returns:
      a new Checker instance
    • check

      public static Checker check(Object object)
      Creates a Checker for the given object with a default name.
      Parameters:
      object - the object to check
      Returns:
      a new Checker instance
    • isInstance

      public <T> Checker isInstance(Class<T> clazz)
      Checks if the object is an instance of the given class.
      Type Parameters:
      T - the type of the class
      Parameters:
      clazz - the class to check against
      Returns:
      this Checker
    • isCollection

      public Checker isCollection()
      Checks if the object is a Collection.
      Returns:
      this Checker
    • isGraph

      public <N, E extends Number> CheckerGraph<N,E> isGraph(Collection<Graph.Edge<N,E>> edges, boolean directed)
      Creates a CheckerGraph for the given edges and directionality.
      Type Parameters:
      N - node type
      E - edge weight type (extends Number)
      Parameters:
      edges - the collection of edges
      directed - true if the graph is directed
      Returns:
      a CheckerGraph instance
    • isGraph

      public <N, E extends Number> CheckerGraph<N,E> isGraph(Collection<Graph.Edge<N,E>> edges)
      Creates a CheckerGraph for the given edges (undirected by default).
      Type Parameters:
      N - node type
      E - edge weight type (extends Number)
      Parameters:
      edges - the collection of edges
      Returns:
      a CheckerGraph instance
    • isGraph

      public <N, E extends Number> CheckerGraph<N,E> isGraph(Collection<N> nodes, Collection<Graph.Edge<N,E>> edges)
      Creates a CheckerGraph for the given nodes and edges (undirected by default).
      Type Parameters:
      N - node type
      E - edge weight type (extends Number)
      Parameters:
      nodes - the collection of nodes
      edges - the collection of edges
      Returns:
      a CheckerGraph instance
    • isGraph

      public <N, E extends Number> CheckerGraph<N,E> isGraph(Collection<N> nodes, Collection<Graph.Edge<N,E>> edges, boolean directed)
      Creates a CheckerGraph for the given nodes, edges, and directionality.
      Type Parameters:
      N - node type
      E - edge weight type (extends Number)
      Parameters:
      nodes - the collection of nodes
      edges - the collection of edges
      directed - true if the graph is directed
      Returns:
      a CheckerGraph instance
    • isList

      public CheckerList<?> isList()
      Checks if the object is a List and returns a CheckerList for further validation.
      Returns:
      a CheckerList instance
    • isList

      public <T> CheckerList<T> isList(Class<T> clazz)
      Checks if the object is a List whose elements are all instances of the given class.
      Type Parameters:
      T - the element type
      Parameters:
      clazz - the class of the list elements
      Returns:
      a CheckerList instance
    • isMap

      public CheckerMap<?,?> isMap()
      Checks if the object is a Map and returns a CheckerMap for further validation.
      Returns:
      a CheckerMap instance
    • isMap

      public <K, V> CheckerMap<K,V> isMap(Class<K> clazzKey, Class<V> clazzValue)
      Checks if the object is a Map whose keys and values are instances of the given classes.
      Type Parameters:
      K - key type
      V - value type
      Parameters:
      clazzKey - the class of the map keys
      clazzValue - the class of the map values
      Returns:
      a CheckerMap instance
    • isSet

      public CheckerSet<?> isSet()
      Checks if the object is a Set and returns a CheckerSet for further validation.
      Returns:
      a CheckerSet instance
    • isSet

      public <T> CheckerSet<T> isSet(Class<T> clazz)
      Checks if the object is a Set whose elements are all instances of the given class.
      Type Parameters:
      T - the element type
      Parameters:
      clazz - the class of the set elements
      Returns:
      a CheckerSet instance
    • isTree

      public <T> CheckerTree<T> isTree(T rootValue, Map<T,List<T>> childrenMap)
      Creates a CheckerTree for the given root value and children map.
      Type Parameters:
      T - node type
      Parameters:
      rootValue - the root node value
      childrenMap - the map of children for each node
      Returns:
      a CheckerTree instance
    • isTree

      public <T> CheckerTree<T> isTree(T rootValue)
      Creates a CheckerTree for the given root value.
      Type Parameters:
      T - node type
      Parameters:
      rootValue - the root node value
      Returns:
      a CheckerTree instance
    • isFile

      public CheckerFile isFile()
      Checks if the object is a File and returns a CheckerFile for further validation.
      Returns:
      a CheckerFile instance
    • isJson

      public CheckerJson isJson() throws IOException
      Checks if the object is a File and returns a CheckerJson for JSON file validation.
      Returns:
      a CheckerJson instance
      Throws:
      IOException - if file reading fails
    • isURI

      public CheckerURI isURI() throws IOException
      Checks if the object is a URI and returns a CheckerURI for further validation.
      Returns:
      a CheckerURI instance
      Throws:
      IOException - if URI reading fails
    • isNumber

      public Checker isNumber()
      Checks if the object is a Number.
      Returns:
      this Checker
    • isBigInteger

      public CheckerBigInteger isBigInteger()
      Checks if the object is a BigInteger and returns a CheckerBigInteger for further validation.
      Returns:
      a CheckerBigInteger instance
    • isBigDecimal

      public CheckerBigDecimal isBigDecimal()
      Checks if the object is a BigDecimal and returns a CheckerBigDecimal for further validation.
      Returns:
      a CheckerBigDecimal instance
    • isInteger

      public CheckerInteger isInteger()
      Checks if the object is an Integer and returns a CheckerInteger for further validation.
      Returns:
      a CheckerInteger instance
    • isLong

      public CheckerLong isLong()
      Checks if the object is a Long and returns a CheckerLong for further validation.
      Returns:
      a CheckerLong instance
    • isFloat

      public CheckerFloat isFloat()
      Checks if the object is a Float and returns a CheckerFloat for further validation.
      Returns:
      a CheckerFloat instance
    • isDouble

      public CheckerDouble isDouble()
      Checks if the object is a Double and returns a CheckerDouble for further validation.
      Returns:
      a CheckerDouble instance
    • isArray

      public CheckerArray<?> isArray()
      Checks if the object is an array and returns a CheckerArray for further validation.
      Returns:
      a CheckerArray instance
    • isArray

      public <T> CheckerArray<T> isArray(Class<T> clazz)
      Checks if the object is an array of the given class and returns a CheckerArray for further validation.
      Type Parameters:
      T - the element type
      Parameters:
      clazz - the class of the array elements
      Returns:
      a CheckerArray instance
    • isMatrix

      public CheckerMatrix<?> isMatrix()
      Checks if the object is a matrix (2D array) and returns a CheckerMatrix for further validation.
      Returns:
      a CheckerMatrix instance
    • isMatrix

      public <T extends Number> CheckerMatrix<T> isMatrix(Class<T> clazz)
      Checks if the object is a matrix (2D array) of the given class and returns a CheckerMatrix for further validation.
      Type Parameters:
      T - the element type (extends Number)
      Parameters:
      clazz - the class of the matrix elements
      Returns:
      a CheckerMatrix instance
    • isColor

      public CheckerColor isColor()
      Checks if the object is a Color and returns a CheckerColor for further validation.
      Returns:
      a CheckerColor instance
    • isCurrency

      public CheckerCurrency isCurrency()
      Checks if the object is a Currency and returns a CheckerCurrency for further validation.
      Returns:
      a CheckerCurrency instance
    • isString

      public CheckerString isString()
      Checks if the object is a String and returns a CheckerString for further validation.
      Returns:
      a CheckerString instance