in geode-core/src/main/java/org/apache/geode/pdx/internal/PdxInstanceImpl.java [253:323]
public int hashCode() {
if (cachedHashCode != UNUSED_HASH_CODE) {
// Already computed.
return cachedHashCode;
}
PdxReaderImpl ur = getUnmodifiableReader();
// Compute hash code.
Collection<PdxField> fields = ur.getPdxType().getSortedIdentityFields();
int hashCode = 1;
for (PdxField ft : fields) {
switch (ft.getFieldType()) {
case CHAR:
case BOOLEAN:
case BYTE:
case SHORT:
case INT:
case LONG:
case DATE:
case FLOAT:
case DOUBLE:
case STRING:
case BOOLEAN_ARRAY:
case CHAR_ARRAY:
case BYTE_ARRAY:
case SHORT_ARRAY:
case INT_ARRAY:
case LONG_ARRAY:
case FLOAT_ARRAY:
case DOUBLE_ARRAY:
case STRING_ARRAY:
case ARRAY_OF_BYTE_ARRAYS: {
ByteSource buffer = ur.getRaw(ft);
if (!buffer.equals(ByteSourceFactory.create(ft.getFieldType().getDefaultBytes()))) {
hashCode = hashCode * 31 + buffer.hashCode();
}
break;
}
case OBJECT_ARRAY: {
Object[] oArray = ur.readObjectArray(ft);
if (oArray != null) {
// default value of null does not modify hashCode.
hashCode = hashCode * 31 + Arrays.deepHashCode(oArray);
}
break;
}
case OBJECT: {
Object objectValue = ur.readObject(ft);
if (objectValue == null) {
// default value of null does not modify hashCode.
} else if (objectValue.getClass().isArray()) {
Class<?> myComponentType = objectValue.getClass().getComponentType();
if (myComponentType.isPrimitive()) {
ByteSource buffer = getRaw(ft);
hashCode = hashCode * 31 + buffer.hashCode();
} else {
hashCode = hashCode * 31 + Arrays.deepHashCode((Object[]) objectValue);
}
} else {
hashCode = hashCode * 31 + objectValue.hashCode();
}
break;
}
default:
throw new InternalGemFireException("Unhandled field type " + ft.getFieldType());
}
}
int result = (hashCode == UNUSED_HASH_CODE) ? (hashCode + 1) : hashCode;
cachedHashCode = result;
return result;
}