Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010-2014 SAP AG and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     SAP AG - initial API and implementation
 *******************************************************************************/

import java.util.Arrays;

import java.util.HashMap;

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

public class Main {
    /**
     * Returns a new <code>Map</code> instance which contains the given <code>sourceMap<code>
     * and <code>members<code> values.
     *
     * @param sourceMap  map from which to copy entries into the result.
     * @param members  additional entries to add.
     */
    public static Map<String, String> addAll(Map<String, String> sourceMap, String[][] members) {
        Map<String, String> result = new HashMap<String, String>(sourceMap);
        result.putAll(asMap(members));
        return result;
    }

    public static Map<String, String> asMap(String[][] args) {
        HashMap<String, String> result = new HashMap<String, String>();
        if (args != null) {
            for (int i = 0; i < args.length; ++i) {
                String key = args[i][0];
                String value = args[i][1];
                result.put(key, value);
            }
        }
        return result;
    }

    public static <K, V> Map<K, V> asMap(K key, V value) {
        HashMap<K, V> result = new HashMap<K, V>(1);
        result.put(key, value);
        return result;
    }

    public static Map<String, List<String>> asMap(String key, String... args) {
        HashMap<String, List<String>> result = new HashMap<String, List<String>>();
        if (args != null) {
            result.put(key, Arrays.asList(args));
        }
        return result;
    }
}