Class CheckerMatrix<T extends Number>

java.lang.Object
util.AbstractChecker<T[][],CheckerMatrix<T>>
specialized_checkers.math.CheckerMatrix<T>
Type Parameters:
T - the type of the elements in the matrix being checked (must extend Number)
All Implemented Interfaces:
InterfaceChecker<AbstractChecker<T[][],CheckerMatrix<T>>,T[][]>

public class CheckerMatrix<T extends Number> extends AbstractChecker<T[][],CheckerMatrix<T>>
Checker for matrix (2D array) instances, providing fluent validation methods for matrices of any numeric type.

This class allows you to validate and assert properties of matrix objects in a fluent and readable way.

  • Constructor Details

    • CheckerMatrix

      protected CheckerMatrix(T[][] matrix, String name)
      Constructs a new CheckerMatrix with the specified matrix and name.
      Parameters:
      matrix - the matrix to be used by this checker
      name - the name identifying this checker
  • Method Details

    • check

      public static <T extends Number> CheckerMatrix<T> check(T[][] matrix, String name)
      Creates a new CheckerMatrix for the given matrix instance with a custom name.
      Type Parameters:
      T - the type of the elements in the matrix (must extend Number)
      Parameters:
      matrix - the matrix instance to be checked
      name - the name to identify this checker instance (useful for error messages)
      Returns:
      a new CheckerMatrix for the provided matrix
    • check

      public static <T extends Number> CheckerMatrix<T> check(T[][] matrix)
      Creates a new CheckerMatrix for the given matrix instance with a default name.
      Type Parameters:
      T - the type of the elements in the matrix (must extend Number)
      Parameters:
      matrix - the matrix instance to be checked
      Returns:
      a new CheckerMatrix for the provided matrix
    • self

      protected CheckerMatrix<T> self()
      Returns this checker instance (for fluent API usage).
      Specified by:
      self in class AbstractChecker<T extends Number[][],CheckerMatrix<T extends Number>>
      Returns:
      this CheckerMatrix instance
    • isEmpty

      public CheckerMatrix<T> isEmpty()
      Asserts that the matrix is empty (has zero rows or all rows are empty).
      Returns:
      this CheckerMatrix instance for further validation
    • isSquare

      public CheckerMatrix<T> isSquare()
      Asserts that the matrix is square (number of rows equals number of columns).
      Returns:
      this CheckerMatrix instance for further validation
    • isZero

      public CheckerMatrix<T> isZero()
      Asserts that the matrix is a zero matrix (all elements are zero).
      Returns:
      this CheckerMatrix instance for further validation
    • isIdentity

      public CheckerMatrix<T> isIdentity()
      Asserts that the matrix is an identity matrix (ones on the diagonal, zeros elsewhere).
      Returns:
      this CheckerMatrix instance for further validation
    • isSymmetric

      public CheckerMatrix<T> isSymmetric()
      Asserts that the matrix is symmetric (equal to its transpose).
      Returns:
      this CheckerMatrix instance for further validation
    • isDiagonal

      public CheckerMatrix<T> isDiagonal()
      Asserts that the matrix is diagonal (all off-diagonal elements are zero).
      Returns:
      this CheckerMatrix instance for further validation
    • isOrthogonal

      public CheckerMatrix<T> isOrthogonal()
      Asserts that the matrix is orthogonal (its transpose is its inverse).
      Returns:
      this CheckerMatrix instance for further validation
    • isInvertible

      public CheckerMatrix<T> isInvertible()
      Asserts that the matrix is invertible (has a non-zero determinant).
      Returns:
      this CheckerMatrix instance for further validation
    • isPositiveDefinite

      public CheckerMatrix<T> isPositiveDefinite()
      Asserts that the matrix is positive definite (all eigenvalues are positive).
      Returns:
      this CheckerMatrix instance for further validation
    • isUpperTriangular

      public CheckerMatrix<T> isUpperTriangular()
      Asserts that the matrix is upper triangular (all elements below the main diagonal are zero).
      Returns:
      this CheckerMatrix instance for further validation
    • isLowerTriangular

      public CheckerMatrix<T> isLowerTriangular()
      Asserts that the matrix is lower triangular (all elements above the main diagonal are zero).
      Returns:
      this CheckerMatrix instance for further validation
    • hasRank

      public CheckerMatrix<T> hasRank(int rank)
      Asserts that the matrix has the specified rank.
      Parameters:
      rank - the expected rank of the matrix
      Returns:
      this CheckerMatrix instance for further validation
    • hasRealEigenvalues

      public CheckerMatrix<T> hasRealEigenvalues()
      Asserts that the matrix has only real eigenvalues.
      Returns:
      this CheckerMatrix instance for further validation
    • isFullRank

      public CheckerMatrix<T> isFullRank()
      Asserts that the matrix is full rank (rank equals the minimum of the number of rows and columns).
      Returns:
      this CheckerMatrix instance for further validation
    • anyMatch

      public CheckerMatrix<T> anyMatch(Predicate<T> predicate)
      Asserts that any element in the matrix matches the provided predicate.
      Parameters:
      predicate - the predicate to test elements
      Returns:
      this CheckerMatrix instance for further validation
    • allMatch

      public CheckerMatrix<T> allMatch(Predicate<T> predicate)
      Asserts that all elements in the matrix match the provided predicate.
      Parameters:
      predicate - the predicate to test elements
      Returns:
      this CheckerMatrix instance for further validation
    • convertToDoubleMatrix

      public static <T extends Number> double[][] convertToDoubleMatrix(T[][] matrix)
      Converts a matrix of any numeric type to a matrix of doubles.
      Type Parameters:
      T - the type of the elements in the matrix (must extend Number)
      Parameters:
      matrix - the matrix to convert
      Returns:
      a new matrix of doubles with the same dimensions as the input