Java Map Print printMap(Map map, int depth)

Here you can find the source of printMap(Map map, int depth)

Description

Prints the map.

License

Apache License

Parameter

Parameter Description
map the map
depth the depth

Declaration

@SuppressWarnings("unchecked")
public static void printMap(Map<String, Object> map, int depth) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w . j a va  2s .c  o m*/
 * Copyright 2017 Walmart, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

import java.util.Map;

public class Main {
    /**
     * Prints the map.
     *
     * @param map the map
     * @param depth the depth
     */
    @SuppressWarnings("unchecked")
    public static void printMap(Map<String, Object> map, int depth) {
        String log = "Parent";
        if (depth > 0) {
            log = "Children";
        }
        StringBuilder str = new StringBuilder();
        int loop = depth;
        while (loop > 0) {
            str.append('\t');
            loop--;
        }
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            System.out.printf("%s %s: key: %s; value:%s: %n",
                    str.toString(), log, key,
                    value == null ? "" : value.getClass());
            if (value instanceof Map) {
                printMap((Map<String, Object>) value, ++depth);
            }

        }
    }
}

Related

  1. printMap(Map map)
  2. printMap(Map map)
  3. printMap(Map map)
  4. printMap(Map map)
  5. printMap(Map map)
  6. printMap(String mapLabel, Map map)
  7. printMapGeneral(Map map)
  8. printMapObject(Map mapobject)
  9. printMapStrings(Map> map, String mapDescription)