@Override public int hashCode() { HashCodeBuilder builder = new HashCodeBuilder(); boolean pathPresent = path != null; builder.append(pathPresent); if (pathPresent) { builder.append(path.toCharArray()); } boolean lockObjectPresent = obj != null; builder.append(lockObjectPresent); if (lockObjectPresent) { builder.append(obj.hashCode()); } boolean modePresent = mode != null; builder.append(modePresent); if (modePresent) { builder.append(mode); } return builder.toHashCode(); } }
@Override public int hashCode() { HashCodeBuilder builder = new HashCodeBuilder(); boolean pathPresent = path != null; builder.append(pathPresent); if (pathPresent) { builder.append(path.toCharArray()); } boolean lockObjectPresent = obj != null; builder.append(lockObjectPresent); if (lockObjectPresent) { builder.append(obj.hashCode()); } boolean modePresent = mode != null; builder.append(modePresent); if (modePresent) { builder.append(mode); } return builder.toHashCode(); } }
@Test public void testEqualsAndHashCode() { HiveLockObjectData data1 = new HiveLockObjectData("ID1", "SHARED", "1997-07-01", "select * from mytable", conf); HiveLockObjectData data2 = new HiveLockObjectData("ID1", "SHARED", "1997-07-01", "select * from mytable", conf); Assert.assertEquals(data1, data2); Assert.assertEquals(data1.hashCode(), data2.hashCode()); HiveLockObject obj1 = new HiveLockObject("mytable", data1); HiveLockObject obj2 = new HiveLockObject("mytable", data2); Assert.assertEquals(obj1, obj2); Assert.assertEquals(obj1.hashCode(), obj2.hashCode()); }