Java List Print printList(List list0)

Here you can find the source of printList(List list0)

Description

Generates and prints the list that needs to be processed

License

Open Source License

Parameter

Parameter Description
indoorP a parameter

Return

String

Declaration

public static StringBuffer printList(List<?> list0) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*w  w w.  j a va 2 s  . c om*/
      * Generates and prints the list that needs to be processed
      * 
      * @param indoorP
      * @return String
      */
    public static StringBuffer printList(List<?> list0) {
        StringBuffer sb = new StringBuffer();

        if (list0.isEmpty()) {
            sb.append("    None");
            sb.append(System.lineSeparator());
            return sb;
        }

        List<String> list = new ArrayList<>();
        for (Object o : list0) {
            list.add(o.toString());
        }

        StringBuffer s = new StringBuffer();
        int SPACES = 22;
        //int row = 0;
        for (int i = 0; i < list.size(); i++) {
            int column = 0;

            String c = "";
            int num = 0;

            // Find out what column
            if ((i - 1) % 3 == 0)
                column = 1;
            else if ((i - 2) % 3 == 0)
                column = 2;

            // Look at how many whitespaces needed before printing each column
            if (column == 0) {
                c = list.get(i).toString();
                num = SPACES - c.length();

            }

            else if (column == 1 || column == 2) {
                c = list.get(i).toString();
                num = SPACES - list.get(i - 1).toString().length();

                // Handle the extra space before the parenthesis
                for (int j = 0; j < num; j++) {
                    s.append(" ");
                }
            }

            if (i + 1 < 10)
                s.append(" ");
            s.append("(");
            s.append(i + 1);
            s.append("). ");
            s.append(c);

            // if this is the last column
            if (column == 2 || i == list.size() - 1) {
                sb.append(s);
                sb.append(System.lineSeparator());
                s = new StringBuffer();
            }
        }

        return sb;
    }
}

Related

  1. printList(List l)
  2. printList(List l)
  3. printList(List results)
  4. printList(List l)
  5. printList(List l)
  6. printList(List list, String filename)
  7. printList(List list)
  8. printList(List> list)
  9. printList(List truthTableHeader)