Implement Comparable in Version (#22378)
Supports using streams to calculate min/max of a collection of Versions, etc.
This commit is contained in:
parent
38427c1df0
commit
6ad5486e6b
|
@ -28,8 +28,9 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.monitor.jvm.JvmInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class Version {
|
||||
public class Version implements Comparable<Version> {
|
||||
/*
|
||||
* The logic for ID is: XXYYZZAA, where XX is major version, YY is minor version, ZZ is revision, and AA is alpha/beta/rc indicator AA
|
||||
* values below 25 are for alpha builder (since 5.0), and above 25 and below 50 are beta builds, and below 99 are RC builds, with 99
|
||||
|
@ -310,6 +311,11 @@ public class Version {
|
|||
return version.id >= id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Version other) {
|
||||
return Integer.compare(this.id, other.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum compatible version based on the current
|
||||
* version. Ie a node needs to have at least the return version in order
|
||||
|
|
|
@ -38,7 +38,10 @@ import static org.elasticsearch.Version.V_5_0_0_alpha1;
|
|||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
|
||||
public class VersionTests extends ESTestCase {
|
||||
|
@ -64,6 +67,10 @@ public class VersionTests extends ESTestCase {
|
|||
assertTrue(Version.fromString("5.0.0").onOrAfter(Version.fromString("5.0.0-beta2")));
|
||||
assertTrue(Version.fromString("5.0.0-rc1").onOrAfter(Version.fromString("5.0.0-beta24")));
|
||||
assertTrue(Version.fromString("5.0.0-alpha24").before(Version.fromString("5.0.0-beta0")));
|
||||
|
||||
assertThat(V_2_2_0, is(lessThan(V_5_0_0_alpha1)));
|
||||
assertThat(V_2_2_0.compareTo(V_2_2_0), is(0));
|
||||
assertThat(V_5_0_0_alpha1, is(greaterThan(V_2_2_0)));
|
||||
}
|
||||
|
||||
public void testMin() {
|
||||
|
|
Loading…
Reference in New Issue