Skip to content

Commit

Permalink
Merge branch 'release/1.3.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
G00fY2 committed Oct 9, 2020
2 parents 04be669 + e7adf5a commit 7497d51
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 46 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ 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:**
```
<dependency>
<groupId>com.g00fy2</groupId>
<artifactId>versioncompare</artifactId>
<version>1.3.4</version>
<version>1.3.5</version>
</dependency>
```

Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 7 additions & 18 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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.
Expand All @@ -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%
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand All @@ -30,7 +30,7 @@ dependencies {
}

buildscript {
ext.kotlin_version = '1.3.61'
ext.kotlin_version = '1.4.10'
repositories {
mavenCentral()
}
Expand Down
3 changes: 2 additions & 1 deletion versioncompare/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion versioncompare/deploy.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
56 changes: 41 additions & 15 deletions versioncompare/src/main/java/com/g00fy2/versioncompare/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Version implements Comparable<Version> {

@Nullable private final String originalString;
@Nonnull private final List<Integer> subversionNumbers = new ArrayList<>();
@Nonnull private final List<Integer> subversionNumbersWithoutTrailingZeros = new ArrayList<>();
@Nonnull private String suffix = "";

/**
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 7497d51

Please sign in to comment.