org.jvnet.jaxbcommons.lang.util.EqualsUtils Maven / Gradle / Ivy
package org.jvnet.jaxbcommons.lang.util;
import java.util.List;
import java.util.ListIterator;
import org.jvnet.jaxbcommons.lang.EqualsAware;
import org.jvnet.jaxbcommons.lang.VisitedObjects;
public class EqualsUtils {
private EqualsUtils() {
}
public static boolean equals(Object left, Object right, VisitedObjects visitedObjects) {
if (left == right) {
return true;
}
else if (left == null) {
return right == null;
}
else {
if (left instanceof EqualsAware) {
return ((EqualsAware) left).visitEquals(right, visitedObjects);
}
else if (left instanceof List) {
if (!(right instanceof List)) {
return false;
}
else {
final ListIterator e1 = ((List) left).listIterator();
final ListIterator e2 = ((List) right).listIterator();
while (e1.hasNext() && e2.hasNext()) {
final Object o1 = e1.next();
final Object o2 = e2.next();
if (!(o1 == null ? o2 == null :
(o1 instanceof EqualsAware ? ((EqualsAware) o1).visitEquals(o2, visitedObjects) : o1
.equals(o2))))
return false;
}
return !(e1.hasNext() || e2.hasNext());
}
}
else {
return left.equals(right);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy