Java Array Dump dumpArray(final float[] array, final int maxElemsPerLine)

Here you can find the source of dumpArray(final float[] array, final int maxElemsPerLine)

Description

Dumps the contents of the given array to stdout.

License

Open Source License

Parameter

Parameter Description
array a parameter
maxElemsPerLine a parameter

Declaration

public static final void dumpArray(final float[] array, final int maxElemsPerLine) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from  w ww.j a  v  a 2  s. c  o  m*/
     * Dumps the contents of the given array to stdout.
     * 
     * @param array
     * @param maxElemsPerLine
     */
    public static final void dumpArray(final float[] array, final int maxElemsPerLine) {
        if (array == null) {
            System.out.println((String) null);
            return;
        }

        int line = 0;

        System.out.print("[ ");
        for (int i = 0; i < array.length; i++) {
            if ((i > 0) && ((i % maxElemsPerLine) == 0)) {
                System.out.println();
                System.out.print("  ");
                line++;
            }

            System.out.print(array[i]);

            if (i < array.length - 1) {
                System.out.print(", ");
            }
        }

        if (line > 0) {
            System.out.println();
            System.out.println("]");
        } else {
            System.out.println(" ]");
        }
    }

    /**
     * Dumps the contents of the given array to stdout (in one line).
     * 
     * @param array
     */
    public static final void dumpArray(final float[] array) {
        dumpArray(array, Integer.MAX_VALUE);
    }

    /**
     * Dumps the contents of the given array to stdout.
     * 
     * @param array
     * @param maxElemsPerLine
     */
    public static final void dumpArray(final double[] array, final int maxElemsPerLine) {
        if (array == null) {
            System.out.println((String) null);
            return;
        }

        int line = 0;

        System.out.print("[ ");
        for (int i = 0; i < array.length; i++) {
            if ((i > 0) && ((i % maxElemsPerLine) == 0)) {
                System.out.println();
                System.out.print("  ");
                line++;
            }

            System.out.print(array[i]);

            if (i < array.length - 1) {
                System.out.print(", ");
            }
        }

        if (line > 0) {
            System.out.println();
            System.out.println("]");
        } else {
            System.out.println(" ]");
        }
    }

    /**
     * Dumps the contents of the given array to stdout (in one line).
     * 
     * @param array
     */
    public static final void dumpArray(final double[] array) {
        dumpArray(array, Integer.MAX_VALUE);
    }

    /**
     * Dumps the contents of the given array to stdout.
     * 
     * @param array
     * @param maxElemsPerLine
     */
    public static final void dumpArray(final int[] array, final int maxElemsPerLine) {
        if (array == null) {
            System.out.println((String) null);
            return;
        }

        int line = 0;

        System.out.print("[ ");
        for (int i = 0; i < array.length; i++) {
            if ((i > 0) && ((i % maxElemsPerLine) == 0)) {
                System.out.println();
                System.out.print("  ");
                line++;
            }

            System.out.print(array[i]);

            if (i < array.length - 1) {
                System.out.print(", ");
            }
        }

        if (line > 0) {
            System.out.println();
            System.out.println("]");
        } else {
            System.out.println(" ]");
        }
    }

    /**
     * Dumps the contents of the given array to stdout (in one line).
     * 
     * @param array
     */
    public static final void dumpArray(final int[] array) {
        dumpArray(array, Integer.MAX_VALUE);
    }

    /**
     * Dumps the contents of the given array to stdout.
     * 
     * @param array
     * @param maxElemsPerLine
     */
    public static final void dumpArray(final short[] array, final int maxElemsPerLine) {
        if (array == null) {
            System.out.println((String) null);
            return;
        }

        int line = 0;

        System.out.print("[ ");
        for (int i = 0; i < array.length; i++) {
            if ((i > 0) && ((i % maxElemsPerLine) == 0)) {
                System.out.println();
                System.out.print("  ");
                line++;
            }

            System.out.print(array[i]);

            if (i < array.length - 1) {
                System.out.print(", ");
            }
        }

        if (line > 0) {
            System.out.println();
            System.out.println("]");
        } else {
            System.out.println(" ]");
        }
    }

    /**
     * Dumps the contents of the given array to stdout (in one line).
     * 
     * @param array
     */
    public static final void dumpArray(final short[] array) {
        dumpArray(array, Integer.MAX_VALUE);
    }

    /**
     * Dumps the contents of the given array to stdout.
     * 
     * @param array
     * @param handleLikeUnsigned
     * @param maxElemsPerLine
     */
    public static final void dumpArray(final byte[] array, boolean handleLikeUnsigned, final int maxElemsPerLine) {
        if (array == null) {
            System.out.println((String) null);
            return;
        }

        int line = 0;

        System.out.print("[ ");
        for (int i = 0; i < array.length; i++) {
            if ((i > 0) && ((i % maxElemsPerLine) == 0)) {
                System.out.println();
                System.out.print("  ");
                line++;
            }

            if (handleLikeUnsigned)
                System.out.print(array[i] & 0xFF);
            else
                System.out.print(array[i]);

            if (i < array.length - 1) {
                System.out.print(", ");
            }
        }

        if (line > 0) {
            System.out.println();
            System.out.println("]");
        } else {
            System.out.println(" ]");
        }
    }

    /**
     * Dumps the contents of the given array to stdout (in one line).
     * 
     * @param array
     * @param handleLikeUnsigned
     */
    public static final void dumpArray(final byte[] array, boolean handleLikeUnsigned) {
        dumpArray(array, handleLikeUnsigned, Integer.MAX_VALUE);
    }
}

Related

  1. dump(String name, byte[] in)
  2. dump(String t, String[] arr)
  3. dump(T[] from, T[] to)
  4. dump_octets(byte[] oct)
  5. dump_strarr(String[] arr, String doc)
  6. dumpArray(String msg, float[][] A, int x1, int x2, int y1, int y2)
  7. dumpArray(String msg, Object[] refs)
  8. dumpArray(T[] ts)
  9. dumpArrayHex(byte b[])