org.vfny.geoserver.global.dto.EqualsLibrary Maven / Gradle / Ivy
/* 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.
*
*
* Static Library class for testing equality of complex structures independant
* of their contents.
*
*
*
*
* @author dzwiers, Refractions Research, Inc.
* @version $Id: EqualsLibrary.java 6326 2007-03-15 18:36:40Z jdeolive $
*/
public final class EqualsLibrary {
/**
* EqualsLibrary constructor.
*
*
* Should never be called, static class.
*
*/
private EqualsLibrary() {
}
/**
* equals purpose.
*
*
* Performs a complex equality check between two Lists
*
*
* @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.
*
*
* Performs a complex equality check between two Maps
*
*
* @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;
}
}