Refactor previous commit; remove duplications

This commit is contained in:
Zafar Khaja 2012-11-27 22:00:08 +04:00
parent e0bca455ae
commit 7b4e653723

View File

@ -173,40 +173,31 @@ public class Version implements Comparable<Version> {
} }
private int comparePreReleaseVersions(Version other) { private int comparePreReleaseVersions(Version other) {
int result; if (preReleaseVersion == null ^ other.getPreReleaseVersion() == null) {
if (preReleaseVersion == null && return preReleaseVersion == null ? 1 : -1;
other.getPreReleaseVersion() == null) {
result = 0;
} else if (preReleaseVersion == null ||
other.getPreReleaseVersion() == null) {
result = preReleaseVersion == null ? 1 : -1;
} else { } else {
result = compareAlphaNumericVersions( return compareAlphaNumericVersions(
preReleaseVersion, preReleaseVersion,
other.getPreReleaseVersion() other.getPreReleaseVersion()
); );
} }
return result;
} }
private int compareBuildVersions(Version other) { private int compareBuildVersions(Version other) {
int result; if (buildVersion == null ^ other.getBuildVersion() == null) {
if (buildVersion == null && return buildVersion == null ? -1 : 1;
other.getBuildVersion()== null) {
result = 0;
} else if (buildVersion == null ||
other.getBuildVersion()== null) {
result = buildVersion == null ? -1 : 1;
} else { } else {
result = compareAlphaNumericVersions( return compareAlphaNumericVersions(
buildVersion, buildVersion,
other.getBuildVersion() other.getBuildVersion()
); );
} }
return result;
} }
private int compareAlphaNumericVersions(String thisOp, String otherOp) { private int compareAlphaNumericVersions(String thisOp, String otherOp) {
if (thisOp == null && otherOp == null) {
return 0;
}
String[] thisIdents = thisOp.split("\\."); String[] thisIdents = thisOp.split("\\.");
String[] otherIdents = otherOp.split("\\."); String[] otherIdents = otherOp.split("\\.");