40
40
41
41
public class ContributedLibraryReleases {
42
42
43
- private final ContributedLibrary library ;
44
- private final List <ContributedLibrary > releases ;
45
- private final List <String > versions ;
46
-
47
- private ContributedLibrary selected ;
43
+ private List <ContributedLibrary > releases = new LinkedList <>();
44
+ private List <String > versions = new LinkedList <>();
45
+ private ContributedLibrary latest = null ;
46
+ private ContributedLibrary selected = null ;
48
47
49
48
public ContributedLibraryReleases (ContributedLibrary library ) {
50
- this .library = library ;
51
- this .versions = new LinkedList <>();
52
- this .releases = new LinkedList <>();
53
- this .selected = null ;
54
49
add (library );
55
50
}
56
51
57
52
public ContributedLibrary getLibrary () {
58
- return library ;
53
+ return latest ;
59
54
}
60
55
61
56
public List <ContributedLibrary > getReleases () {
62
57
return releases ;
63
58
}
64
59
65
60
public boolean shouldContain (ContributedLibrary lib ) {
66
- return lib .getName ().equals (library .getName ());
61
+ if (latest == null ) {
62
+ return true ;
63
+ }
64
+ return lib .getName ().equals (latest .getName ());
67
65
}
68
66
69
67
public void add (ContributedLibrary library ) {
68
+ if (latest == null ) {
69
+ latest = library ;
70
+ }
70
71
releases .add (library );
71
72
String version = library .getParsedVersion ();
72
73
if (version != null ) {
73
74
versions .add (version );
74
75
}
75
- selected = getLatest ();
76
+ if (VersionComparator .greaterThan (version , latest .getParsedVersion ())) {
77
+ latest = library ;
78
+ }
79
+ selected = latest ;
76
80
}
77
81
78
82
public Optional <ContributedLibrary > getInstalled () {
@@ -85,25 +89,17 @@ public Optional<ContributedLibrary> getInstalled() {
85
89
}
86
90
87
91
public ContributedLibrary getLatest () {
88
- List <ContributedLibrary > rels = new LinkedList <>(releases );
89
- final VersionComparator versionComparator = new VersionComparator ();
90
- Collections .sort (rels , (x , y ) -> versionComparator .compare (x .getParsedVersion (), y .getParsedVersion ()));
91
-
92
- if (rels .isEmpty ()) {
93
- return null ;
94
- }
95
-
96
- return rels .get (rels .size () - 1 );
92
+ return latest ;
97
93
}
98
94
99
95
public ContributedLibrary getSelected () {
100
96
return selected ;
101
97
}
102
98
103
- public void select (ContributedLibrary value ) {
104
- for (ContributedLibrary plat : releases ) {
105
- if (plat == value ) {
106
- selected = plat ;
99
+ public void select (ContributedLibrary lib ) {
100
+ for (ContributedLibrary r : releases ) {
101
+ if (r == lib ) {
102
+ selected = r ;
107
103
return ;
108
104
}
109
105
}
0 commit comments