Skip to content

Commit 1ebdb02

Browse files
cmagliefacchinm
authored andcommitted
Added helper methods to compare versions
1 parent d72cb23 commit 1ebdb02

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

arduino-core/src/cc/arduino/contributions/VersionHelper.java

+3
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,7 @@ public static Optional<Version> valueOf(String ver) {
6565
}
6666
}
6767

68+
public static int compare(String a, String b) {
69+
return valueOf(a).get().compareTo(valueOf(b).get());
70+
}
6871
}

arduino-core/src/cc/arduino/contributions/libraries/ContributedLibrary.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232
import cc.arduino.contributions.DownloadableContribution;
3333
import processing.app.I18n;
3434
import processing.app.packages.UserLibrary;
35+
import static processing.app.I18n.tr;
3536

3637
import java.util.Comparator;
3738
import java.util.List;
3839
import java.util.Optional;
3940

40-
import static processing.app.I18n.tr;
41+
import cc.arduino.contributions.VersionHelper;
4142

4243
public abstract class ContributedLibrary extends DownloadableContribution {
4344

@@ -181,6 +182,10 @@ public boolean equals(Object obj) {
181182
return versionEquals && nameEquals;
182183
}
183184

185+
public boolean isBefore(ContributedLibrary other) {
186+
return VersionHelper.compare(getVersion(), other.getVersion()) < 0;
187+
}
188+
184189
@Override
185190
public int hashCode() {
186191
String hashingData = "CONTRIBUTEDLIB" + getName() + getVersion();

0 commit comments

Comments
 (0)