001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005:
006: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
007: * This code is licensed under the GPL 2.0 license, availible at the root
008: * application directory.
009: */
010: package org.vfny.geoserver.global.dto;
011:
012: import java.util.Iterator;
013: import java.util.List;
014: import java.util.Map;
015:
016: //import com.vividsolutions.jts.geom.*;
017:
018: /**
019: * Utility methods with custom equals implementation against Maps and Lists.
020: *
021: * <p>
022: * Static Library class for testing equality of complex structures independant
023: * of their contents.
024: * </p>
025: *
026: * <p></p>
027: *
028: * @author dzwiers, Refractions Research, Inc.
029: * @version $Id: EqualsLibrary.java 6326 2007-03-15 18:36:40Z jdeolive $
030: */
031: public final class EqualsLibrary {
032: /**
033: * EqualsLibrary constructor.
034: *
035: * <p>
036: * Should never be called, static class.
037: * </p>
038: */
039: private EqualsLibrary() {
040: }
041:
042: /**
043: * equals purpose.
044: *
045: * <p>
046: * Performs a complex equality check between two Lists
047: * </p>
048: *
049: * @param a One List to be compared
050: * @param b The other List to be compared
051: *
052: * @return true if they are equal
053: *
054: * @see java.util.List
055: * @see java.lang.Object#equals(java.lang.Object)
056: */
057: public static boolean equals(List a, List b) {
058: if (a == b) {
059: return true;
060: }
061:
062: if (a == null) {
063: return false;
064: }
065:
066: if (b == null) {
067: return false;
068: }
069:
070: if (a.size() != b.size()) {
071: return false;
072: }
073:
074: Iterator i = a.iterator();
075:
076: while (i.hasNext())
077:
078: if (!b.contains(i.next())) {
079: return false;
080: }
081:
082: return true;
083: }
084:
085: /**
086: * equals purpose.
087: *
088: * <p>
089: * Performs a complex equality check between two Maps
090: * </p>
091: *
092: * @param a One Map to be compared
093: * @param b The other Map to be compared
094: *
095: * @return true if they are equal
096: *
097: * @see java.util.Map
098: * @see java.lang.Object#equals(java.lang.Object)
099: */
100: public static boolean equals(Map a, Map b) {
101: if (a == b) {
102: return true;
103: }
104:
105: if (a == null) {
106: return false;
107: }
108:
109: if (b == null) {
110: return false;
111: }
112:
113: if (a.size() != b.size()) {
114: return false;
115: }
116:
117: Iterator i = a.keySet().iterator();
118:
119: while (i.hasNext()) {
120: Object t = i.next();
121:
122: if (!b.containsKey(t) || !a.get(t).equals(b.get(t))) {
123: return false;
124: }
125: }
126:
127: return true;
128: }
129: }
|