Java File Size Readable Format formatSeperatorRow(int[] sizes)

Here you can find the source of formatSeperatorRow(int[] sizes)

Description

Format seperator row.

License

Open Source License

Parameter

Parameter Description
sizes the sizes

Return

the string

Declaration

public static String formatSeperatorRow(int[] sizes) 

Method Source Code

//package com.java2s;

public class Main {
    private static final String SPACES = "                                                ";
    private static final String DASHES = "------------------------------------------------";

    /**/*from  w  ww .j av  a  2s . com*/
     * Format seperator row.
     * 
     * @param sizes
     *            the sizes
     * 
     * @return the string
     */
    public static String formatSeperatorRow(int[] sizes) {
        String[] values = new String[sizes.length];
        for (int i = 0; i < values.length; i++) {
            values[i] = DASHES;
        }

        return formatRow(" ", values, sizes);
    }

    /**
     * Format row.
     * 
     * @param values
     *            the values
     * @param sizes
     *            the sizes
     * 
     * @return the string
     */
    public static String formatRow(String[] values, int[] sizes) {
        return formatRow(" ", values, sizes);
    }

    /**
     * Format row.
     * 
     * @param prefix
     *            the prefix
     * @param values
     *            the values
     * @param sizes
     *            the sizes
     * 
     * @return the string
     */
    public static String formatRow(String prefix, String[] values, int[] sizes) {
        StringBuffer sb = new StringBuffer();

        sb.append(prefix);
        for (int i = 0; i < sizes.length; i++) {
            if (i != 0) {
                sb.append(" ");
            }
            sb.append(fixLength(values[i], sizes[i]));
        }

        return sb.toString();
    }

    /**
     * Fix length.
     * 
     * @param str
     *            the str
     * @param len
     *            the len
     * 
     * @return the string
     */
    public static String fixLength(String str, int len) {
        if (str != null) {
            str = str + SPACES;
        } else {
            str = SPACES;
        }
        return str.substring(0, len);
    }
}

Related

  1. formatFileStats(final String label, final long fileCount, final Object rawSize)
  2. formatGroup(String str, int groupSize, int lineBreak)
  3. formatIndex(int index, int totalSize)
  4. formatInt(int val, int size)
  5. formatRow(String[] values, int[] sizes)
  6. formatShortByte(long size)
  7. formatSize(double size)
  8. formatSize(Integer size)
  9. formatSize(long bytes)