1
+ /*
2
+ * This file is part of Arduino.
3
+ *
4
+ * Copyright 2015 Arduino LLC (http://www.arduino.cc/)
5
+ *
6
+ * Arduino is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ *
20
+ * As a special exception, you may use this file as part of a free software
21
+ * library without restriction. Specifically, if other files instantiate
22
+ * templates or use macros or inline functions from this file, or you compile
23
+ * this file and link it with other files to produce an executable, this
24
+ * file does not by itself cause the resulting executable to be covered by
25
+ * the GNU General Public License. This exception does not however
26
+ * invalidate any other reasons why the executable file might be covered by
27
+ * the GNU General Public License.
28
+ */
29
+
30
+ package cc .arduino .contributions .packages .ui ;
31
+
32
+ import java .util .Collections ;
33
+ import java .util .LinkedList ;
34
+ import java .util .List ;
35
+ import java .util .stream .Collectors ;
36
+
37
+ import cc .arduino .contributions .DownloadableContributionBuiltInAtTheBottomComparator ;
38
+ import cc .arduino .contributions .filters .InstalledPredicate ;
39
+ import cc .arduino .contributions .packages .ContributedPackage ;
40
+ import cc .arduino .contributions .packages .ContributedPlatform ;
41
+
42
+ public class ContributedPlatformReleases {
43
+
44
+ public final ContributedPackage packager ;
45
+ public final String arch ;
46
+ public final List <ContributedPlatform > releases ;
47
+ public final List <String > versions ;
48
+ public ContributedPlatform selected = null ;
49
+
50
+ public ContributedPlatformReleases (ContributedPlatform platform ) {
51
+ packager = platform .getParentPackage ();
52
+ arch = platform .getArchitecture ();
53
+ releases = new LinkedList <>();
54
+ versions = new LinkedList <>();
55
+ add (platform );
56
+ }
57
+
58
+ public boolean shouldContain (ContributedPlatform platform ) {
59
+ if (platform .getParentPackage () != packager )
60
+ return false ;
61
+ return platform .getArchitecture ().equals (arch );
62
+ }
63
+
64
+ public void add (ContributedPlatform platform ) {
65
+ releases .add (platform );
66
+ String version = platform .getParsedVersion ();
67
+ if (version != null ) {
68
+ versions .add (version );
69
+ }
70
+ selected = getLatest ();
71
+ }
72
+
73
+ public ContributedPlatform getInstalled () {
74
+ List <ContributedPlatform > installedReleases = releases .stream ()
75
+ .filter (new InstalledPredicate ()).collect (Collectors .toList ());
76
+ Collections
77
+ .sort (installedReleases ,
78
+ new DownloadableContributionBuiltInAtTheBottomComparator ());
79
+
80
+ if (installedReleases .isEmpty ()) {
81
+ return null ;
82
+ }
83
+
84
+ return installedReleases .get (0 );
85
+ }
86
+
87
+ public ContributedPlatform getLatest () {
88
+ return ContributionIndexTableModel .getLatestOf (releases );
89
+ }
90
+
91
+ public ContributedPlatform getSelected () {
92
+ return selected ;
93
+ }
94
+
95
+ public void select (ContributedPlatform value ) {
96
+ for (ContributedPlatform plat : releases ) {
97
+ if (plat == value ) {
98
+ selected = plat ;
99
+ return ;
100
+ }
101
+ }
102
+ }
103
+ }
0 commit comments