Skip to content

Commit 402b29a

Browse files
authored
Merge pull request #5134 from rbonifacio/refactor-towards-language-evolution
Refactor to use a few Java 8 features
2 parents 897f7ae + 2721d54 commit 402b29a

File tree

9 files changed

+19
-35
lines changed

9 files changed

+19
-35
lines changed

app/src/processing/app/Library.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static String[] listPlatformEntries(File libraryFolder, String folderName, Strin
282282
}
283283

284284

285-
static protected HashMap<String, Object> packageWarningMap = new HashMap<String, Object>();
285+
static protected HashMap<String, Object> packageWarningMap = new HashMap<>();
286286

287287
/**
288288
* Add the packages provided by this library to the master list that maps
@@ -461,12 +461,7 @@ public boolean supportsArch(int platform, String variant) {
461461

462462

463463
static public boolean hasMultipleArch(int platform, List<Library> libraries) {
464-
for (Library library : libraries) {
465-
if (library.hasMultipleArch(platform)) {
466-
return true;
467-
}
468-
}
469-
return false;
464+
return libraries.stream().anyMatch(library -> library.hasMultipleArch(platform));
470465
}
471466

472467

@@ -484,7 +479,7 @@ public boolean accept(File dir, String name) {
484479

485480

486481
static public List<File> discover(File folder) {
487-
List<File> libraries = new ArrayList<File>();
482+
List<File> libraries = new ArrayList<>();
488483
String[] folderNames = folder.list(junkFolderFilter);
489484

490485
// if a bad folder or something like that, this might come back null
@@ -529,8 +524,8 @@ static public List<File> discover(File folder) {
529524

530525

531526
static public List<Library> list(File folder) {
532-
List<Library> libraries = new ArrayList<Library>();
533-
List<File> librariesFolders = new ArrayList<File>();
527+
List<Library> libraries = new ArrayList<>();
528+
List<File> librariesFolders = new ArrayList<>();
534529
librariesFolders.addAll(discover(folder));
535530

536531
for (File baseFolder : librariesFolders) {

app/src/processing/app/ui/MarkerColumn.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class MarkerColumn extends JPanel {
6060
private Color warningColor;
6161

6262
// Stores error markers displayed PER TAB along the error bar.
63-
private List<LineMarker> errorPoints = new ArrayList<LineMarker>();
63+
private List<LineMarker> errorPoints = new ArrayList<>();
6464

6565

6666
public MarkerColumn(Editor editor, int height) {

build/shared/tools/MovieMaker/src/ch/randelshofer/gui/datatransfer/FileTextFieldTransferHandler.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ public boolean importData(JComponent comp, Transferable t) {
109109
c.setText(file.getPath());
110110
}
111111
imported = true;
112-
} catch (UnsupportedFlavorException ex) {
113-
// ex.printStackTrace();
114-
} catch (IOException ex) {
112+
} catch (UnsupportedFlavorException | IOException ex) {
115113
// ex.printStackTrace();
116114
}
117115
}
@@ -129,11 +127,7 @@ public boolean importData(JComponent comp, Transferable t) {
129127
boolean useRead = false;
130128
handleReaderImport(r, c, useRead);
131129
imported = true;
132-
} catch (UnsupportedFlavorException ex) {
133-
// ex.printStackTrace();
134-
} catch (BadLocationException ex) {
135-
// ex.printStackTrace();
136-
} catch (IOException ex) {
130+
} catch (UnsupportedFlavorException | BadLocationException | IOException ex) {
137131
// ex.printStackTrace();
138132
}
139133
}

java/libraries/io/src/processing/io/LED.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public static String[] list() {
161161
return new String[]{ "led0", "led1" };
162162
}
163163

164-
ArrayList<String> devs = new ArrayList<String>();
164+
ArrayList<String> devs = new ArrayList<>();
165165
File dir = new File("/sys/class/leds");
166166
File[] files = dir.listFiles();
167167
if (files != null) {

java/src/processing/mode/java/VariableInspector.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class VariableInspector extends JDialog {
8181
// protected Debugger dbg;
8282

8383
/// list of expanded tree paths. (using list to maintain the order of expansion)
84-
protected List<TreePath> expandedNodes = new ArrayList<TreePath>();
84+
protected List<TreePath> expandedNodes = new ArrayList<>();
8585

8686

8787
public VariableInspector(final JavaEditor editor) {
@@ -696,7 +696,7 @@ public void treeCollapsed(TreeExpansionEvent tee) {
696696
// first remove all children of collapsed path
697697
// this makes sure children do not appear before parents in the list.
698698
// (children can't be expanded before their parents)
699-
List<TreePath> removalList = new ArrayList<TreePath>();
699+
List<TreePath> removalList = new ArrayList<>();
700700
for (TreePath path : expandedNodes) {
701701
if (path.getParentPath().equals(tee.getPath())) {
702702
removalList.add(path);
@@ -911,7 +911,7 @@ protected TreePath synthesizePath(TreePath path) {
911911
* @return the filtered list.
912912
*/
913913
protected List<VariableNode> filterNodes(List<VariableNode> nodes, VariableNodeFilter filter) {
914-
List<VariableNode> filtered = new ArrayList<VariableNode>();
914+
List<VariableNode> filtered = new ArrayList<>();
915915
for (VariableNode node : nodes) {
916916
if (filter.accept(node)) {
917917
filtered.add(node);

java/src/processing/mode/java/debug/ArrayFieldNode.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ public ArrayFieldNode(String name, String type, Value value, ArrayReference arra
5252
public void setValue(Value value) {
5353
try {
5454
array.setValue(index, value);
55-
} catch (InvalidTypeException ex) {
56-
Messages.loge(null, ex);
57-
} catch (ClassNotLoadedException ex) {
55+
} catch (InvalidTypeException | ClassNotLoadedException ex) {
5856
Messages.loge(null, ex);
5957
}
6058
this.value = value;

java/src/processing/mode/java/debug/LocalVariableNode.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ public LocalVariableNode(String name, String type, Value value, LocalVariable va
5151
public void setValue(Value value) {
5252
try {
5353
frame.setValue(var, value);
54-
} catch (InvalidTypeException ex) {
55-
Messages.loge(null, ex);
56-
} catch (ClassNotLoadedException ex) {
54+
} catch (InvalidTypeException | ClassNotLoadedException ex) {
5755
Messages.loge(null, ex);
5856
}
5957
this.value = value;

java/src/processing/mode/java/debug/VariableNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class VariableNode implements MutableTreeNode {
5555
protected String type;
5656
protected String name;
5757
protected Value value;
58-
protected List<MutableTreeNode> children = new ArrayList<MutableTreeNode>();
58+
protected List<MutableTreeNode> children = new ArrayList<>();
5959
protected MutableTreeNode parent;
6060

6161

java/src/processing/mode/java/tweak/SketchParser.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.*;
2424
import java.util.regex.Matcher;
2525
import java.util.regex.Pattern;
26+
import java.util.stream.Collectors;
2627

2728

2829
public class SketchParser {
@@ -581,11 +582,9 @@ private void handleMultipleColorModes() {
581582
for (int i = 0; i < codeTabs.length; i++) {
582583
List<ColorControlBox> toDelete = new ArrayList<ColorControlBox>();
583584
for (String context : multipleContexts) {
584-
for (ColorControlBox ccb : colorBoxes.get(i)) {
585-
if (ccb.drawContext.equals(context) && !ccb.isHex) {
586-
toDelete.add(ccb);
587-
}
588-
}
585+
toDelete = colorBoxes.get(i).stream()
586+
.filter(ccb -> ccb.drawContext.equals(context) && !ccb.isHex)
587+
.collect(Collectors.toList());
589588
}
590589
colorBoxes.get(i).removeAll(toDelete);
591590
}

0 commit comments

Comments
 (0)