Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * This file is part of Arduino.
3 *
4 * Copyright 2014 Arduino LLC (http://www.arduino.cc/)
5 *
6 * Arduino is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
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 }