Java Map Equal MapEquals(Map mapA, Map mapB)

Here you can find the source of MapEquals(Map mapA, Map mapB)

Description

Map Equals

License

Creative Commons License

Declaration

public static <TKey, TValue> boolean MapEquals(Map<TKey, TValue> mapA, Map<TKey, TValue> mapB) 

Method Source Code


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

public class Main {
    public static <TKey, TValue> boolean MapEquals(Map<TKey, TValue> mapA, Map<TKey, TValue> mapB) {
        if (mapA == null) {
            return mapB == null;
        }//from  w  w  w.  j a  v a2 s. co m
        if (mapB == null) {
            return false;
        }
        if (mapA.size() != mapB.size()) {
            return false;
        }
        for (Map.Entry<TKey, TValue> kvp : mapA.entrySet()) {
            TValue valueB = null;
            boolean hasKey;
            valueB = mapB.get(kvp.getKey());
            hasKey = (valueB == null) ? mapB.containsKey(kvp.getKey()) : true;
            if (hasKey) {
                TValue valueA = kvp.getValue();
                if (!(((valueA) == null) ? ((valueB) == null) : (valueA).equals(valueB))) {
                    return false;
                }
            } else {
                return false;
            }
        }
        return true;
    }
}

Related

  1. mapEquals(Map fst, Map snd)
  2. mapEquals(Map map1, Map map2)
  3. mapEquals(Map map1, Map map2)
  4. mapEquals(Map a, Object b)
  5. mapEquals(Map leftMap, Map rightMap)