Bug 572429: [RService] Adapt RVersion to extend common Version
Change-Id: I1b1fd0a2b23ed5f449a365d1c85b3130ede5d54c
diff --git a/core/org.eclipse.statet.rj.services.core/META-INF/MANIFEST.MF b/core/org.eclipse.statet.rj.services.core/META-INF/MANIFEST.MF
index 69efe64..054f26c 100644
--- a/core/org.eclipse.statet.rj.services.core/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.statet.rj.services.core/META-INF/MANIFEST.MF
@@ -14,7 +14,8 @@
org.eclipse.statet.jcommons.lang;version="4.4.0",
org.eclipse.statet.jcommons.runtime;version="4.4.0",
org.eclipse.statet.jcommons.status;version="4.4.0",
- org.eclipse.statet.jcommons.ts.core;version="4.4.0";resolution:=optional
+ org.eclipse.statet.jcommons.ts.core;version="4.4.0";resolution:=optional,
+ org.eclipse.statet.jcommons.util;version="4.4.0"
Export-Package: org.eclipse.statet.rj.graphic.core;version="4.4.0",
org.eclipse.statet.rj.graphic.core.util;version="4.4.0",
org.eclipse.statet.rj.renv.core;version="4.4.0",
diff --git a/core/org.eclipse.statet.rj.services.core/src/org/eclipse/statet/rj/services/RVersion.java b/core/org.eclipse.statet.rj.services.core/src/org/eclipse/statet/rj/services/RVersion.java
index df32c37..c1a30b2 100644
--- a/core/org.eclipse.statet.rj.services.core/src/org/eclipse/statet/rj/services/RVersion.java
+++ b/core/org.eclipse.statet.rj.services.core/src/org/eclipse/statet/rj/services/RVersion.java
@@ -16,174 +16,25 @@
import org.eclipse.statet.jcommons.lang.NonNullByDefault;
import org.eclipse.statet.jcommons.lang.Nullable;
-import org.eclipse.statet.jcommons.lang.ObjectUtils;
+import org.eclipse.statet.jcommons.util.Version;
@NonNullByDefault
-public class RVersion implements Comparable<RVersion> {
-
- private static int parseInt(final String value, final String componentName) {
- try {
- return Integer.parseInt(value);
- }
- catch (final NumberFormatException e) {
- throw new IllegalArgumentException(componentName + "= '" + value + "'", e);
- }
- }
-
- private static void validateInt(final int value, final String componentName) {
- if (value < 0) {
- throw new IllegalArgumentException(componentName + "= " + value);
- }
- }
-
-
- private final int major;
- private final int minor;
- private final int patch;
- private final String build;
-
- private transient @Nullable String versionString;
- private transient int hash;
+public class RVersion extends Version {
public RVersion(final int major, final int minor, final int micro,
final @Nullable String qualifier) {
- this.major= major;
- this.minor= minor;
- this.patch= micro;
- this.build= ObjectUtils.nonNullElse(qualifier, ""); //$NON-NLS-1$
- validate();
+ super(major, minor, micro, qualifier);
}
- public RVersion(final int major, final int minor, final int path) {
- this(major, minor, path, null);
+ public RVersion(final int major, final int minor, final int micro) {
+ super(major, minor, micro);
}
public RVersion(final String version) {
- int major= 0;
- int minor= 0;
- int patch= 0;
- String build= "";
- { final String[] components= version.split("\\.", 4);
- if (components.length == 0 || components[0].isEmpty()) {
- throw new IllegalArgumentException("version= '" + version + "'");
- }
- major= parseInt(components[0], "major");
- if (components.length >= 2) {
- minor= parseInt(components[1], "minor");
- if (components.length >= 3) {
- patch= parseInt(components[2], "patch");
- if (components.length >= 4) {
- build= components[3];
- }
- }
- }
- }
-
- this.major= major;
- this.minor= minor;
- this.patch= patch;
- this.build= build;
- validate();
+ super(version);
}
- private void validate() {
- validateInt(this.major, "major");
- validateInt(this.minor, "minor");
- validateInt(this.patch, "patch");
- for (int i= 0; i < this.build.length(); i++) {
- final char c= this.build.charAt(i);
- if (!Character.isDefined(c) || c == ' ') {
- throw new IllegalArgumentException("build= " + this.build);
- }
- }
- }
-
-
- public int getMajor() {
- return this.major;
- }
-
- public int getMinor() {
- return this.minor;
- }
-
- public int getMicro() {
- return this.patch;
- }
-
- public String getBuild() {
- return this.build;
- }
-
-
- @Override
- public int hashCode() {
- int h= this.hash;
- if (h != 0) {
- return h;
- }
- h= 31 * 17;
- h= 31 * h + this.major;
- h= 31 * h + this.minor;
- h= 31 * h + this.patch;
- h= 31 * h + this.build.hashCode();
- return this.hash= h;
- }
-
- @Override
- public boolean equals(final @Nullable Object object) {
- if (this == object) {
- return true;
- }
- if (object instanceof RVersion) {
- final RVersion other= (RVersion) object;
- return ((this.major == other.major)
- && (this.minor == other.minor)
- && (this.patch == other.patch)
- && this.build.equals(other.build) );
- }
- return false;
- }
-
- @Override
- public int compareTo(final RVersion other) {
- if (this == other) {
- return 0;
- }
- int result= this.major - other.major;
- if (result != 0) {
- return result;
- }
- result= this.minor - other.minor;
- if (result != 0) {
- return result;
- }
- result= this.patch - other.patch;
- if (result != 0) {
- return result;
- }
- return this.build.compareTo(other.build);
- }
-
- @Override
- public String toString() {
- final String s= this.versionString;
- if (s != null) {
- return s;
- }
- final StringBuilder result= new StringBuilder(20 + this.build.length());
- result.append(this.major);
- result.append('.');
- result.append(this.minor);
- result.append('.');
- result.append(this.patch);
- if (!this.build.isEmpty()) {
- result.append('.');
- result.append(this.build);
- }
- return this.versionString= result.toString();
- }
}