diff options
author | Julien Eluard <[email protected]> | 2012-02-02 13:05:21 -0300 |
---|---|---|
committer | Julien Eluard <[email protected]> | 2012-02-02 13:05:21 -0300 |
commit | e70897957143a0044a410b90542cf67dc5091068 (patch) | |
tree | f18311412e18900a6507c7c3c26952b52511cac3 /api | |
parent | af2c9184a69ad2b3e1de9a41d5d00edda3c65f69 (diff) |
Fixed wrong compareTo order.
Diffstat (limited to 'api')
-rwxr-xr-x | api/src/main/java/org/semver/Delta.java | 4 | ||||
-rwxr-xr-x | api/src/main/java/org/semver/Version.java | 27 | ||||
-rwxr-xr-x | api/src/test/java/org/semver/DeltaTest.java | 2 | ||||
-rwxr-xr-x | api/src/test/java/org/semver/VersionTest.java | 18 |
4 files changed, 28 insertions, 23 deletions
diff --git a/api/src/main/java/org/semver/Delta.java b/api/src/main/java/org/semver/Delta.java index e856bb2..ebb6b57 100755 --- a/api/src/main/java/org/semver/Delta.java +++ b/api/src/main/java/org/semver/Delta.java @@ -213,7 +213,7 @@ public final class Delta { if (current == null) { throw new IllegalArgumentException("null current"); } - if (previous.compareTo(current) <= 0) { + if (current.compareTo(previous) <= 0) { throw new IllegalArgumentException("Current version <"+previous+"> must be more recent than previous version <"+current+">."); } //When in development public API is not considered stable @@ -223,7 +223,7 @@ public final class Delta { //Current version must be superior or equals to inferred version final Version inferredVersion = infer(previous); - return inferredVersion.compareTo(current) >= 0; + return current.compareTo(inferredVersion) >= 0; } } diff --git a/api/src/main/java/org/semver/Version.java b/api/src/main/java/org/semver/Version.java index b4c76ee..e6c9abf 100755 --- a/api/src/main/java/org/semver/Version.java +++ b/api/src/main/java/org/semver/Version.java @@ -24,6 +24,7 @@ import javax.annotation.Nonnegative; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; + import org.apache.commons.lang.StringUtils; /** @@ -159,20 +160,24 @@ public final class Version implements Comparable<Version> { return 0; } - if (other.major > this.major) { - return 1; - } else if (other.major == this.major) { - if (other.minor > this.minor) { - return 1; - } else if (other.minor == this.minor) { - if (other.patch > this.patch) { - return 1; + if (this.major < other.major) { + return -1; + } else if (this.major == other.major) { + if (this.minor < other.minor) { + return -1; + } else if (this.minor == other.minor) { + if (this.patch < other.patch) { + return -1; + } else if (this.special != null && other.special != null) { + return this.special.compareTo(other.special); } else if (other.special != null) { - return other.special.compareTo(this.special); - } + return -1; + } else if (this.special != null) { + return 1; + } // else handled by previous equals check } } - return -1; + return 1; } @Override diff --git a/api/src/test/java/org/semver/DeltaTest.java b/api/src/test/java/org/semver/DeltaTest.java index 5e292ec..f01ddff 100755 --- a/api/src/test/java/org/semver/DeltaTest.java +++ b/api/src/test/java/org/semver/DeltaTest.java @@ -144,4 +144,4 @@ public class DeltaTest { Assert.assertFalse(new Delta(Collections.singleton(new Delta.Remove("class", new FieldInfo(0, "", "", "", null)))).validate(new Version(1, 1, 0), new Version(1, 1, 1))); } -} +}
\ No newline at end of file diff --git a/api/src/test/java/org/semver/VersionTest.java b/api/src/test/java/org/semver/VersionTest.java index a7aa0e4..ab32892 100755 --- a/api/src/test/java/org/semver/VersionTest.java +++ b/api/src/test/java/org/semver/VersionTest.java @@ -100,15 +100,15 @@ public class VersionTest { @Test public void isNewer() { - Assert.assertTrue(Version.parse("1.0.0").compareTo(Version.parse("0.0.0")) < 0); - Assert.assertTrue(Version.parse("0.0.0").compareTo(Version.parse("1.0.0")) > 0); - Assert.assertTrue(Version.parse("1.1.0").compareTo(Version.parse("1.0.0")) < 0); - Assert.assertTrue(Version.parse("1.0.0").compareTo(Version.parse("1.1.0")) > 0); - Assert.assertTrue(Version.parse("1.0.1").compareTo(Version.parse("1.0.0")) < 0); - Assert.assertTrue(Version.parse("1.0.0").compareTo(Version.parse("1.0.1")) > 0); - Assert.assertTrue(Version.parse("1.0.0Beta").compareTo(Version.parse("1.0.0Alpha")) < 0); - Assert.assertFalse(Version.parse("0.0.0").compareTo(Version.parse("0.0.0")) < 0); - Assert.assertFalse(Version.parse("0.0.0").compareTo(Version.parse("0.0.1")) < 0); + Assert.assertTrue(Version.parse("1.0.0").compareTo(Version.parse("0.0.0")) > 0); + Assert.assertTrue(Version.parse("0.0.0").compareTo(Version.parse("1.0.0")) < 0); + Assert.assertTrue(Version.parse("1.1.0").compareTo(Version.parse("1.0.0")) > 0); + Assert.assertTrue(Version.parse("1.0.0").compareTo(Version.parse("1.1.0")) < 0); + Assert.assertTrue(Version.parse("1.0.1").compareTo(Version.parse("1.0.0")) > 0); + Assert.assertTrue(Version.parse("1.0.0").compareTo(Version.parse("1.0.1")) < 0); + Assert.assertTrue(Version.parse("1.0.0Beta").compareTo(Version.parse("1.0.0Alpha")) > 0); + Assert.assertFalse(Version.parse("0.0.0").compareTo(Version.parse("0.0.0")) > 0); + Assert.assertFalse(Version.parse("0.0.0").compareTo(Version.parse("0.0.1")) > 0); } @Test |