diff --git a/README.md b/README.md
index 3cc9e74..c10f032 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@ Pure Java (java.util), no dependencies, very small method count.
**Gradle:**
```
dependencies {
- implementation 'com.g00fy2:versioncompare:1.3.4'
+ implementation 'com.g00fy2:versioncompare:1.3.5'
}
```
**Maven:**
@@ -20,7 +20,7 @@ dependencies {
com.g00fy2
versioncompare
- 1.3.4
+ 1.3.5
```
@@ -89,7 +89,7 @@ suffix compare logic ||
## Sample App
![Image](https://raw.githubusercontent.com/G00fY2/version-compare/gh-pages/images/version_compare_sampleapp_framed.png)
-**Try out the sample app to compare your version inputs: [Download APK](https://github.com/G00fY2/version-compare/releases/download/1.3.4/version-compare-1.3.4-sample.apk)**
+**Try out the sample app to compare your version inputs: [Download APK](https://github.com/G00fY2/version-compare/releases/download/1.3.5/version-compare-1.3.5-sample.apk)**
## License
Copyright (C) 2018 Thomas Wirth
diff --git a/build.gradle b/build.gradle
index 9d4ae7f..0548cf5 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,14 +4,15 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.5.3'
- classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
+ classpath 'com.android.tools.build:gradle:4.0.2'
+ classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
}
}
allprojects {
repositories {
google()
+ mavenCentral()
jcenter()
}
}
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index cc4fdc2..e708b1c 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 0ebb310..33682bb 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
index 2fe81a7..4f906e0 100755
--- a/gradlew
+++ b/gradlew
@@ -82,6 +82,7 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
diff --git a/gradlew.bat b/gradlew.bat
index 9618d8d..107acd3 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@@ -37,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
+if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -51,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-if exist "%JAVA_EXE%" goto init
+if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@@ -61,28 +64,14 @@ echo location of your Java installation.
goto fail
-:init
-@rem Get command-line arguments, handling Windows variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
diff --git a/sample/build.gradle b/sample/build.gradle
index 85870fb..7477dc8 100644
--- a/sample/build.gradle
+++ b/sample/build.gradle
@@ -3,11 +3,11 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
- compileSdkVersion 29
+ compileSdkVersion 30
defaultConfig {
applicationId 'com.g00fy2.versioncomparesample'
minSdkVersion 14
- targetSdkVersion 29
+ targetSdkVersion 30
versionCode 1
versionName '1.0'
}
@@ -30,7 +30,7 @@ dependencies {
}
buildscript {
- ext.kotlin_version = '1.3.61'
+ ext.kotlin_version = '1.4.10'
repositories {
mavenCentral()
}
diff --git a/versioncompare/build.gradle b/versioncompare/build.gradle
index f22c140..769ee1b 100644
--- a/versioncompare/build.gradle
+++ b/versioncompare/build.gradle
@@ -4,7 +4,8 @@ apply plugin: 'jacoco'
dependencies {
compileOnly 'com.google.code.findbugs:jsr305:3.0.2' // only required at compile time
- testImplementation 'junit:junit:4.12'
+ testImplementation 'junit:junit:4.13'
+ testImplementation 'nl.jqno.equalsverifier:equalsverifier:3.4.3'
}
jacoco {
diff --git a/versioncompare/deploy.gradle b/versioncompare/deploy.gradle
index 1c5cded..4419cdc 100644
--- a/versioncompare/deploy.gradle
+++ b/versioncompare/deploy.gradle
@@ -11,7 +11,7 @@ ext {
issueUrl = 'https://github.com/G00fY2/version-compare/issues'
gitUrl = 'https://github.com/G00fY2/version-compare.git'
- libraryVersion = '1.3.4'
+ libraryVersion = '1.3.5'
developerId = 'g00fy2'
developerName = 'Thomas Wirth'
diff --git a/versioncompare/src/main/java/com/g00fy2/versioncompare/Version.java b/versioncompare/src/main/java/com/g00fy2/versioncompare/Version.java
index 28d8a2b..ef0f525 100644
--- a/versioncompare/src/main/java/com/g00fy2/versioncompare/Version.java
+++ b/versioncompare/src/main/java/com/g00fy2/versioncompare/Version.java
@@ -10,6 +10,7 @@ public class Version implements Comparable {
@Nullable private final String originalString;
@Nonnull private final List subversionNumbers = new ArrayList<>();
+ @Nonnull private final List subversionNumbersWithoutTrailingZeros = new ArrayList<>();
@Nonnull private String suffix = "";
/**
@@ -122,8 +123,9 @@ public boolean isHigherThan(String otherVersion) {
* @see #isHigherThan(String otherVersion)
*/
public boolean isHigherThan(Version otherVersion) {
- int subversionsResult =
- VersionComparator.compareSubversionNumbers(subversionNumbers, otherVersion.subversionNumbers);
+ int subversionsResult = VersionComparator.compareSubversionNumbers(
+ subversionNumbersWithoutTrailingZeros,
+ otherVersion.subversionNumbersWithoutTrailingZeros);
if (subversionsResult != 0) {
return subversionsResult > 0;
}
@@ -151,8 +153,10 @@ public boolean isLowerThan(String otherVersion) {
* @see #isLowerThan(String otherVersion)
*/
public boolean isLowerThan(Version otherVersion) {
- int subversionsResult =
- VersionComparator.compareSubversionNumbers(subversionNumbers, otherVersion.subversionNumbers);
+ int subversionsResult = VersionComparator.compareSubversionNumbers(
+ subversionNumbersWithoutTrailingZeros,
+ otherVersion.subversionNumbersWithoutTrailingZeros
+ );
if (subversionsResult != 0) {
return subversionsResult < 0;
}
@@ -180,8 +184,10 @@ public boolean isEqual(String otherVersion) {
* @see #isEqual(String otherVersion)
*/
public boolean isEqual(Version otherVersion) {
- return VersionComparator.compareSubversionNumbers(subversionNumbers, otherVersion.subversionNumbers) == 0
- && VersionComparator.compareSuffix(suffix, otherVersion.suffix) == 0;
+ return VersionComparator.compareSubversionNumbers(
+ subversionNumbersWithoutTrailingZeros,
+ otherVersion.subversionNumbersWithoutTrailingZeros
+ ) == 0 && VersionComparator.compareSuffix(suffix, otherVersion.suffix) == 0;
}
/**
@@ -231,8 +237,10 @@ public boolean isAtLeast(String otherVersion, boolean ignoreSuffix) {
* @see #isAtLeast(String otherVersion, boolean ignoreSuffix)
*/
public boolean isAtLeast(Version otherVersion, boolean ignoreSuffix) {
- int subversionsResult =
- VersionComparator.compareSubversionNumbers(subversionNumbers, otherVersion.subversionNumbers);
+ int subversionsResult = VersionComparator.compareSubversionNumbers(
+ subversionNumbersWithoutTrailingZeros,
+ otherVersion.subversionNumbersWithoutTrailingZeros
+ );
if (subversionsResult == 0 && !ignoreSuffix) {
return VersionComparator.compareSuffix(suffix, otherVersion.suffix) >= 0;
}
@@ -267,20 +275,38 @@ private void initVersion() {
}
}
}
+ subversionNumbersWithoutTrailingZeros.addAll(subversionNumbers);
+ while (subversionNumbersWithoutTrailingZeros.lastIndexOf(0) >= 0) {
+ subversionNumbersWithoutTrailingZeros.remove(subversionNumbersWithoutTrailingZeros.lastIndexOf(0));
+ }
if (suffixSb != null) suffix = suffixSb.toString();
}
}
@Override
- public int compareTo(@Nonnull Version version) {
- if (this.isEqual(version)) return 0;
- else if (this.isLowerThan(version)) return -1;
- else return 1;
+ final public int compareTo(@Nonnull Version version) {
+ if (this.isEqual(version)) return 0;
+ else if (this.isLowerThan(version)) return -1;
+ else return 1;
}
@Override
- public boolean equals(Object o) {
- if (o instanceof Version && this.isEqual((Version)o)) return true;
- else return super.equals(o);
+ final public boolean equals(Object o) {
+ if (o instanceof Version && this.isEqual((Version) o)) return true;
+ else return super.equals(o);
+ }
+
+ @Override
+ final public int hashCode() {
+ final int prime = 31;
+ int hash = 1;
+ hash = prime * hash + subversionNumbersWithoutTrailingZeros.hashCode();
+ if (suffix.isEmpty()) return hash;
+
+ int releaseQualifier = VersionComparator.qualifierToNumber(suffix);
+ int releaseQualifierVersion = VersionComparator.preReleaseVersion(suffix, releaseQualifier);
+ hash = prime * hash + releaseQualifier;
+ hash = prime * hash + releaseQualifierVersion;
+ return hash;
}
}
diff --git a/versioncompare/src/main/java/com/g00fy2/versioncompare/VersionComparator.java b/versioncompare/src/main/java/com/g00fy2/versioncompare/VersionComparator.java
index 2b643df..7b876f7 100644
--- a/versioncompare/src/main/java/com/g00fy2/versioncompare/VersionComparator.java
+++ b/versioncompare/src/main/java/com/g00fy2/versioncompare/VersionComparator.java
@@ -64,7 +64,7 @@ static int compareSuffix(@Nonnull final String suffixA, @Nonnull final String su
return 0;
}
- private static int qualifierToNumber(@Nonnull String suffix) {
+ static int qualifierToNumber(@Nonnull String suffix) {
if (suffix.length() > 0) {
suffix = suffix.toLowerCase();
if (suffix.contains(RC_STRING)) return RC;
@@ -81,7 +81,7 @@ private static int qualifierToNumber(@Nonnull String suffix) {
return UNKNOWN;
}
- private static int preReleaseVersion(@Nonnull final String suffix, final int qualifier) {
+ static int preReleaseVersion(@Nonnull final String suffix, final int qualifier) {
final int startIndex = indexOfQualifier(suffix, qualifier);
if (startIndex < suffix.length()) {
final int maxStartIndex = Math.min(startIndex + 2, suffix.length());
diff --git a/versioncompare/src/test/java/com/g00fy2/versioncompare/VersionEqualsVerifier.java b/versioncompare/src/test/java/com/g00fy2/versioncompare/VersionEqualsVerifier.java
new file mode 100644
index 0000000..4f661a1
--- /dev/null
+++ b/versioncompare/src/test/java/com/g00fy2/versioncompare/VersionEqualsVerifier.java
@@ -0,0 +1,12 @@
+package com.g00fy2.versioncompare;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+import org.junit.Test;
+
+public class VersionEqualsVerifier {
+
+ @Test
+ public void equalsContract() {
+ EqualsVerifier.forClass(Version.class).withIgnoredFields("originalString", "subversionNumbers", "suffix").verify();
+ }
+}
diff --git a/versioncompare/src/test/java/com/g00fy2/versioncompare/VersionTestEquals.java b/versioncompare/src/test/java/com/g00fy2/versioncompare/VersionTestEquals.java
index 203f2cd..9ffd93a 100644
--- a/versioncompare/src/test/java/com/g00fy2/versioncompare/VersionTestEquals.java
+++ b/versioncompare/src/test/java/com/g00fy2/versioncompare/VersionTestEquals.java
@@ -53,4 +53,8 @@ public VersionTestEquals(String versionA, String versionB) {
@Test public void isEqualsComparatorCorrect() {
assertEquals(equalVersionA + " and " + equalVersionB + " should be equal", equalVersionAObject, equalVersionBObject);
}
+
+ @Test public void isHashCodeCorrect() {
+ assertEquals(equalVersionA + " and " + equalVersionB + " should be equal", equalVersionAObject.hashCode(), equalVersionBObject.hashCode());
+ }
}
\ No newline at end of file