Java Map Equal mapEquals(Map map1, Map map2)

Here you can find the source of mapEquals(Map map1, Map map2)

Description

map Equals

License

Apache License

Declaration

public static boolean mapEquals(Map<?, ?> map1, Map<?, ?> map2) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    public static boolean mapEquals(Map<?, ?> map1, Map<?, ?> map2) {
        if (map1 == null && map2 == null) {
            return true;
        }//from w  ww .  j a v  a 2  s .  c  o  m
        if (map1 == null || map2 == null) {
            return false;
        }
        if (map1.size() != map2.size()) {
            return false;
        }
        for (Map.Entry<?, ?> entry : map1.entrySet()) {
            Object key = entry.getKey();
            Object value1 = entry.getValue();
            Object value2 = map2.get(key);
            if (!objectEquals(value1, value2)) {
                return false;
            }
        }
        return true;
    }

    private static boolean objectEquals(Object obj1, Object obj2) {
        if (obj1 == null && obj2 == null) {
            return true;
        }
        if (obj1 == null || obj2 == null) {
            return false;
        }
        return obj1.equals(obj2);
    }
}

Related

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