From 0783f40ba5cc0f33b3871ffe44d95a0604741b02 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 16 May 2014 01:07:56 +0200 Subject: [PATCH] Added VersionComparator to be used for comparing versions numbers (WIP) --- .../contributions/ContributedPackage.java | 22 ++++++++++ .../contributions/ContributionsIndex.java | 7 ++++ .../contributions/VersionComparator.java | 41 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 arduino-core/src/cc/arduino/packages/contributions/VersionComparator.java diff --git a/arduino-core/src/cc/arduino/packages/contributions/ContributedPackage.java b/arduino-core/src/cc/arduino/packages/contributions/ContributedPackage.java index 2ca938ba3..14cab49f1 100644 --- a/arduino-core/src/cc/arduino/packages/contributions/ContributedPackage.java +++ b/arduino-core/src/cc/arduino/packages/contributions/ContributedPackage.java @@ -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)) diff --git a/arduino-core/src/cc/arduino/packages/contributions/ContributionsIndex.java b/arduino-core/src/cc/arduino/packages/contributions/ContributionsIndex.java index 8787266a6..8c6b2f51e 100644 --- a/arduino-core/src/cc/arduino/packages/contributions/ContributionsIndex.java +++ b/arduino-core/src/cc/arduino/packages/contributions/ContributionsIndex.java @@ -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 = ""; diff --git a/arduino-core/src/cc/arduino/packages/contributions/VersionComparator.java b/arduino-core/src/cc/arduino/packages/contributions/VersionComparator.java new file mode 100644 index 000000000..d048a44eb --- /dev/null +++ b/arduino-core/src/cc/arduino/packages/contributions/VersionComparator.java @@ -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 { + + @Override + public int compare(String o1, String o2) { + // TODO: do a proper version compare + return o1.compareTo(o2); + } + +}