Skip to content

Commit 380b147

Browse files
author
Federico Fissore
committed
Code cleanup
1 parent 5ebce32 commit 380b147

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
import java.io.IOException;
5353
import java.io.InputStream;
5454
import java.util.ArrayList;
55-
import java.util.Arrays;
55+
import java.util.Collections;
5656
import java.util.List;
5757

5858
import static processing.app.I18n._;
@@ -67,8 +67,8 @@ public class LibrariesIndexer {
6767
private final File indexFile;
6868
private final File stagingFolder;
6969
private File sketchbookLibrariesFolder;
70-
71-
private final List<String> badLibNotified = new ArrayList<String>();
70+
71+
private final List<String> badLibNotified = new ArrayList<>();
7272

7373
public LibrariesIndexer(File preferencesFolder, ContributionsIndexer contributionsIndexer) {
7474
this.contributionsIndexer = contributionsIndexer;
@@ -92,11 +92,10 @@ private void parseIndex(File indexFile) throws IOException {
9292
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
9393
index = mapper.readValue(indexIn, LibrariesIndex.class);
9494

95-
for (ContributedLibrary library : index.getLibraries()) {
96-
if (library.getCategory() == null || "".equals(library.getCategory())) {
97-
library.setCategory("Uncategorized");
98-
}
99-
}
95+
index.getLibraries()
96+
.stream()
97+
.filter(library -> library.getCategory() == null || "".equals(library.getCategory()))
98+
.forEach(library -> library.setCategory("Uncategorized"));
10099
} finally {
101100
IOUtils.closeQuietly(indexIn);
102101
}
@@ -124,7 +123,7 @@ public void rescanLibraries() {
124123
@Override
125124
public Object apply(UserLibrary userLibrary) {
126125
ContributedPlatform platform = contributionsIndexer.getPlatformByFolder(userLibrary.getInstalledFolder());
127-
userLibrary.setTypes(Arrays.asList(platform.getCategory()));
126+
userLibrary.setTypes(Collections.singletonList(platform.getCategory()));
128127
return userLibrary;
129128
}
130129
}).toList();
@@ -140,14 +139,14 @@ private void scanInstalledLibraries(File folder, boolean isSketchbook) {
140139
if (!BaseNoGui.isSanitaryName(subfolder.getName())) {
141140

142141
// Detect whether the current folder name has already had a notification.
143-
if(!badLibNotified.contains(subfolder.getName())) {
142+
if (!badLibNotified.contains(subfolder.getName())) {
144143

145144
badLibNotified.add(subfolder.getName());
146145

147146
String mess = I18n.format(_("The library \"{0}\" cannot be used.\n"
148-
+ "Library names must contain only basic letters and numbers.\n"
149-
+ "(ASCII only and no spaces, and it cannot start with a number)"),
150-
subfolder.getName());
147+
+ "Library names must contain only basic letters and numbers.\n"
148+
+ "(ASCII only and no spaces, and it cannot start with a number)"),
149+
subfolder.getName());
151150
BaseNoGui.showMessage(_("Ignoring bad library name"), mess);
152151
}
153152
continue;
@@ -213,7 +212,7 @@ private void scanLibrary(File folder, boolean isSketchbook) throws IOException {
213212
}
214213

215214
if (lib.getTypes() == null) {
216-
lib.setTypes(Arrays.asList("Contributed"));
215+
lib.setTypes(Collections.singletonList("Contributed"));
217216
}
218217
}
219218

0 commit comments

Comments
 (0)