org.jvnet.jaxbcommons.lang.util.HashCodeUtils Maven / Gradle / Ivy
package org.jvnet.jaxbcommons.lang.util;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import org.jvnet.jaxbcommons.lang.EqualsAware;
import org.jvnet.jaxbcommons.lang.HashCodeAware;
import org.jvnet.jaxbcommons.lang.VisitedObjects;
public class HashCodeUtils {
private HashCodeUtils() {
}
public static int hashCode(Object object, VisitedObjects visitedObjects) {
if (object == null) {
return 0;
}
else {
if (object instanceof HashCodeAware) {
return ((HashCodeAware) object).visitHashCode(visitedObjects);
}
else if (object instanceof List) {
int hashCode = 1;
final Iterator i = ((List) object).iterator();
while (i.hasNext()) {
Object obj = i.next();
hashCode = 31
* hashCode
+ (obj == null ? 0 : ((obj instanceof HashCodeAware) ? ((HashCodeAware) obj)
.visitHashCode(visitedObjects) : obj.hashCode()));
}
return hashCode;
}
else {
return object.hashCode();
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy