Class PrettyPrint

java.lang.Object
org.flag4j.io.PrettyPrint

public final class PrettyPrint extends Object
Utility class for formatting arrays as ★★pretty★★ human-readable strings.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    abbreviatedArray(double[] arr, int maxEntries, int padding, int precision, boolean centering)
    Formats array as an abbreviated array so that no more than maxEntries is actually printed.
    static String
    abbreviatedArray(int[][] arr, int maxRows, int maxCols, int padding, int offset, boolean centering)
    Formats array as an abbreviated array so that no more than maxCols is actually printed.
    static String
    abbreviatedArray(int[] arr, int maxEntries, int padding, boolean centering)
    Formats array as an abbreviated array so that no more than maxEntries is actually printed.
    static <T> String
    abbreviatedArray(T[] arr, int maxEntries, int padding, int precision, boolean centering)
    Formats array as an abbreviated array so that no more than maxEntries is actually printed.
    static <T> String
    matrixToString(Shape shape, double[] data)
    Converts a matrix into a "pretty" string using parameters set in the PrintOptions class.
    static <T> String
    matrixToString(Shape shape, T[] data)
    Converts a matrix into a "pretty" string using parameters set in the PrintOptions class.
    static int
    maxStringLengthRounded(double[] src, int stopIndex)
    Computes the maximum length of the string representation of a double in an array of doubles up until stopping index.
    static <T> int
    maxStringLengthRounded(double[] src, int startIdx, int stopIdx, int stride, int finalIdx)
    Computes the maximum length of the string representation of an element in an array over a specified range with elements spaced by some specified stride.
    static <T> int
    maxStringLengthRounded(T[] src, int stopIndex)
    Computes the maximum length of the string representation of an element in an array up until some stopping index.
    static <T> int
    maxStringLengthRounded(T[] src, int startIdx, int stopIdx, int stride, int finalIdx)
    Computes the maximum length of the string representation of an element in an array over a specified range with elements spaced by some specified stride.

    Methods inherited from class java.lang.Object

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

    • abbreviatedArray

      public static String abbreviatedArray(double[] arr, int maxEntries, int padding, int precision, boolean centering)
      Formats array as an abbreviated array so that no more than maxEntries is actually printed.
      Parameters:
      arr - Array to format.
      maxEntries - The maximum number of data to print.
      padding - The amount of padding to use between each entry.
      precision - The number of decimal places to print for each value.
      centering - Flag indicating if each value should be centered within the padding.
      Returns:
      A string representing the abbreviated and formatted array.
    • abbreviatedArray

      public static <T> String abbreviatedArray(T[] arr, int maxEntries, int padding, int precision, boolean centering)
      Formats array as an abbreviated array so that no more than maxEntries is actually printed.
      Parameters:
      arr - Array to format.
      maxEntries - The maximum number of data to print.
      padding - The amount of padding to use between each entry.
      precision - The number of decimal places to print for each value.
      centering - Flag indicating if each value should be centered within the padding.
      Returns:
      A string representing the abbreviated and formatted array.
    • abbreviatedArray

      public static String abbreviatedArray(int[][] arr, int maxRows, int maxCols, int padding, int offset, boolean centering)
      Formats array as an abbreviated array so that no more than maxCols is actually printed.
      Parameters:
      arr - Array to format.
      maxRows - Maximum number of rows to print.
      maxCols - The maximum number of columns to print.
      padding - The amount of padding to use between each entry.
      offset - Offset for array rows after the first.
      centering - Flag indicating if each value should be centered within the padding.
      centering - Flag indicating if each value should be centered within the padding.
      Returns:
      A string representing the abbreviated and formatted array.
    • abbreviatedArray

      public static String abbreviatedArray(int[] arr, int maxEntries, int padding, boolean centering)
      Formats array as an abbreviated array so that no more than maxEntries is actually printed.
      Parameters:
      arr - Array to format.
      maxEntries - The maximum number of data to print.
      padding - The amount of padding to use between each entry.
      centering - Flag indicating if each value should be centered within the padding.
      precision - The number of decimal places to print for each value.
      Returns:
      A string representing the abbreviated and formatted array.
    • maxStringLengthRounded

      public static int maxStringLengthRounded(double[] src, int stopIndex)
      Computes the maximum length of the string representation of a double in an array of doubles up until stopping index. The length of the last element is always considered.
      Parameters:
      src - Array for which to compute the max string representation length of a double in.
      stopIndex - Stopping index for finding max length.
      Returns:
      The maximum length of the string representation of the doubles in the array.
    • maxStringLengthRounded

      public static <T> int maxStringLengthRounded(T[] src, int stopIndex)
      Computes the maximum length of the string representation of an element in an array up until some stopping index. The length of the last element is always considered.
      Parameters:
      src - Array for which to compute the max string representation length of a double in.
      stopIndex - Stopping index for finding max length.
      Returns:
      The maximum length of the string representation of the doubles in the array.
    • maxStringLengthRounded

      public static <T> int maxStringLengthRounded(double[] src, int startIdx, int stopIdx, int stride, int finalIdx)
      Computes the maximum length of the string representation of an element in an array over a specified range with elements spaced by some specified stride.
      Type Parameters:
      T - Type of elements within the array.
      Parameters:
      src - Array to find maximum length string representation
      startIdx - Staring index to search for maximum length string (inclusive).
      stopIdx - Stopping index to search for maximum length string (exclusive).
      stride - The gap between consecutive elements within src to check.
      finalIdx - The final index to consider for the maximum length string. The length of the string representation of the element at this index in src is always considered.
      Returns:
      The maximum string representation length of elements within src between indices startIdx (inclusive) and stopIdx spaced by stride and a final element at index finalIdx.
    • maxStringLengthRounded

      public static <T> int maxStringLengthRounded(T[] src, int startIdx, int stopIdx, int stride, int finalIdx)
      Computes the maximum length of the string representation of an element in an array over a specified range with elements spaced by some specified stride.
      Type Parameters:
      T - Type of elements within the array.
      Parameters:
      src - Array to find maximum length string representation
      startIdx - Staring index to search for maximum length string (inclusive).
      stopIdx - Stopping index to search for maximum length string (exclusive).
      stride - The gap between consecutive elements within src to check.
      finalIdx - The final index to consider for the maximum length string. The length of the string representation of the element at this index in src is always considered.
      Returns:
      The maximum string representation length of elements within src between indices startIdx (inclusive) and stopIdx spaced by stride and a final element at index finalIdx.
    • matrixToString

      public static <T> String matrixToString(Shape shape, double[] data)
      Converts a matrix into a "pretty" string using parameters set in the PrintOptions class.
      Type Parameters:
      T - Type of an individual entry of the matrix.
      Parameters:
      shape - Shape of the matrix. Must be rank 2.
      data - Entries of the matrix.
      Returns:
      This matrix represented as a "pretty" string.
    • matrixToString

      public static <T> String matrixToString(Shape shape, T[] data)
      Converts a matrix into a "pretty" string using parameters set in the PrintOptions class.
      Type Parameters:
      T - Type of an individual entry of the matrix.
      Parameters:
      shape - Shape of the matrix. Must be rank 2.
      data - Entries of the matrix.
      Returns:
      This matrix represented as a "pretty" string.