All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.box.boxjavalibv2.dao.BoxHashMap Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
package com.box.boxjavalibv2.dao;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;

public class BoxHashMap extends HashMap {

    private static final long serialVersionUID = 1L;

    @SuppressWarnings("unchecked")
    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }

        if (!(obj instanceof HashMap)) {
            return false;
        }

        HashMap mapObj = (HashMap) obj;

        if (mapObj.size() != this.size()) {
            return false;
        }

        try {
            Iterator> i = mapObj.entrySet().iterator();
            while (i.hasNext()) {
                Entry e = i.next();
                Object key = e.getKey();
                Object value = e.getValue();
                if (value == null) {
                    if (!(get(key) == null && containsKey(key))) {
                        return false;
                    }
                }
                else {
                    if (value instanceof Object[]) {
                        if (!Arrays.equals((Object[]) value, (Object[]) (get(key)))) {
                            return false;
                        }
                    }
                    else if (!value.equals(get(key))) {
                        return false;
                    }

                }

            }
        }
        catch (ClassCastException e) {
            return false;
        }
        catch (NullPointerException e) {
            return false;
        }
        return true;

    }

    @Override
    public int hashCode() {
        int hashCode = 0;
        Iterator> i = entrySet().iterator();
        while (i.hasNext()) {
            Entry entry = i.next();
            // ignore primitive arrays in our calculation of hashCode.
            if (!(entry.getValue() instanceof Object[])) {
                hashCode += entry.hashCode();
            }
        }
        return hashCode;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy