Class Functions

java.lang.Object
hlcd.operations.Functions

public class Functions extends Object
A class contains static variables and methods to be used globally across the classes in this program. It deals mostly with checking if the values being used for matrix dimension, bases, indices, etc. are valid.
Since:
February 2nd, 2022
Version:
1.0
Author:
Maysara Al Jumaily
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static long
    Contains 64 1's: 0b11111111_11111111_11111111_11111111_11111111_11111111_11111111_11111111
    static byte[][]
    The division logic in base \(4\).
    static long
    The decimal value "15" repeated in binary: 0b00001111_00001111_00001111_00001111_00001111_00001111_00001111_00001111
    static byte[][]
    The multiplication logic in base \(4\).
    static long
    The decimal value "1" repeated in binary: 0b01010101_01010101_01010101_01010101_01010101_01010101_01010101_01010101
    static long
    The decimal value "3" repeated in binary: 0b00110011_00110011_00110011_00110011_00110011_00110011_00110011_00110011
    static long
    The decimal value "2" repeated in binary: 0b10101010_10101010_10101010_10101010_10101010_10101010_10101010_10101010
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isValidBase​(byte base)
    Checks whether the base of the code is valid.
    static boolean
    isValidColIndex​(byte index, byte maxCol)
    Checks whether the specified column index is valid.
    static boolean
    isValidColumnVectorDimension​(byte columnVectorRowCount, byte k)
    Checks if a column vector is appropriate in the sense that its length should be between \(1\) and \(k\) (one-based).
    static boolean
    isValidDigit​(byte digit, byte base)
    Checks whether the digit specified is a valid digit in the base passed.
    static boolean
    isValidIdentityRowIndex​(byte index, byte k)
    Checks whether the specified row index is valid row in an identity matrix.
    static boolean
    isValidMatrixMultiplicationDimension​(long[] leftMatrixArray, byte leftMatrixArrayN, byte leftMatrixArrayK, long[] rightMatrixArray, byte rightMatrixArrayN, byte rightMatrixArrayK)
    Checks if the dimension of two matrices leftMatrixArray and rightMatrixArray is valid for performing the multiplication.
    static boolean
    isValidMinimumDistance​(byte minimumDistance)
    Checks whether the passed minimum distance is valid.
    static boolean
    isValidNAndKValues​(byte n, byte k)
    Checks whether the \(n\) and \(k\) values being used are valid.
    static boolean
    isValidRowIndex​(byte index, byte maxRow)
    Checks whether the specified row index is valid.
    static boolean
    isValidSettingColumnInMatrix​(byte columnVectorRowCount, byte matrixRowCount)
    Checks if a column vector is appropriate to be placed inside a matrix.
    static long
    power​(long x, long n)
    Efficiently finds the result of \(x^n\).
    static String
    An aesthetic way to draw a solid (non-dashed) line on console by using the character .
    static String
    writeConsoleLineSeparator​(byte length)
    An aesthetic way to draw a solid (non-dashed) line on console by using the character .

    Methods inherited from class java.lang.Object

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

    • ONE

      public static final long ONE
      The decimal value "1" repeated in binary: 0b01010101_01010101_01010101_01010101_01010101_01010101_01010101_01010101
      See Also:
      Constant Field Values
    • TWO

      public static final long TWO
      The decimal value "2" repeated in binary: 0b10101010_10101010_10101010_10101010_10101010_10101010_10101010_10101010
      See Also:
      Constant Field Values
    • THREE

      public static final long THREE
      The decimal value "3" repeated in binary: 0b00110011_00110011_00110011_00110011_00110011_00110011_00110011_00110011
      See Also:
      Constant Field Values
    • F

      public static final long F
      The decimal value "15" repeated in binary: 0b00001111_00001111_00001111_00001111_00001111_00001111_00001111_00001111
      See Also:
      Constant Field Values
    • ALL_ONES

      public static final long ALL_ONES
      Contains 64 1's: 0b11111111_11111111_11111111_11111111_11111111_11111111_11111111_11111111
      See Also:
      Constant Field Values
    • MUL_ARRAY

      public static final byte[][] MUL_ARRAY
      The multiplication logic in base \(4\). It is given as:
      The multiplication table in base \(4\)
      \(\times\) \(0\) \(1\) \(\omega\) \(\overline{\omega}\)
      \(0\) \(0\) \(0\) \(0\) \(0\)
      \(1\) \(0\) \(1\) \(\omega\) \(\overline{\omega}\)
      \(\omega\) \(0\) \(\omega\) \(\overline{\omega}\) \(1\)
      \(\overline{\omega}\) \(0\) \(\overline{\omega}\) \(1\) \(\omega\)
    • DIV_ARRAY

      public static final byte[][] DIV_ARRAY
      The division logic in base \(4\). Note that the far-left column is not defined (division by 0), hence, denoted as "\(-\)" and in code, assigned the number -99 . It is given as:
      The division table in base \(4\)
      \(\div\) \(0\) \(1\) \(\omega\) \(\overline{\omega}\)
      \(0\) \(-\) \(0\) \(0\) \(0\)
      \(1\) \(-\) \(1\) \(\overline{\omega}\) \(\omega\)
      \(\omega\) \(-\) \(\omega\) \(1\) \(\overline{\omega}\)
      \(\overline{\omega}\) \(-\) \(\overline{\omega}\) \(\omega\) \(1\)
  • Method Details

    • isValidBase

      public static boolean isValidBase(byte base)
      Checks whether the base of the code is valid. A valid base is either \(2\) or \(4\).
      Parameters:
      base - the base of the code (could be either \(2\) or \(4\))
      Returns:
      true if the base is valid (i.e., \(2\) or \(4\)), false otherwise
    • isValidNAndKValues

      public static boolean isValidNAndKValues(byte n, byte k)
      Checks whether the \(n\) and \(k\) values being used are valid. They are valid in base \(2\) if \(1 \leq k \leq 62\), \(1 \leq n \leq 62\), \(1 \leq k \leq n\) and valid in base \(4\) if \(1 \leq k \leq 30\), \(1 \leq n \leq 30\) and \(1 \leq k \leq n\).
      Parameters:
      n - the length of a codeword in the code
      k - the dimension of the code
      Returns:
      true if \(n\) and \(k\) are valid, false otherwise
    • isValidMinimumDistance

      public static boolean isValidMinimumDistance(byte minimumDistance)
      Checks whether the passed minimum distance is valid. The implementation of this program doesn't support minimum distance of \(d \lt 3\).
      Parameters:
      minimumDistance - the minimum distance to be checked
      Returns:
      true if the minimum distance bigger or equal to \(3\), false otherwise
    • isValidColIndex

      public static boolean isValidColIndex(byte index, byte maxCol)
      Checks whether the specified column index is valid. A column index is zero-based.
      Parameters:
      index - the column index to check
      maxCol - the maximum valid column that is accessible. This is one-based so the column index must be strictly less than
      Returns:
      true if the column index is within the appropriate range, false otherwise
    • isValidRowIndex

      public static boolean isValidRowIndex(byte index, byte maxRow)
      Checks whether the specified row index is valid. A row index is zero-based.
      Parameters:
      index - the row index to check
      maxRow - the maximum valid row that is accessible. This is one-based so the row index must be strictly less than
      Returns:
      true if the row index is within the appropriate range, false otherwise
    • isValidIdentityRowIndex

      public static boolean isValidIdentityRowIndex(byte index, byte k)
      Checks whether the specified row index is valid row in an identity matrix. A row index is zero-based.
      Parameters:
      index - the row index to check
      k - the maximum valid row that is accessible. This is one-based so the row index must be strictly less than
      Returns:
      true if the row index is within the appropriate range, false otherwise
    • isValidSettingColumnInMatrix

      public static boolean isValidSettingColumnInMatrix(byte columnVectorRowCount, byte matrixRowCount)
      Checks if a column vector is appropriate to be placed inside a matrix. The number of rows in the column vector must match the number of rows in the matrix. It doesn't matter if it is zero-based or one-based as long as both use the same convention. Keep it as one-based if in doubt.
      Parameters:
      columnVectorRowCount - the number of rows in the column vector
      matrixRowCount - the number of rows in the matrix
      Returns:
      true if both the column vector and matrix have the same number of rows, false otherwise
    • isValidColumnVectorDimension

      public static boolean isValidColumnVectorDimension(byte columnVectorRowCount, byte k)
      Checks if a column vector is appropriate in the sense that its length should be between \(1\) and \(k\) (one-based).
      Parameters:
      columnVectorRowCount - the number of rows in the column vector
      k - the length of the code
      Returns:
      true if the column vector has a valid size, false otherwise
    • isValidDigit

      public static boolean isValidDigit(byte digit, byte base)
      Checks whether the digit specified is a valid digit in the base passed.
      Parameters:
      digit - the digit to check
      base - the base of the code
      Returns:
      true if the digit is valid in the base passed, false otherwise
    • isValidMatrixMultiplicationDimension

      public static boolean isValidMatrixMultiplicationDimension(long[] leftMatrixArray, byte leftMatrixArrayN, byte leftMatrixArrayK, long[] rightMatrixArray, byte rightMatrixArrayN, byte rightMatrixArrayK)
      Checks if the dimension of two matrices leftMatrixArray and rightMatrixArray is valid for performing the multiplication.
      Parameters:
      leftMatrixArray - the left matrix to be multiplied
      leftMatrixArrayN - the number of columns in the left matrix
      leftMatrixArrayK - the number of rows in the left matrix
      rightMatrixArray - the right matrix to be multiplied
      rightMatrixArrayN - the number of columns in the right matrix
      rightMatrixArrayK - the number of rows in the right matrix
      Returns:
      true if the multiplication can be performed, false otherwise
    • writeConsoleLineSeparator

      public static String writeConsoleLineSeparator()
      An aesthetic way to draw a solid (non-dashed) line on console by using the character . It will automatically draw a horizontal line consisting of 80 characters.
      Returns:
      A string containing 80 characters of .
    • writeConsoleLineSeparator

      public static String writeConsoleLineSeparator(byte length)
      An aesthetic way to draw a solid (non-dashed) line on console by using the character . It will create a horizontal line consisting of the specified length.
      Parameters:
      length - the length of the line
      Returns:
      A string of the length specified containing characters of .
    • power

      public static long power(long x, long n)
      Efficiently finds the result of \(x^n\). In the case where \(n=63\) or \(n=64\), then the maximum value that will be return is \(2^{63} - 1 = 9223372036854775807\). Since this only return positive values, we cannot have a binary vector of length \(63\) nor \(64\) or a quaternary vector of length \(31\) nor \(32\). In the case where an invalid length is passed, then a warning message will be displayed on console. All in all, the valid lengths for a binary code is between \(1\) and \(62\) (including both) and for a quaternary code is between \(1\) and \(30\) (including both).
      Parameters:
      x - the base of the power
      n - the number to raise to
      Returns:
      the result of \(x^n\)