Java Dump Stream dumpMap(PrintStream out, Map Values)

Here you can find the source of dumpMap(PrintStream out, Map Values)

Description

print a string listing what is in a Map Works best of all entried are string or have good toString methods

License

Apache License

Parameter

Parameter Description
out non-null printstream
Values non-null Map

Declaration

public static void dumpMap(PrintStream out, Map Values) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;

import java.util.*;

public class Main {
    /**//www.j  a v a 2  s. c  o m
     * print a string listing what is in a Map
     * Works best of all entried are string or have
     * good toString methods
     * @param out non-null printstream
     * @param Values non-null Map
     */
    public static void dumpMap(PrintStream out, Map Values) {
        out.println(describeMap(Values));
    }

    /**
      * Wrapper for System.out.println so I can track
      * where output is coming from
     * @param s non-null string to print
     */
    public static void println(Object s) {
        println(s.toString());
    }

    /**
      * Wrapper for System.out.println so I can track
      * where output is coming from
     * @param s non-null string to print
     */
    public static void println(String s) {
        System.out.println(s);
    }

    /**
     * build a strig listing what is in a Map
     * Works best of all entried are string or have
     * good toString methods
     * @param Values non-null Map
     * @return non-nul string
     */
    public static String describeMap(Map Values) {
        SortedSet keys = new TreeSet(Values.keySet());
        Iterator it = keys.iterator();
        StringBuffer sb = new StringBuffer();
        int lineLength = 0;
        while (it.hasNext()) {
            Object key = it.next();
            String keyStr = key.toString();
            String value = Values.get(key).toString();
            if (value.length() == 0)
                value = "\'\'";
            sb.append("key = ");
            sb.append(keyStr);
            sb.append(" value = ");
            sb.append(value);
            lineLength += 14 + keyStr.length() + value.length();
            if (lineLength > 80) {
                lineLength = 0;
                sb.append("\n");
            } else {
                sb.append("  ");
            }

        }
        return (sb.toString());
    }

    /**{ method
     @name toString
     @function convert a char to a string
     @param c the char
     @return the String
     }*/
    public static String toString(char c) {
        StringBuffer s = new StringBuffer();
        s.append(c);
        return (s.toString());
    }
}

Related

  1. dumpInputStream(InputStream instream)
  2. dumpInputStream(InputStream is, PrintStream p)
  3. dumpInputStream(InputStream stream)
  4. dumpInputStreamAsString(InputStream is)
  5. dumpInputStreamIntoString(InputStream f, String encoding)
  6. dumpStream(InputStream in, PrintStream dump, boolean closeIn)
  7. dumpStream(InputStream in, String file)
  8. dumpStreamAndReOffer(InputStream is)
  9. dumpStreamToFile(InputStream is, String filename)