| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
package processing.app.packages; |
| 30 |
|
| 31 |
import java.io.File; |
| 32 |
import java.util.Collections; |
| 33 |
import java.util.EnumSet; |
| 34 |
import java.util.LinkedList; |
| 35 |
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; |
| 42 |
|
| 43 |
import processing.app.helpers.FileUtils; |
| 44 |
|
| 45 |
@SuppressWarnings("serial") |
| 46 |
public class LibraryList extends LinkedList<UserLibrary> { |
| 47 |
|
| 48 |
public LibraryList(LibraryList libs) { |
| 49 |
super(libs); |
| 50 |
} |
| 51 |
|
| 52 |
public LibraryList() { |
| 53 |
super(); |
| 54 |
} |
| 55 |
|
| 56 |
public LibraryList(List<UserLibrary> ideLibs) { |
| 57 |
super(ideLibs); |
| 58 |
} |
| 59 |
|
| 60 |
public synchronized UserLibrary getByName(String name) { |
| 61 |
for (UserLibrary l : this) |
| 62 |
if (l.getName().equals(name)) |
| 63 |
return l; |
| 64 |
return null; |
| 65 |
} |
| 66 |
|
| 67 |
public synchronized void sort() { |
| 68 |
Collections.sort(this, (x, y) -> x.getName().compareToIgnoreCase(y.getName())); |
| 69 |
} |
| 70 |
|
| 71 |
public synchronized LibraryList filterLibrariesInSubfolder(File subFolder) { |
| 72 |
LibraryList res = new LibraryList(); |
| 73 |
for (UserLibrary lib : this) { |
| 74 |
if (FileUtils.isSubDirectory(subFolder, lib.getInstalledFolder())) { |
| 75 |
res.add(lib); |
| 76 |
} |
| 77 |
} |
| 78 |
return res; |
| 79 |
} |
| 80 |
|
| 81 |
public synchronized boolean hasLibrary(UserLibrary lib) { |
| 82 |
for (UserLibrary l : this) |
| 83 |
if (l == lib) return true; |
| 84 |
return false; |
| 85 |
} |
| 86 |
|
| 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 |
} |