Greg Padgett has uploaded a new change for review. Change subject: WIP core: fix businessentity hashCode/equals errors ......................................................................
WIP core: fix businessentity hashCode/equals errors Fix several inconsistencies in businessentity hashCode() and equals() methods, listed below. Hashes could differ for equal objects: permissions, storage_pool, StorageDomain, VDS, VdsDynamic, VdsStatistics Odd semantics in equals: StorageServerConnections, VM (called Object.equals) VmTemplate (did not consider class fields if super.equals(obj)) Suboptimal hashcodes (more entropy in equals than hashCode): QuotaStorage, QuotaVdsGroup, Role, VdsStatic, VmBase Misc: VmDevice (possible NPE, also in toString()) DO NOT MERGE! Ssome of the changes above need closer inspection before merging. Change-Id: Ic83c16ab9bbbb95f45bfcd91920f8137890e63d8 Signed-off-by: Greg Padgett <gpadg...@redhat.com> --- M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/QuotaStorage.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/QuotaVdsGroup.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Role.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/StorageDomain.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/StorageServerConnections.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsDynamic.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatistics.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDevice.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPool.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmTemplate.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/permissions.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage_pool.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ObjectUtils.java M backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ObjectUtilsTest.java 18 files changed, 95 insertions(+), 38 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/39/12539/1 diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/QuotaStorage.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/QuotaStorage.java index 32be7a4..e037777 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/QuotaStorage.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/QuotaStorage.java @@ -140,6 +140,7 @@ result = prime * result + ((quotaId == null) ? 0 : quotaId.hashCode()); result = prime * result + ((quotaStorageId == null) ? 0 : quotaStorageId.hashCode()); result = prime * result + ((storageId == null) ? 0 : storageId.hashCode()); + result = prime * result + ((storageLimitGigaByteUsage == null) ? 0 : storageLimitGigaByteUsage.hashCode()); result = prime * result + ((storageLimitGigaByte == null) ? 0 : storageLimitGigaByte.hashCode()); return result; } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/QuotaVdsGroup.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/QuotaVdsGroup.java index 9f7e96b..eba45fa 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/QuotaVdsGroup.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/QuotaVdsGroup.java @@ -192,7 +192,9 @@ result = prime * result + ((quotaVdsGroupId == null) ? 0 : quotaVdsGroupId.hashCode()); result = prime * result + ((vdsGroupId == null) ? 0 : vdsGroupId.hashCode()); result = prime * result + ((virtualCpu == null) ? 0 : virtualCpu.hashCode()); + result = prime * result + ((virtualCpuUsage == null) ? 0 : virtualCpuUsage.hashCode()); result = prime * result + ((memSizeMB == null) ? 0 : memSizeMB.hashCode()); + result = prime * result + ((memSizeMBUsage == null) ? 0 : memSizeMBUsage.hashCode()); return result; } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Role.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Role.java index e4b9c5f..6e80159 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Role.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Role.java @@ -48,6 +48,7 @@ result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + (readOnly ? 1231 : 1237); + result = prime * result + (allowsViewingChildren ? 1231 : 1237); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode()); return result; diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/StorageDomain.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/StorageDomain.java index 771cdcf..34a0234 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/StorageDomain.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/StorageDomain.java @@ -329,8 +329,11 @@ StorageDomain other = (StorageDomain) obj; return (ObjectUtils.objectsEqual(getId(), other.getId()) && committedDiskSize == other.committedDiskSize + && ObjectUtils.objectsEqual(dynamicData, other.dynamicData) + && ObjectUtils.objectsEqual(staticData, other.staticData) && storageDomainSharedStatus == other.storageDomainSharedStatus && storageDomainOverCommitPercent == other.storageDomainOverCommitPercent + && ObjectUtils.objectsEqual(storagePoolIsoMapData, storagePoolIsoMapData) && ObjectUtils.objectsEqual(totalDiskSize, other.totalDiskSize)); } } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/StorageServerConnections.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/StorageServerConnections.java index 8fbcb26..6c0cda4 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/StorageServerConnections.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/StorageServerConnections.java @@ -2,6 +2,8 @@ import java.io.Serializable; +import org.ovirt.engine.core.common.utils.ObjectUtils; + public class StorageServerConnections implements Serializable { private static final long serialVersionUID = 5444293590307760809L; @@ -182,12 +184,17 @@ @Override public boolean equals(Object obj) { - boolean returnValue = super.equals(obj); - if (!returnValue && obj != null && obj instanceof StorageServerConnections) { - returnValue = - (getid() != null && !getid().isEmpty() && getid().equals(((StorageServerConnections) obj).getid())); + if (this == obj) { + return true; } - return returnValue; + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + StorageServerConnections other = (StorageServerConnections) obj; + return (ObjectUtils.objectsEqual(getid(), other.getid())); } @Override diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java index 9e71493..98ff837 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java @@ -77,6 +77,8 @@ } VDS other = (VDS) obj; return (ObjectUtils.objectsEqual(mVdsStatic, other.mVdsStatic) + && ObjectUtils.objectsEqual(mVdsDynamic, other.mVdsDynamic) + && ObjectUtils.objectsEqual(mVdsStatistics, other.mVdsStatistics) && ObjectUtils.objectsEqual(cpuName, other.cpuName) && _spm_status == other._spm_status && cpuOverCommitDurationMinutes == other.cpuOverCommitDurationMinutes diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java index e769c5b..06889c6 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java @@ -11,6 +11,7 @@ import org.ovirt.engine.core.common.businessentities.Disk.DiskStorageType; import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; +import org.ovirt.engine.core.common.utils.ObjectUtils; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.NGuid; import org.ovirt.engine.core.compat.StringHelper; @@ -1192,6 +1193,14 @@ setUsageMemPercent(vmStatistics.getusage_mem_percent()); } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + return result; + } + /** * Check if two Vms are Equal. Current equality rule is: Two Vms are equal when them points to same object or have * same vm_guid property @@ -1201,19 +1210,17 @@ */ @Override public boolean equals(Object obj) { + if (this == obj) { + return true; + } if (obj == null) { return false; } - if (super.equals(obj)) { - return true; + if (getClass() != obj.getClass()) { + return false; } - VM eq = (VM) ((obj instanceof VM) ? obj : null); - if (eq != null) { - if (eq.getId().equals(this.getId())) { - return true; - } - } - return false; + VM other = (VM) obj; + return (ObjectUtils.objectsEqual(getId(), other.getId())); } public String getVmPoolName() { diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsDynamic.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsDynamic.java index 78229f4..5795a9d 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsDynamic.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsDynamic.java @@ -665,7 +665,7 @@ && ObjectUtils.objectsEqual(physical_mem_mb, other.physical_mem_mb) && previous_status == other.previous_status && ObjectUtils.objectsEqual(reserved_mem, other.reserved_mem) - && ObjectUtils.objectsEqual(getsoftware_version(), other.getsoftware_version()) + && ObjectUtils.objectsEqual(softwareVersion, other.softwareVersion) && ObjectUtils.objectsEqual(spice_version, other.spice_version) && status == other.status && ObjectUtils.objectsEqual(supported_cluster_levels, other.supported_cluster_levels) diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java index b8ecffd..97c2dac 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java @@ -502,6 +502,7 @@ result = prime * result + ((vdsGroupId == null) ? 0 : vdsGroupId.hashCode()); result = prime * result + ((vdsStrength == null) ? 0 : vdsStrength.hashCode()); result = prime * result + ((vdsType == null) ? 0 : vdsType.hashCode()); + result = prime * result + ((sshKeyFingerprint == null) ? 0 : sshKeyFingerprint.hashCode()); return result; } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatistics.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatistics.java index becfcce..845860d 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatistics.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatistics.java @@ -51,10 +51,10 @@ final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((cpu_idle == null) ? 0 : cpu_idle.hashCode()); - result = prime * result + ((cpu_load == null) ? 0 : cpu_load.hashCode()); - result = prime * result + ((cpu_sys == null) ? 0 : cpu_sys.hashCode()); - result = prime * result + ((cpu_user == null) ? 0 : cpu_user.hashCode()); + result = prime * result + ObjectUtils.bigDecimalHash(cpu_idle); + result = prime * result + ObjectUtils.bigDecimalHash(cpu_load); + result = prime * result + ObjectUtils.bigDecimalHash(cpu_sys); + result = prime * result + ObjectUtils.bigDecimalHash(cpu_user); result = prime * result + ((mem_available == null) ? 0 : mem_available.hashCode()); result = prime * result + ((mem_shared == null) ? 0 : mem_shared.hashCode()); result = prime * result + ((usage_cpu_percent == null) ? 0 : usage_cpu_percent.hashCode()); diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java index 62d83ba..856b817 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java @@ -572,6 +572,7 @@ result = prime * result + priority; result = prime * result + (stateless ? 1231 : 1237); result = prime * result + (smartcardEnabled ? 1231 : 1237); + result = prime * result + (deleteProtected ? 1231 : 1237); result = prime * result + ((timeZone == null) ? 0 : timeZone.hashCode()); result = prime * result + ((usbPolicy == null) ? 0 : usbPolicy.hashCode()); result = prime * result + ((vdsGroupId == null) ? 0 : vdsGroupId.hashCode()); diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDevice.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDevice.java index fab167c..648925f 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDevice.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmDevice.java @@ -200,16 +200,16 @@ public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + id.hashCode(); - result = prime * result + device.hashCode(); - result = prime * result + type.hashCode(); - result = prime * result + address.hashCode(); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((device == null) ? 0 : device.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + ((address == null) ? 0 : address.hashCode()); result = prime * result + bootOrder; result = prime * result + ((specParams == null) ? 0 : specParams.hashCode()); result = prime * result + (isManaged ? 1231 : 1237); result = prime * result + (isPlugged ? 1231 : 1237); result = prime * result + (isReadOnly ? 1231 : 1237); - result = prime * result + alias.hashCode(); + result = prime * result + ((alias == null) ? 0 : alias.hashCode()); return result; } @@ -241,9 +241,9 @@ public String toString() { StringBuilder sb = new StringBuilder("VmDevice {"); sb.append("vmId="); - sb.append(id.getVmId()); + sb.append((id == null) ? "null" : id.getVmId()); sb.append(", deviceId="); - sb.append(id.getDeviceId()); + sb.append((id == null) ? "null" : id.getDeviceId()); sb.append(", device="); sb.append(getDevice()); sb.append(", type="); diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPool.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPool.java index c2db042..443ddbe 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPool.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPool.java @@ -60,17 +60,15 @@ final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((defaultEndTime == null) ? 0 : defaultEndTime.hashCode()); - result = prime * result + ((defaultStartTime == null) ? 0 : defaultStartTime.hashCode()); result = prime * result + defaultTimeInDays; result = prime * result + ((parameters == null) ? 0 : parameters.hashCode()); result = prime * result + ((vdsGroupId == null) ? 0 : vdsGroupId.hashCode()); result = prime * result + ((vdsGroupName == null) ? 0 : vdsGroupName.hashCode()); - result = prime * result + vmPoolAssignedCount; result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + vmPoolRunningCount; result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + vmPoolAssignedCount; + result = prime * result + vmPoolRunningCount; return result; } @@ -92,9 +90,12 @@ && defaultTimeInDays == other.defaultTimeInDays && ObjectUtils.objectsEqual(parameters, other.parameters) && ObjectUtils.objectsEqual(vdsGroupId, other.vdsGroupId) + && ObjectUtils.objectsEqual(vdsGroupName, other.vdsGroupName) && ObjectUtils.objectsEqual(description, other.description) && ObjectUtils.objectsEqual(name, other.name) - && ObjectUtils.objectsEqual(type, other.type)); + && ObjectUtils.objectsEqual(type, other.type) + && vmPoolAssignedCount == other.vmPoolAssignedCount + && vmPoolRunningCount == other.vmPoolRunningCount); } private void initializeTimeLeasedDefaultData(String parameter) { diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmTemplate.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmTemplate.java index c9a36c6..000616f 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmTemplate.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmTemplate.java @@ -14,6 +14,7 @@ import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; +import org.ovirt.engine.core.common.utils.ObjectUtils; import org.ovirt.engine.core.common.validation.annotation.ValidI18NName; import org.ovirt.engine.core.common.validation.group.CreateEntity; import org.ovirt.engine.core.common.validation.group.ImportClonedEntity; @@ -207,17 +208,25 @@ @Override public boolean equals(Object obj) { - boolean returnValue = super.equals(obj); - if (!returnValue && obj != null && obj instanceof VmTemplate) { - returnValue = getId() - .equals(((VmTemplate) obj).getId()); + if (this == obj) { + return true; } - return returnValue; + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + VmTemplate other = (VmTemplate) obj; + return (ObjectUtils.objectsEqual(getId(), other.getId())); } @Override public int hashCode() { - return getId().hashCode(); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + return result; } @Override diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/permissions.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/permissions.java index 027abea..f84c649 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/permissions.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/permissions.java @@ -162,8 +162,12 @@ return (ObjectUtils.objectsEqual(id, other.id) && ObjectUtils.objectsEqual(adElementId, other.adElementId) && ObjectUtils.objectsEqual(objectId, other.objectId) + && ObjectUtils.objectsEqual(objectName, other.objectName) && objectType == other.objectType + && ObjectUtils.objectsEqual(ownerName, other.ownerName) && ObjectUtils.objectsEqual(tags, other.tags) + && ObjectUtils.objectsEqual(roleName, other.roleName) + && roleType == other.roleType && ObjectUtils.objectsEqual(roleId, other.roleId)); } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage_pool.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage_pool.java index edd6b37..dfff24e 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage_pool.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage_pool.java @@ -172,7 +172,7 @@ result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((LVER == null) ? 0 : LVER.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode()); - result = prime * result + ((compatibilityVersion == null) ? 0 : compatibilityVersion.hashCode()); + result = prime * result + ((getcompatibility_version() == null) ? 0 : getcompatibility_version().hashCode()); result = prime * result + masterDomainVersion; result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((recovery_mode == null) ? 0 : recovery_mode.hashCode()); diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ObjectUtils.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ObjectUtils.java index 5ccc7ee..bdb9ba3 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ObjectUtils.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ObjectUtils.java @@ -22,4 +22,9 @@ return bd1 == bd2 || bd1 != null && bd2 != null && bd1.compareTo(bd2) == 0; } + public static int bigDecimalHash(BigDecimal bd) { + // Convert to minimal scale for orthogonality with bigDecimalEqual() + return (bd == null) ? 0 : bd.stripTrailingZeros().hashCode(); + } + } diff --git a/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ObjectUtilsTest.java b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ObjectUtilsTest.java index cfff2b7..e4fccb1 100644 --- a/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ObjectUtilsTest.java +++ b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ObjectUtilsTest.java @@ -29,4 +29,17 @@ assertFalse(ObjectUtils.bigDecimalEqual(new BigDecimal("0"), null)); assertFalse(ObjectUtils.bigDecimalEqual(new BigDecimal("1"), new BigDecimal("0"))); } + + @Test + public void testBigDecimalHash() { + assertTrue(ObjectUtils.bigDecimalHash(new BigDecimal("0")) == ObjectUtils.bigDecimalHash(new BigDecimal("0.0"))); + assertTrue(ObjectUtils.bigDecimalHash(new BigDecimal("0.0")) == ObjectUtils.bigDecimalHash(new BigDecimal("0.00"))); + assertTrue(ObjectUtils.bigDecimalHash(new BigDecimal("1")) == ObjectUtils.bigDecimalHash(new BigDecimal("1.0"))); + assertTrue(ObjectUtils.bigDecimalHash(new BigDecimal("0.1")) == ObjectUtils.bigDecimalHash(new BigDecimal("0.1"))); + assertTrue(ObjectUtils.bigDecimalHash(null) == ObjectUtils.bigDecimalHash(null)); + // Hash uniqueness is not guaranteed, but failure warrants closer inspection + assertFalse(ObjectUtils.bigDecimalHash(null) == ObjectUtils.bigDecimalHash(new BigDecimal("0"))); + assertFalse(ObjectUtils.bigDecimalHash(new BigDecimal("0")) == ObjectUtils.bigDecimalHash(null)); + assertFalse(ObjectUtils.bigDecimalHash(new BigDecimal("1")) == ObjectUtils.bigDecimalHash(new BigDecimal("0"))); + } } -- To view, visit http://gerrit.ovirt.org/12539 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic83c16ab9bbbb95f45bfcd91920f8137890e63d8 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Greg Padgett <gpadg...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches