-
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
242 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/version/Version.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.python.pydev.shared_core.version; | ||
|
||
import java.util.StringTokenizer; | ||
|
||
public class Version implements Comparable<Version> { | ||
private int major; | ||
private int minor; | ||
private int patch; | ||
|
||
public Version(String versionString) { | ||
StringTokenizer tokenizer = new StringTokenizer(versionString, "."); | ||
if (tokenizer.hasMoreTokens()) { | ||
major = Integer.parseInt(tokenizer.nextToken()); | ||
} | ||
if (tokenizer.hasMoreTokens()) { | ||
minor = Integer.parseInt(tokenizer.nextToken()); | ||
} | ||
if (tokenizer.hasMoreTokens()) { | ||
patch = Integer.parseInt(tokenizer.nextToken()); | ||
} | ||
} | ||
|
||
@Override | ||
public int compareTo(Version other) { | ||
if (this.major != other.major) { | ||
return Integer.compare(this.major, other.major); | ||
} | ||
if (this.minor != other.minor) { | ||
return Integer.compare(this.minor, other.minor); | ||
} | ||
return Integer.compare(this.patch, other.patch); | ||
} | ||
|
||
public boolean isGreaterThanOrEqualTo(Version other) { | ||
return compareTo(other) >= 0; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return major + "." + minor + "." + patch; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
.../org.python.pydev.shared_core/tests/org/python/pydev/shared_core/version/VersionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.python.pydev.shared_core.version; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class VersionTest extends TestCase { | ||
|
||
public void testVersionComparison() { | ||
Version v1 = new Version("1.2"); | ||
Version v2 = new Version("1.2.1"); | ||
Version v3 = new Version("1.2.2"); | ||
Version v4 = new Version("1.3"); | ||
|
||
Version v5 = new Version("2.0"); | ||
Version v6 = new Version("2.0.0"); | ||
|
||
assertTrue(v1.isGreaterThanOrEqualTo(v1)); | ||
assertTrue(v5.isGreaterThanOrEqualTo(v6)); | ||
assertTrue(v5.isGreaterThanOrEqualTo(v4)); | ||
|
||
assertFalse(v1.isGreaterThanOrEqualTo(v2)); | ||
assertFalse(v2.isGreaterThanOrEqualTo(v3)); | ||
assertFalse(v3.isGreaterThanOrEqualTo(v4)); | ||
assertFalse(v4.isGreaterThanOrEqualTo(v5)); | ||
} | ||
|
||
public static void main(String[] args) { | ||
junit.textui.TestRunner.run(VersionTest.class); | ||
} | ||
} |
Oops, something went wrong.