Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.ArrayList;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {
    public static Map<String, List<String>> joinAll(final Map<String, Map<String, String>> map,
            final String separator) {
        if (map == null) {
            return null;
        }
        final Map<String, List<String>> result = new HashMap<String, List<String>>();
        for (final Map.Entry<String, Map<String, String>> entry : map.entrySet()) {
            result.put(entry.getKey(), join(entry.getValue(), separator));
        }
        return result;
    }

    public static List<String> join(final Map<String, String> map, final String separator) {
        if (map == null) {
            return null;
        }
        final List<String> list = new ArrayList<String>();
        if (map == null || map.size() == 0) {
            return list;
        }
        for (final Map.Entry<String, String> entry : map.entrySet()) {
            final String key = entry.getKey();
            final String value = entry.getValue();
            if (value == null || value.length() == 0) {
                list.add(key);
            } else {
                list.add(key + separator + value);
            }
        }
        return list;
    }
}