Class Matrix

java.lang.Object
net.messagevortex.router.operation.Matrix
Direct Known Subclasses:
VandermondeMatrix

public class Matrix extends Object

Offers matrixContent calculations in different fields.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Matrix(int x, int y, MathMode mode)
    Creates a matrixContent (x,y) with the specified MathMode.
    Matrix(int x, int y, MathMode mode, byte[] content)
    Creates a two dimensional matrixContent (x,y) with the specified MathMode.
    Matrix(int x, int y, MathMode mode, int content)
    Creates a two dimensional matrixContent (x,y) with the specified MathMode.
    Matrix(int x, int y, MathMode mode, int[] content)
    Creates a two dimensional matrixContent (x,y) with the specified MathMode.
    Matrix(Matrix originalMatrix)
    Creates a copy of the current matrix object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    divRow(int row, int scalar)
    Divides all values of the specified row in the matrixContent by the scalar specified.
    static boolean
    enableMatrixCache(boolean enable)
    Enables or disables the matrixContent cache.
    boolean
     
    void
    flipRow(int row1, int row2)
    Flips two rows of the current matrixContent.
    byte[]
    Get the content of the matrixContent as byte array.
    int
    getField(int x, int y)
    Extracts the value of a specified matrixContent field.
    Calculates the inverse by applying the Gauss-Jordan-algorithm.
    int[]
    getRow(int i)
    Get a row of the matrixContent as array.
    byte[]
    Get the values of a row as byte arrays.
    int
    Get the number of columns.
    int
    Set the number of rows.
    int
     
    Multiplies the current matrixContent with the specified matrixContent.
    static Matrix
    randomMatrix(int x, int y, MathMode mode)
    Returns a matrixContent with the specified dimension initialised with random values.
    void
    removeRow(int index)
    Removes the specified row from the matrixContent.
    int
    setField(int x, int y, int value)
    Sets the value of a specified matrixContent field.
    int
    setModulo(int i)
    Sets a modulo value of the matrixContent for all operations.
     
    void
    transformColumn(int col, int col2, int scalar)
    Multiplies element by element the values of the second column by the specified scalar and subtracts the resulting value from the first element.
    void
    transformRow(int row, int row2, int scalar, boolean doDiv)
    Divides or multiplies element by element the values of the second row by the specified scalar and subtracts the resulting value from the first element.
    static Matrix
    unitMatrix(int size, MathMode mode)
    Creates a two dimensional unit matrixContent (size,size) with the specified MathMode.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Matrix

      public Matrix(Matrix originalMatrix)

      Creates a copy of the current matrix object.

      Parameters:
      originalMatrix - the matrix to be copied
    • Matrix

      public Matrix(int x, int y, MathMode mode)

      Creates a matrixContent (x,y) with the specified MathMode.

      Parameters:
      x - the number of columns of the matrixContent
      y - the number of rows of the matrixContent
      mode - the math mode to be applied
    • Matrix

      public Matrix(int x, int y, MathMode mode, int[] content)

      Creates a two dimensional matrixContent (x,y) with the specified MathMode.

      Parameters:
      x - the number of columns of the matrixContent
      y - the number of rows of the matrixContent
      mode - the math mode to be applied
      content - the content as one dimensional array (sequence of rows)
    • Matrix

      public Matrix(int x, int y, MathMode mode, byte[] content)

      Creates a two dimensional matrixContent (x,y) with the specified MathMode.

      Parameters:
      x - the number of columns of the matrixContent
      y - the number of rows of the matrixContent
      mode - the math mode to be applied
      content - the content as one dimensional array (sequence of rows)
    • Matrix

      public Matrix(int x, int y, MathMode mode, int content)

      Creates a two dimensional matrixContent (x,y) with the specified MathMode.

      Parameters:
      x - the number of columns of the matrixContent
      y - the number of rows of the matrixContent
      mode - the math mode to be applied
      content - the value to be set in all fields
  • Method Details

    • unitMatrix

      public static Matrix unitMatrix(int size, MathMode mode)

      Creates a two dimensional unit matrixContent (size,size) with the specified MathMode.

      Parameters:
      size - the number of columns of the matrixContent
      mode - the math mode to be applied
      Returns:
      the requested matrix
    • getX

      public int getX()

      Get the number of columns.

      Returns:
      the number of columns as int value
    • getY

      public int getY()

      Set the number of rows.

      Returns:
      the number of rows as int value
    • removeRow

      public void removeRow(int index)

      Removes the specified row from the matrixContent.

      Parameters:
      index - the index of the row to be removed (starting with 0)
    • randomMatrix

      public static Matrix randomMatrix(int x, int y, MathMode mode)

      Returns a matrixContent with the specified dimension initialised with random values.

      Parameters:
      x - the number of columns of the matrixContent
      y - the number of rows of the matrixContent
      mode - the math mode to be applied
      Returns:
      the generated matrixContent
    • mul

      public Matrix mul(Matrix m)

      Multiplies the current matrixContent with the specified matrixContent.

      Parameters:
      m - the matrixContent to multiply with
      Returns:
      the resulting matrixContent
      Throws:
      ArithmeticException - if multiplication may not be carried out
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setModulo

      public int setModulo(int i)

      Sets a modulo value of the matrixContent for all operations.

      Parameters:
      i - the value to be used as modulo
      Returns:
      the previously set modulo
    • getRow

      public int[] getRow(int i)

      Get a row of the matrixContent as array.

      Parameters:
      i - the index of the row to be extracted as array
      Returns:
      the row representation as array
    • getField

      public int getField(int x, int y)

      Extracts the value of a specified matrixContent field.

      Parameters:
      x - the column of the field
      y - the row of the field
      Returns:
      the value of the field
    • setField

      public int setField(int x, int y, int value)

      Sets the value of a specified matrixContent field.

      Parameters:
      x - the column of the field
      y - the row of the field
      value - the value to be set
      Returns:
      the previously set value of the field
    • getInverse

      public Matrix getInverse()

      Calculates the inverse by applying the Gauss-Jordan-algorithm.

      Returns:
      the inverse of the matrixContent
      Throws:
      ArithmeticException - if matrixContent is not square in dimensions or the algorithm was unable to compute an inverse
    • getRowAsByteArray

      public byte[] getRowAsByteArray(int row)

      Get the values of a row as byte arrays.

      Parameters:
      row - the index of the row to be used (starting with 0)
      Returns:
      the array containing the values of the row
    • getAsByteArray

      public byte[] getAsByteArray()

      Get the content of the matrixContent as byte array.

      Returns:
      the byte array representing the matrixContent values (row by row)
    • transformColumn

      public void transformColumn(int col, int col2, int scalar)

      Multiplies element by element the values of the second column by the specified scalar and subtracts the resulting value from the first element.

      Parameters:
      col - the column to be recalculated/altered
      col2 - the column to be used for recalculation
      scalar - the scalar to be used for division/multiplication
    • transformRow

      public void transformRow(int row, int row2, int scalar, boolean doDiv)

      Divides or multiplies element by element the values of the second row by the specified scalar and subtracts the resulting value from the first element.

      Parameters:
      row - the row o be recalculated/altered
      row2 - the row to be used for recalculation
      scalar - the scalar to be used for division/multiplication
      doDiv - flag to specify whether division (true) or multiplication (false) should be used
    • divRow

      public void divRow(int row, int scalar)

      Divides all values of the specified row in the matrixContent by the scalar specified.

      Parameters:
      row - the index of the row (starting with 0)
      scalar - the scalar to be used as divisor
    • flipRow

      public void flipRow(int row1, int row2)

      Flips two rows of the current matrixContent.

      Parameters:
      row1 - index of the first row (starting with 0)
      row2 - index of the second row (starting with 0)
    • enableMatrixCache

      public static boolean enableMatrixCache(boolean enable)

      Enables or disables the matrixContent cache.

      Parameters:
      enable - set to true if matrixContent cache should be enabled
      Returns:
      the previously set value