Skip to content

Commit 2ac9d0b

Browse files
cmagliefacchinm
authored andcommitted
Added collector to LibraryList
1 parent b771467 commit 2ac9d0b

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

arduino-core/src/processing/app/packages/LibraryList.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,15 @@
3030

3131
import java.io.File;
3232
import java.util.Collections;
33+
import java.util.EnumSet;
3334
import java.util.LinkedList;
3435
import java.util.List;
36+
import java.util.Set;
37+
import java.util.function.BiConsumer;
38+
import java.util.function.BinaryOperator;
39+
import java.util.function.Function;
40+
import java.util.function.Supplier;
41+
import java.util.stream.Collector;
3542

3643
import cc.arduino.contributions.libraries.ContributedLibrary;
3744
import processing.app.helpers.FileUtils;
@@ -98,5 +105,36 @@ public synchronized boolean hasLibrary(UserLibrary lib) {
98105
if (l == lib) return true;
99106
return false;
100107
}
101-
}
102108

109+
public static Collector<UserLibrary, LibraryList, LibraryList> collector() {
110+
return new Collector<UserLibrary, LibraryList, LibraryList>() {
111+
@Override
112+
public Supplier<LibraryList> supplier() {
113+
return () -> new LibraryList();
114+
}
115+
116+
@Override
117+
public BiConsumer<LibraryList, UserLibrary> accumulator() {
118+
return (libs, lib) -> libs.add(lib);
119+
}
120+
121+
@Override
122+
public BinaryOperator<LibraryList> combiner() {
123+
return (we, they) -> {
124+
we.addAll(they);
125+
return we;
126+
};
127+
}
128+
129+
@Override
130+
public Function<LibraryList, LibraryList> finisher() {
131+
return (libs) -> libs;
132+
}
133+
134+
@Override
135+
public Set<Collector.Characteristics> characteristics() {
136+
return EnumSet.noneOf(Characteristics.class);
137+
}
138+
};
139+
}
140+
}

0 commit comments

Comments
 (0)