mirror of https://github.com/apache/lucene.git
LUCENE-5850: Add missing hashCode implementation to Version.java
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1618621 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
aca7364bba
commit
2e6c8e7bd8
|
@ -349,4 +349,9 @@ public final class Version {
|
|||
public boolean equals(Object o) {
|
||||
return o != null && o instanceof Version && ((Version)o).encodedValue == encodedValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return encodedValue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.lucene.util;
|
|||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Random;
|
||||
|
||||
public class TestVersion extends LuceneTestCase {
|
||||
|
||||
|
@ -186,4 +187,23 @@ public class TestVersion extends LuceneTestCase {
|
|||
assertEquals("Version.LATEST does not match the one given in common-build.xml",
|
||||
Version.LATEST.toString(), commonBuildVersion);
|
||||
}
|
||||
|
||||
public void testEqualsHashCode() {
|
||||
Random random = random();
|
||||
String version = "" + (4 + random.nextInt(1)) + "." + random.nextInt(10) + "." + random.nextInt(10);
|
||||
Version v1 = Version.parseLeniently(version);
|
||||
Version v2 = Version.parseLeniently(version);
|
||||
assertEquals(v1.hashCode(), v2.hashCode());
|
||||
assertEquals(v1, v2);
|
||||
final int iters = 10 + random.nextInt(20);
|
||||
for (int i = 0; i < iters; i++) {
|
||||
String v = "" + (4 + random.nextInt(1)) + "." + random.nextInt(10) + "." + random.nextInt(10);
|
||||
if (v.equals(version)) {
|
||||
assertEquals(Version.parseLeniently(v).hashCode(), v1.hashCode());
|
||||
assertEquals(Version.parseLeniently(v), v1);
|
||||
} else {
|
||||
assertFalse(Version.parseLeniently(v).equals(v1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue