Skip to content

Commit 7497d51

Browse files
committed
Merge branch 'release/1.3.5'
2 parents 04be669 + e7adf5a commit 7497d51

File tree

13 files changed

+81
-46
lines changed

13 files changed

+81
-46
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ Pure Java (java.util), no dependencies, very small method count.
1212
**Gradle:**
1313
```
1414
dependencies {
15-
implementation 'com.g00fy2:versioncompare:1.3.4'
15+
implementation 'com.g00fy2:versioncompare:1.3.5'
1616
}
1717
```
1818
**Maven:**
1919
```
2020
<dependency>
2121
<groupId>com.g00fy2</groupId>
2222
<artifactId>versioncompare</artifactId>
23-
<version>1.3.4</version>
23+
<version>1.3.5</version>
2424
</dependency>
2525
```
2626

@@ -89,7 +89,7 @@ suffix compare logic ||
8989
## Sample App
9090
![Image](https://raw.githubusercontent.com/G00fY2/version-compare/gh-pages/images/version_compare_sampleapp_framed.png)
9191

92-
**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)**
92+
**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)**
9393

9494
## License
9595
Copyright (C) 2018 Thomas Wirth

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ buildscript {
44
jcenter()
55
}
66
dependencies {
7-
classpath 'com.android.tools.build:gradle:3.5.3'
8-
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
7+
classpath 'com.android.tools.build:gradle:4.0.2'
8+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
99
}
1010
}
1111

1212
allprojects {
1313
repositories {
1414
google()
15+
mavenCentral()
1516
jcenter()
1617
}
1718
}

gradle/wrapper/gradle-wrapper.jar

501 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

gradlew

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 7 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sample/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44

55
android {
6-
compileSdkVersion 29
6+
compileSdkVersion 30
77
defaultConfig {
88
applicationId 'com.g00fy2.versioncomparesample'
99
minSdkVersion 14
10-
targetSdkVersion 29
10+
targetSdkVersion 30
1111
versionCode 1
1212
versionName '1.0'
1313
}
@@ -30,7 +30,7 @@ dependencies {
3030
}
3131

3232
buildscript {
33-
ext.kotlin_version = '1.3.61'
33+
ext.kotlin_version = '1.4.10'
3434
repositories {
3535
mavenCentral()
3636
}

versioncompare/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ apply plugin: 'jacoco'
44
dependencies {
55
compileOnly 'com.google.code.findbugs:jsr305:3.0.2' // only required at compile time
66

7-
testImplementation 'junit:junit:4.12'
7+
testImplementation 'junit:junit:4.13'
8+
testImplementation 'nl.jqno.equalsverifier:equalsverifier:3.4.3'
89
}
910

1011
jacoco {

versioncompare/deploy.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ext {
1111
issueUrl = 'https://github.com/G00fY2/version-compare/issues'
1212
gitUrl = 'https://github.com/G00fY2/version-compare.git'
1313

14-
libraryVersion = '1.3.4'
14+
libraryVersion = '1.3.5'
1515

1616
developerId = 'g00fy2'
1717
developerName = 'Thomas Wirth'

versioncompare/src/main/java/com/g00fy2/versioncompare/Version.java

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Version implements Comparable<Version> {
1010

1111
@Nullable private final String originalString;
1212
@Nonnull private final List<Integer> subversionNumbers = new ArrayList<>();
13+
@Nonnull private final List<Integer> subversionNumbersWithoutTrailingZeros = new ArrayList<>();
1314
@Nonnull private String suffix = "";
1415

1516
/**
@@ -122,8 +123,9 @@ public boolean isHigherThan(String otherVersion) {
122123
* @see #isHigherThan(String otherVersion)
123124
*/
124125
public boolean isHigherThan(Version otherVersion) {
125-
int subversionsResult =
126-
VersionComparator.compareSubversionNumbers(subversionNumbers, otherVersion.subversionNumbers);
126+
int subversionsResult = VersionComparator.compareSubversionNumbers(
127+
subversionNumbersWithoutTrailingZeros,
128+
otherVersion.subversionNumbersWithoutTrailingZeros);
127129
if (subversionsResult != 0) {
128130
return subversionsResult > 0;
129131
}
@@ -151,8 +153,10 @@ public boolean isLowerThan(String otherVersion) {
151153
* @see #isLowerThan(String otherVersion)
152154
*/
153155
public boolean isLowerThan(Version otherVersion) {
154-
int subversionsResult =
155-
VersionComparator.compareSubversionNumbers(subversionNumbers, otherVersion.subversionNumbers);
156+
int subversionsResult = VersionComparator.compareSubversionNumbers(
157+
subversionNumbersWithoutTrailingZeros,
158+
otherVersion.subversionNumbersWithoutTrailingZeros
159+
);
156160
if (subversionsResult != 0) {
157161
return subversionsResult < 0;
158162
}
@@ -180,8 +184,10 @@ public boolean isEqual(String otherVersion) {
180184
* @see #isEqual(String otherVersion)
181185
*/
182186
public boolean isEqual(Version otherVersion) {
183-
return VersionComparator.compareSubversionNumbers(subversionNumbers, otherVersion.subversionNumbers) == 0
184-
&& VersionComparator.compareSuffix(suffix, otherVersion.suffix) == 0;
187+
return VersionComparator.compareSubversionNumbers(
188+
subversionNumbersWithoutTrailingZeros,
189+
otherVersion.subversionNumbersWithoutTrailingZeros
190+
) == 0 && VersionComparator.compareSuffix(suffix, otherVersion.suffix) == 0;
185191
}
186192

187193
/**
@@ -231,8 +237,10 @@ public boolean isAtLeast(String otherVersion, boolean ignoreSuffix) {
231237
* @see #isAtLeast(String otherVersion, boolean ignoreSuffix)
232238
*/
233239
public boolean isAtLeast(Version otherVersion, boolean ignoreSuffix) {
234-
int subversionsResult =
235-
VersionComparator.compareSubversionNumbers(subversionNumbers, otherVersion.subversionNumbers);
240+
int subversionsResult = VersionComparator.compareSubversionNumbers(
241+
subversionNumbersWithoutTrailingZeros,
242+
otherVersion.subversionNumbersWithoutTrailingZeros
243+
);
236244
if (subversionsResult == 0 && !ignoreSuffix) {
237245
return VersionComparator.compareSuffix(suffix, otherVersion.suffix) >= 0;
238246
}
@@ -267,20 +275,38 @@ private void initVersion() {
267275
}
268276
}
269277
}
278+
subversionNumbersWithoutTrailingZeros.addAll(subversionNumbers);
279+
while (subversionNumbersWithoutTrailingZeros.lastIndexOf(0) >= 0) {
280+
subversionNumbersWithoutTrailingZeros.remove(subversionNumbersWithoutTrailingZeros.lastIndexOf(0));
281+
}
270282
if (suffixSb != null) suffix = suffixSb.toString();
271283
}
272284
}
273285

274286
@Override
275-
public int compareTo(@Nonnull Version version) {
276-
if (this.isEqual(version)) return 0;
277-
else if (this.isLowerThan(version)) return -1;
278-
else return 1;
287+
final public int compareTo(@Nonnull Version version) {
288+
if (this.isEqual(version)) return 0;
289+
else if (this.isLowerThan(version)) return -1;
290+
else return 1;
279291
}
280292

281293
@Override
282-
public boolean equals(Object o) {
283-
if (o instanceof Version && this.isEqual((Version)o)) return true;
284-
else return super.equals(o);
294+
final public boolean equals(Object o) {
295+
if (o instanceof Version && this.isEqual((Version) o)) return true;
296+
else return super.equals(o);
297+
}
298+
299+
@Override
300+
final public int hashCode() {
301+
final int prime = 31;
302+
int hash = 1;
303+
hash = prime * hash + subversionNumbersWithoutTrailingZeros.hashCode();
304+
if (suffix.isEmpty()) return hash;
305+
306+
int releaseQualifier = VersionComparator.qualifierToNumber(suffix);
307+
int releaseQualifierVersion = VersionComparator.preReleaseVersion(suffix, releaseQualifier);
308+
hash = prime * hash + releaseQualifier;
309+
hash = prime * hash + releaseQualifierVersion;
310+
return hash;
285311
}
286312
}

0 commit comments

Comments
 (0)