1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-18 07:52:14 +01:00

Added VersionComparator to be used for comparing versions numbers (WIP)

This commit is contained in:
Cristian Maglie 2014-05-16 01:07:56 +02:00 committed by Federico Fissore
parent 1aab726750
commit 0783f40ba5
3 changed files with 70 additions and 0 deletions

View File

@ -53,6 +53,28 @@ public abstract class ContributedPackage {
return null;
}
/**
* Return the latest version available of a platform
*
* @param platform
* @return
*/
public ContributedPlatform findPlatform(String platform) {
VersionComparator version = new VersionComparator();
ContributedPlatform found = null;
for (ContributedPlatform p : getPlatforms()) {
if (!p.getName().equals(platform))
continue;
if (found == null) {
found = p;
continue;
}
if (version.compare(p.getVersion(), found.getVersion()) > 0)
found = p;
}
return found;
}
public ContributedTool findTool(String name, String version) {
for (ContributedTool tool : getTools()) {
if (tool.getName().equals(name) && tool.getVersion().equals(version))

View File

@ -67,6 +67,13 @@ public abstract class ContributionsIndex {
}
}
public ContributedPackage getPackage(String packager) {
for (ContributedPackage pack : getPackages())
if (pack.getName().equals(packager))
return pack;
return null;
}
@Override
public String toString() {
String res = "";

View File

@ -0,0 +1,41 @@
/*
* This file is part of Arduino.
*
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*/
package cc.arduino.packages.contributions;
import java.util.Comparator;
public class VersionComparator implements Comparator<String> {
@Override
public int compare(String o1, String o2) {
// TODO: do a proper version compare
return o1.compareTo(o2);
}
}