Skip to content

Commit 1db3aab

Browse files
committed
Added collector to LibraryList
1 parent a76588c commit 1db3aab

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

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

+39-1
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 processing.app.helpers.FileUtils;
3744

@@ -76,5 +83,36 @@ public synchronized boolean hasLibrary(UserLibrary lib) {
7683
if (l == lib) return true;
7784
return false;
7885
}
79-
}
8086

87+
public static Collector<UserLibrary, LibraryList, LibraryList> collector() {
88+
return new Collector<UserLibrary, LibraryList, LibraryList>() {
89+
@Override
90+
public Supplier<LibraryList> supplier() {
91+
return () -> new LibraryList();
92+
}
93+
94+
@Override
95+
public BiConsumer<LibraryList, UserLibrary> accumulator() {
96+
return (libs, lib) -> libs.add(lib);
97+
}
98+
99+
@Override
100+
public BinaryOperator<LibraryList> combiner() {
101+
return (we, they) -> {
102+
we.addAll(they);
103+
return we;
104+
};
105+
}
106+
107+
@Override
108+
public Function<LibraryList, LibraryList> finisher() {
109+
return (libs) -> libs;
110+
}
111+
112+
@Override
113+
public Set<Collector.Characteristics> characteristics() {
114+
return EnumSet.noneOf(Characteristics.class);
115+
}
116+
};
117+
}
118+
}

0 commit comments

Comments
 (0)