Class PrettyPrint
java.lang.Object
org.flag4j.io.PrettyPrint
Utility class for formatting arrays as ★★pretty★★ human-readable strings.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringabbreviatedArray(double[] arr, int maxEntries, int padding, int precision, boolean centering) Formats array as an abbreviated array so that no more thanmaxEntriesis actually printed.static StringabbreviatedArray(int[][] arr, int maxRows, int maxCols, int padding, int offset, boolean centering) Formats array as an abbreviated array so that no more thanmaxColsis actually printed.static StringabbreviatedArray(int[] arr, int maxEntries, int padding, boolean centering) Formats array as an abbreviated array so that no more thanmaxEntriesis actually printed.static <T> StringabbreviatedArray(T[] arr, int maxEntries, int padding, int precision, boolean centering) Formats array as an abbreviated array so that no more thanmaxEntriesis actually printed.static <T> StringmatrixToString(Shape shape, double[] data) Converts a matrix into a "pretty" string using parameters set in thePrintOptionsclass.static <T> StringmatrixToString(Shape shape, T[] data) Converts a matrix into a "pretty" string using parameters set in thePrintOptionsclass.static intmaxStringLengthRounded(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> intmaxStringLengthRounded(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 specifiedstride.static <T> intmaxStringLengthRounded(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> intmaxStringLengthRounded(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 specifiedstride.
-
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 thanmaxEntriesis 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 thanmaxEntriesis 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 thanmaxColsis 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
Formats array as an abbreviated array so that no more thanmaxEntriesis 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 specifiedstride.- Type Parameters:
T- Type of elements within the array.- Parameters:
src- Array to find maximum length string representationstartIdx- 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 withinsrcto check.finalIdx- The final index to consider for the maximum length string. The length of the string representation of the element at this index insrcis always considered.- Returns:
- The maximum string representation length of elements within
srcbetween indicesstartIdx(inclusive) andstopIdxspaced bystrideand a final element at indexfinalIdx.
-
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 specifiedstride.- Type Parameters:
T- Type of elements within the array.- Parameters:
src- Array to find maximum length string representationstartIdx- 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 withinsrcto check.finalIdx- The final index to consider for the maximum length string. The length of the string representation of the element at this index insrcis always considered.- Returns:
- The maximum string representation length of elements within
srcbetween indicesstartIdx(inclusive) andstopIdxspaced bystrideand a final element at indexfinalIdx.
-
matrixToString
Converts a matrix into a "pretty" string using parameters set in thePrintOptionsclass.- 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
Converts a matrix into a "pretty" string using parameters set in thePrintOptionsclass.- 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.
-