Gets a Map having a null value for each of the keys provided in keySet . - Java Collection Framework

Java examples for Collection Framework:Map

Description

Gets a Map having a null value for each of the keys provided in keySet .

Demo Code

/*// w ww. java2  s  .  co  m
 * Copyright Terracotta, 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.
 */
//package com.java2s;
import java.util.ArrayList;

import java.util.Collections;

import java.util.LinkedHashMap;

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

public class Main {
    /**
     * Gets a {@code Map} having a {@code null} value for each of the keys provided in {@code keySet}.
     *
     * @param keySet the {@code Iterable} over the keys for the result {@code Map}
     *
     * @return a new, insert-ordered, modifiable {@code Map} holding {@code null} values for each key provided
     */
    static Map<String, String> getNullEntryMap(final Iterable<String> keySet) {
        return getNullEntryMap(Collections.singletonList(keySet));
    }

    /**
     * Gets a {@code Map} having a {@code null} value for each of the keys provided all identified keySets.
     *
     * @param keySet1 the first {@code Iterable} over the keys for the result {@code Map}
     * @param keySet2 the second {@code Iterable} over the keys for the result {@code Map}
     *
     * @return a new, insert-ordered, modifiable {@code Map} holding {@code null} values for each key provided
     */
    static Map<String, String> getNullEntryMap(
            final Iterable<String> keySet1, final Iterable<String> keySet2) {
        final List<Iterable<String>> keySets = new ArrayList<Iterable<String>>(
                2);
        keySets.add(keySet1);
        keySets.add(keySet2);
        return getNullEntryMap(keySets);
    }

    /**
     * Gets a {@code Map} having a {@code null} value for each of the keys provided in {@code keySets}.
     *
     * @param keySets the {@code Iterable}s over the keys for the result {@code Map}
     *
     * @return a new, insert-ordered, modifiable {@code Map} holding {@code null} values for each key provided
     */
    private static Map<String, String> getNullEntryMap(
            final List<Iterable<String>> keySets) {
        final Map<String, String> entryMap = new LinkedHashMap<String, String>();
        for (final Iterable<String> keySet : keySets) {
            for (final String key : keySet) {
                entryMap.put(key, null);
            }
        }
        return entryMap;
    }
}

Related Tutorials