Package hlcd.operations
Class MatrixPrinter
java.lang.Object
hlcd.operations.MatrixPrinter
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
ConstructorsConstructorDescriptionMatrixPrinter(long[] matrixArray, byte n, byte k, byte base, Style style)Constructs a simple printer for the matrix specified. -
Method Summary
Modifier and TypeMethodDescriptionvoidPrints 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.voidprintMatrix(boolean addBrackets, boolean showSize)Prints the matrix on console while having the space character as the delimiter between the columns.voidprintMatrix(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.voidprintMatrix(String delimiter, boolean addBrackets, boolean showSize)Prints the matrix on console while having the specified delimiter between the columns.voidprintMatrix(String delimiter, boolean addBrackets, Style style, boolean showSize)Prints the matrix on console while having the specified delimiter between the columns.static StringvectorAsString(long vector, byte n, byte base, String delimiter, Style style)Returns a formatted vector based on the properties specified.
-
Constructor Details
-
MatrixPrinter
Constructs a simple printer for the matrix specified.- Parameters:
matrixArray- the matrix to be displayed on consolen- the length of each vectork- the dimension of the matrixbase- 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 bracketsshowSize- should the dimension of the matrix be displayed in the bottom-right corner
-
printMatrix
Prints the matrix on console while having the specified delimiter between the columns.- Parameters:
delimiter- the delimiter used to separate the digitsaddBrackets- should surround the matrix with bracketsshowSize- should the dimension of the matrix be displayed in the bottom-right corner
-
printMatrix
Prints the matrix on console while having the specified delimiter between the columns.- Parameters:
delimiter- the delimiter used to separate the digitsaddBrackets- should surround the matrix array with bracketsstyle- 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 consolen- the length of each vector in the matrix arraybase- the base of the code which could either be \(2\) or \(4\)delimiter- the delimiter used to separate the digitsaddBrackets- should surround the matrix array with bracketsstyle- 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
Returns a formatted vector based on the properties specified.- Parameters:
vector- the vector to be formattedn- the length of the vectorbase- the base of the code which could either be \(2\) or \(4\)delimiter- the delimiter used to separate the digits in the vectorstyle- the style format which could either be binary, quaternary, decimal or \(\LaTeX\)- Returns:
- a formatted vector based on the properties specified
-