Class MatrixPrinter

java.lang.Object
hlcd.operations.MatrixPrinter

public class MatrixPrinter extends Object
Prints a matrix nicely on console. There are three different formats to choose from: binary, quaternary and decimal. The binary format will print the binary representation of a vector regardless of whether the code is in base \(2\) or \(4\). The quaternary format prints 0, 1, 2 and 3 as 0, 1, ω and ε, respectively. The decimal format will print the digits in base 10 (i.e., 0, 1, 2 and 3). Lastly, the LaTeX option will render the digits in LaTeX format. There are other aesthetics that will be taken place like placing matrix lines around a matrix, printing the dimension of a matrix in the lower-right corner and adding a delimiter between the digits.
 //minimal example to execute this class:
 public static void main(String[] args) {
     System.out.println("Running MatrixPrinter...");
     long[] matrixArray = new long[]{
         0b11100100,
         0b00000000,
         0b01010101,
         0b10101010,
         0b11111111
     };
     byte n = 4;
     byte k = 5;
     byte base = 4;
     Style style = Style.DECIMAL;
     MatrixPrinter mp = new MatrixPrinter(matrixArray, n, k, base, style);
     mp.printMatrix(" ", true, Style.DECIMAL, true);
     mp.printMatrix(" ", true, Style.BINARY, true);
     mp.printMatrix(" ", true, Style.QUATERNARY, true);
     mp.printMatrix(" & ", true, Style.LATEX, true);
     System.out.println("MatrixPrinter completed.");
 }
Since:
February 2nd, 2022
Version:
1.0
Author:
Maysara Al Jumaily
  • Constructor Summary

    Constructors
    Constructor
    Description
    MatrixPrinter​(long[] matrixArray, byte n, byte k, byte base, Style style)
    Constructs a simple printer for the matrix specified.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Prints the matrix with the following default values: with a space character as the delimiter between the columns, surrounding the matrix with square brackets as well as showing the dimension.
    void
    printMatrix​(boolean addBrackets, boolean showSize)
    Prints the matrix on console while having the space character as the delimiter between the columns.
    void
    printMatrix​(long[] matrixArray, byte n, byte base, String delimiter, boolean addBrackets, Style style, boolean showSize)
    Prints the matrix array on console using the other parameters specified.
    void
    printMatrix​(String delimiter, boolean addBrackets, boolean showSize)
    Prints the matrix on console while having the specified delimiter between the columns.
    void
    printMatrix​(String delimiter, boolean addBrackets, Style style, boolean showSize)
    Prints the matrix on console while having the specified delimiter between the columns.
    static String
    vectorAsString​(long vector, byte n, byte base, String delimiter, Style style)
    Returns a formatted vector based on the properties specified.

    Methods inherited from class java.lang.Object

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

    • MatrixPrinter

      public MatrixPrinter(long[] matrixArray, byte n, byte k, byte base, Style style)
      Constructs a simple printer for the matrix specified.
      Parameters:
      matrixArray - the matrix to be displayed on console
      n - the length of each vector
      k - the dimension of the matrix
      base - the base of which could either be \(2\) or \(4\)
      style - the style format which could either be binary, quaternary, decimal or \(\LaTeX\)
  • Method Details

    • printMatrix

      public void printMatrix()
      Prints the matrix with the following default values: with a space character as the delimiter between the columns, surrounding the matrix with square brackets as well as showing the dimension.
    • printMatrix

      public void printMatrix(boolean addBrackets, boolean showSize)
      Prints the matrix on console while having the space character as the delimiter between the columns.
      Parameters:
      addBrackets - should surround the matrix with brackets
      showSize - should the dimension of the matrix be displayed in the bottom-right corner
    • printMatrix

      public void printMatrix(String delimiter, boolean addBrackets, boolean showSize)
      Prints the matrix on console while having the specified delimiter between the columns.
      Parameters:
      delimiter - the delimiter used to separate the digits
      addBrackets - should surround the matrix with brackets
      showSize - should the dimension of the matrix be displayed in the bottom-right corner
    • printMatrix

      public void printMatrix(String delimiter, boolean addBrackets, Style style, boolean showSize)
      Prints the matrix on console while having the specified delimiter between the columns.
      Parameters:
      delimiter - the delimiter used to separate the digits
      addBrackets - should surround the matrix array with brackets
      style - the style format which could either be binary, quaternary, decimal or \(\LaTeX\)
      showSize - should the dimension of the matrix array be displayed in the bottom-right corner
    • printMatrix

      public void printMatrix(long[] matrixArray, byte n, byte base, String delimiter, boolean addBrackets, Style style, boolean showSize)
      Prints the matrix array on console using the other parameters specified.
      Parameters:
      matrixArray - the matrix array to be printed on console
      n - the length of each vector in the matrix array
      base - the base of the code which could either be \(2\) or \(4\)
      delimiter - the delimiter used to separate the digits
      addBrackets - should surround the matrix array with brackets
      style - the style format which could either be binary, quaternary, decimal or \(\LaTeX\)
      showSize - should the dimension of the matrix array be displayed in the bottom-right corner
    • vectorAsString

      public static String vectorAsString(long vector, byte n, byte base, String delimiter, Style style)
      Returns a formatted vector based on the properties specified.
      Parameters:
      vector - the vector to be formatted
      n - the length of the vector
      base - the base of the code which could either be \(2\) or \(4\)
      delimiter - the delimiter used to separate the digits in the vector
      style - the style format which could either be binary, quaternary, decimal or \(\LaTeX\)
      Returns:
      a formatted vector based on the properties specified