⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 equalslibrary.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
字号:
/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org.  All rights reserved.
 * This code is licensed under the GPL 2.0 license, availible at the root
 * application directory.
 */

/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org.  All rights reserved.
 * This code is licensed under the GPL 2.0 license, availible at the root
 * application directory.
 */
package org.vfny.geoserver.global.dto;

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


//import com.vividsolutions.jts.geom.*;

/**
 * Utility methods with custom equals implementation against Maps and Lists.
 *
 * <p>
 * Static Library class for testing equality of complex structures independant
 * of their contents.
 * </p>
 *
 * <p></p>
 *
 * @author dzwiers, Refractions Research, Inc.
 * @version $Id: EqualsLibrary.java 6326 2007-03-15 18:36:40Z jdeolive $
 */
public final class EqualsLibrary {
    /**
     * EqualsLibrary constructor.
     *
     * <p>
     * Should never be called, static class.
     * </p>
     */
    private EqualsLibrary() {
    }

    /**
     * equals purpose.
     *
     * <p>
     * Performs a complex equality check between two Lists
     * </p>
     *
     * @param a One List to be compared
     * @param b The other List to be compared
     *
     * @return true if they are equal
     *
     * @see java.util.List
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public static boolean equals(List a, List b) {
        if (a == b) {
            return true;
        }

        if (a == null) {
            return false;
        }

        if (b == null) {
            return false;
        }

        if (a.size() != b.size()) {
            return false;
        }

        Iterator i = a.iterator();

        while (i.hasNext())

            if (!b.contains(i.next())) {
                return false;
            }

        return true;
    }

    /**
     * equals purpose.
     *
     * <p>
     * Performs a complex equality check between two Maps
     * </p>
     *
     * @param a One Map to be compared
     * @param b The other Map to be compared
     *
     * @return true if they are equal
     *
     * @see java.util.Map
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public static boolean equals(Map a, Map b) {
        if (a == b) {
            return true;
        }

        if (a == null) {
            return false;
        }

        if (b == null) {
            return false;
        }

        if (a.size() != b.size()) {
            return false;
        }

        Iterator i = a.keySet().iterator();

        while (i.hasNext()) {
            Object t = i.next();

            if (!b.containsKey(t) || !a.get(t).equals(b.get(t))) {
                return false;
            }
        }

        return true;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -