Skip to content

Commit 6428976

Browse files
committed
fixed filtering issue
1 parent 09b73a5 commit 6428976

File tree

3 files changed

+317
-294
lines changed

3 files changed

+317
-294
lines changed

it.baeyens.arduino.core/src/it/baeyens/arduino/managers/LibraryIndex.java

Lines changed: 75 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -10,92 +10,93 @@
1010

1111
public class LibraryIndex {
1212

13-
private List<Library> libraries;
14-
15-
// category name to library name
16-
private Map<String, Set<String>> categories = new HashMap<>();
17-
// library name to latest version of library
18-
private Map<String, Library> latestLibs = new HashMap<>();
19-
20-
public void resolve() {
21-
for (Library library : this.libraries) {
22-
String name = library.getName();
23-
24-
String category = library.getCategory();
25-
if (category == null) {
26-
category = "Uncategorized"; //$NON-NLS-1$
27-
}
28-
29-
Set<String> categoryLibs = this.categories.get(category);
30-
if (categoryLibs == null) {
31-
categoryLibs = new HashSet<>();
32-
this.categories.put(category, categoryLibs);
33-
}
34-
categoryLibs.add(name);
35-
36-
Library current = this.latestLibs.get(name);
37-
if (current != null) {
38-
if (Manager.compareVersions(library.getVersion(), current.getVersion()) > 0) {
39-
this.latestLibs.put(name, library);
13+
private List<Library> libraries;
14+
15+
// category name to library name
16+
private Map<String, Set<String>> categories = new HashMap<>();
17+
18+
// library name to latest version of library
19+
private Map<String, Library> latestLibs = new HashMap<>();
20+
21+
public void resolve() {
22+
for (Library library : this.libraries) {
23+
String name = library.getName();
24+
25+
String category = library.getCategory();
26+
if (category == null) {
27+
category = "Uncategorized"; //$NON-NLS-1$
28+
}
29+
30+
Set<String> categoryLibs = this.categories.get(category);
31+
if (categoryLibs == null) {
32+
categoryLibs = new HashSet<>();
33+
this.categories.put(category, categoryLibs);
34+
}
35+
categoryLibs.add(name);
36+
37+
Library current = this.latestLibs.get(name);
38+
if (current != null) {
39+
if (Manager.compareVersions(library.getVersion(), current.getVersion()) > 0) {
40+
this.latestLibs.put(name, library);
41+
}
42+
} else {
43+
this.latestLibs.put(name, library);
44+
}
4045
}
41-
} else {
42-
this.latestLibs.put(name, library);
43-
}
4446
}
45-
}
4647

47-
public Library getLatestLibrary(String name) {
48-
return this.latestLibs.get(name);
49-
}
50-
51-
public Library getLibrary(String libName, String version) {
52-
for (Library library : this.libraries) {
53-
if (library.getName().equals(libName) && (library.getVersion().equals(version))) {
54-
return library;
55-
}
56-
}
57-
return null;
58-
}
59-
60-
public Library getInstalledLibrary(String libName) {
61-
for (Library library : this.libraries) {
62-
if (library.getName().equals(libName) && library.isInstalled()) {
63-
return library;
64-
}
48+
public Library getLatestLibrary(String name) {
49+
return this.latestLibs.get(name);
6550
}
66-
return null;
67-
}
6851

69-
public Set<String> getCategories() {
70-
return this.categories.keySet();
71-
}
52+
public Library getLibrary(String libName, String version) {
53+
for (Library library : this.libraries) {
54+
if (library.getName().equals(libName) && (library.getVersion().equals(version))) {
55+
return library;
56+
}
57+
}
58+
return null;
59+
}
7260

73-
public Collection<Library> getLatestLibraries(String category) {
74-
Set<String> categoryLibs = this.categories.get(category);
75-
if (categoryLibs == null) {
76-
return new ArrayList<>(0);
61+
public Library getInstalledLibrary(String libName) {
62+
for (Library library : this.libraries) {
63+
if (library.getName().equals(libName) && library.isInstalled()) {
64+
return library;
65+
}
66+
}
67+
return null;
7768
}
7869

79-
List<Library> libs = new ArrayList<>(categoryLibs.size());
80-
for (String name : categoryLibs) {
81-
libs.add(this.latestLibs.get(name));
70+
public Set<String> getCategories() {
71+
return this.categories.keySet();
8272
}
83-
return libs;
84-
}
8573

86-
public Collection<Library> getLibraries(String category) {
87-
Set<String> categoryLibs = this.categories.get(category);
88-
if (categoryLibs == null) {
89-
return new ArrayList<>(0);
74+
public Collection<Library> getLatestLibraries(String category) {
75+
Set<String> categoryLibs = this.categories.get(category);
76+
if (categoryLibs == null) {
77+
return new ArrayList<>(0);
78+
}
79+
80+
List<Library> libs = new ArrayList<>(categoryLibs.size());
81+
for (String name : categoryLibs) {
82+
libs.add(this.latestLibs.get(name));
83+
}
84+
return libs;
9085
}
9186

92-
List<Library> libs = new ArrayList<>(categoryLibs.size());
93-
for (Library curLibrary : this.libraries) {
94-
if (categoryLibs.contains(curLibrary.getName())) {
95-
libs.add(curLibrary);
96-
}
87+
public Collection<Library> getLibraries(String category) {
88+
Set<String> categoryLibs = this.categories.get(category);
89+
if (categoryLibs == null) {
90+
return new ArrayList<>(0);
91+
}
92+
93+
List<Library> libs = new ArrayList<>(categoryLibs.size());
94+
for (Library curLibrary : this.libraries) {
95+
if (categoryLibs.contains(curLibrary.getName())) {
96+
libs.add(curLibrary);
97+
}
98+
}
99+
return libs;
97100
}
98-
return libs;
99-
}
100101

101102
}

it.baeyens.arduino.core/src/it/baeyens/arduino/managers/LibraryTree.java

Lines changed: 0 additions & 173 deletions
This file was deleted.

0 commit comments

Comments
 (0)