1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-29 10:24:12 +01:00

Added helper methods to compare versions

This commit is contained in:
Cristian Maglie 2017-01-26 15:28:31 +01:00 committed by Martino Facchin
parent d72cb2350d
commit 1ebdb02954
2 changed files with 9 additions and 1 deletions

View File

@ -65,4 +65,7 @@ public class VersionHelper {
} }
} }
public static int compare(String a, String b) {
return valueOf(a).get().compareTo(valueOf(b).get());
}
} }

View File

@ -32,12 +32,13 @@ package cc.arduino.contributions.libraries;
import cc.arduino.contributions.DownloadableContribution; import cc.arduino.contributions.DownloadableContribution;
import processing.app.I18n; import processing.app.I18n;
import processing.app.packages.UserLibrary; import processing.app.packages.UserLibrary;
import static processing.app.I18n.tr;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import static processing.app.I18n.tr; import cc.arduino.contributions.VersionHelper;
public abstract class ContributedLibrary extends DownloadableContribution { public abstract class ContributedLibrary extends DownloadableContribution {
@ -181,6 +182,10 @@ public abstract class ContributedLibrary extends DownloadableContribution {
return versionEquals && nameEquals; return versionEquals && nameEquals;
} }
public boolean isBefore(ContributedLibrary other) {
return VersionHelper.compare(getVersion(), other.getVersion()) < 0;
}
@Override @Override
public int hashCode() { public int hashCode() {
String hashingData = "CONTRIBUTEDLIB" + getName() + getVersion(); String hashingData = "CONTRIBUTEDLIB" + getName() + getVersion();