Returns a map of all values in a who's value is not a key in b. - Java java.util

Java examples for java.util:Map Entry

Description

Returns a map of all values in a who's value is not a key in b.

Demo Code


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

import java.util.Map;

public class Main {
    /**//  w w  w.  j a  va  2  s . co  m
     * Returns a map of all values in <b>a</b> who's value is not a
     * key in <b>b</b>.
     *
     * @param a The source map of key value pairs used to populate
     * the resulting map.
     *
     * @param b The exclusion map, who's keys are the exclusions
     * matching map <b>a</b>'s values.
     *
     * @return a map of all values in <b>a</b> who's value is not a
     * key in <b>b</b>.
     */
    public static <K, V> Map<K, V> outerJoin(Map<K, V> a, Map<V, ?> b) {
        Map<K, V> buffer = new HashMap<K, V>();

        for (Map.Entry<K, V> entry : a.entrySet()) {
            if (!b.containsKey(entry.getValue())) {
                buffer.put(entry.getKey(), entry.getValue());
            }
        }

        return buffer;
    }
}

Related Tutorials