Skip to content

Commit fbb61ff

Browse files
author
Federico Fissore
committed
Code cleanup
1 parent 88e8019 commit fbb61ff

13 files changed

+28
-39
lines changed

arduino-core/src/cc/arduino/contributions/GZippedJsonDownloader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private void decompress(File gzipTmpFile, File tmpFile) throws IOException {
6767
os = new FileOutputStream(tmpFile);
6868
gzipIs = new GzipCompressorInputStream(new FileInputStream(gzipTmpFile));
6969
final byte[] buffer = new byte[4096];
70-
int n = 0;
70+
int n;
7171
while (-1 != (n = gzipIs.read(buffer))) {
7272
os.write(buffer, 0, n);
7373
}

arduino-core/src/cc/arduino/contributions/JsonDownloader.java

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public void download(File tmpFile, Progress progress, String statusText) throws
4949
downloader.download(url, tmpFile, progress, statusText);
5050
} catch (InterruptedException e) {
5151
// Download interrupted... just exit
52-
return;
5352
}
5453
}
5554
}

arduino-core/src/cc/arduino/contributions/libraries/ContributedLibrary.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public boolean equals(Object obj) {
142142
String thisVersion = getParsedVersion();
143143
String otherVersion = ((ContributedLibrary) obj).getParsedVersion();
144144

145-
boolean versionEquals = thisVersion == otherVersion || (thisVersion != null && otherVersion != null && thisVersion.equals(otherVersion));
145+
boolean versionEquals = thisVersion != null && otherVersion != null && thisVersion.equals(otherVersion);
146146

147147
String thisName = getName();
148148
String otherName = ((ContributedLibrary) obj).getName();

arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public void updateIndex() throws Exception {
7979
final MultiStepProgress progress = new MultiStepProgress(2);
8080

8181
// Step 1: Download index
82-
URL url = new URL(LIBRARY_INDEX_URL);
8382
File outputFile = indexer.getIndexFile();
8483
File tmpFile = new File(outputFile.getAbsolutePath() + ".tmp");
8584
try {

arduino-core/src/cc/arduino/packages/discoverers/NetworkDiscovery.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ public class NetworkDiscovery implements Discovery, ServiceListener, cc.arduino.
5656

5757
public NetworkDiscovery() {
5858
DNSTaskStarter.Factory.setClassDelegate(new ArduinoDNSTaskStarter());
59-
this.boardPortsDiscoveredWithJmDNS = new LinkedList<BoardPort>();
60-
this.mappedJmDNSs = new Hashtable<InetAddress, JmDNS>();
61-
this.reachableBoardPorts = new LinkedList<BoardPort>();
59+
this.boardPortsDiscoveredWithJmDNS = new LinkedList<>();
60+
this.mappedJmDNSs = new Hashtable<>();
61+
this.reachableBoardPorts = new LinkedList<>();
6262
}
6363

6464
@Override
6565
public List<BoardPort> listDiscoveredBoards() {
6666
synchronized (reachableBoardPorts) {
67-
return new LinkedList<BoardPort>(reachableBoardPorts);
67+
return new LinkedList<>(reachableBoardPorts);
6868
}
6969
}
7070

@@ -77,7 +77,7 @@ public void setReachableBoardPorts(List<BoardPort> newReachableBoardPorts) {
7777

7878
public List<BoardPort> getBoardPortsDiscoveredWithJmDNS() {
7979
synchronized (boardPortsDiscoveredWithJmDNS) {
80-
return new LinkedList<BoardPort>(boardPortsDiscoveredWithJmDNS);
80+
return new LinkedList<>(boardPortsDiscoveredWithJmDNS);
8181
}
8282
}
8383

@@ -114,11 +114,7 @@ public void serviceAdded(ServiceEvent serviceEvent) {
114114
public void serviceRemoved(ServiceEvent serviceEvent) {
115115
String name = serviceEvent.getName();
116116
synchronized (boardPortsDiscoveredWithJmDNS) {
117-
for (BoardPort port : boardPortsDiscoveredWithJmDNS) {
118-
if (port.getBoardName().equals(name)) {
119-
boardPortsDiscoveredWithJmDNS.remove(port);
120-
}
121-
}
117+
boardPortsDiscoveredWithJmDNS.stream().filter(port -> port.getBoardName().equals(name)).forEach(boardPortsDiscoveredWithJmDNS::remove);
122118
}
123119
}
124120

arduino-core/src/cc/arduino/packages/discoverers/SerialDiscovery.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ public class SerialDiscovery implements Discovery {
4343
private final List<BoardPort> serialBoardPorts;
4444

4545
public SerialDiscovery() {
46-
this.serialBoardPorts = new LinkedList<BoardPort>();
46+
this.serialBoardPorts = new LinkedList<>();
4747
}
4848

4949
@Override
5050
public List<BoardPort> listDiscoveredBoards() {
5151
return getSerialBoardPorts();
5252
}
5353

54-
public List<BoardPort> getSerialBoardPorts() {
54+
private List<BoardPort> getSerialBoardPorts() {
5555
synchronized (serialBoardPorts) {
56-
return new LinkedList<BoardPort>(serialBoardPorts);
56+
return new LinkedList<>(serialBoardPorts);
5757
}
5858
}
5959

arduino-core/src/cc/arduino/packages/discoverers/network/BoardReachabilityFilter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void run() {
6161
InetAddress inetAddress = InetAddress.getByName(board.getAddress());
6262
int broadcastedPort = Integer.valueOf(board.getPrefs().get("port"));
6363

64-
List<Integer> ports = new LinkedList<Integer>();
64+
List<Integer> ports = new LinkedList<>();
6565
ports.add(broadcastedPort);
6666

6767
//dirty code: allows non up to date yuns to be discovered. Newer yuns will broadcast port 22

arduino-core/src/cc/arduino/packages/discoverers/network/NetworkChecker.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public NetworkChecker(NetworkTopologyListener topologyListener, NetworkTopologyD
4444
super();
4545
this.topologyListener = topologyListener;
4646
this.topology = topology;
47-
this.knownAddresses = Collections.synchronizedSet(new HashSet<InetAddress>());
47+
this.knownAddresses = Collections.synchronizedSet(new HashSet<>());
4848
}
4949

5050
public void start(Timer timer) {
@@ -55,18 +55,14 @@ public void start(Timer timer) {
5555
public void run() {
5656
try {
5757
InetAddress[] curentAddresses = topology.getInetAddresses();
58-
Set<InetAddress> current = new HashSet<InetAddress>(curentAddresses.length);
58+
Set<InetAddress> current = new HashSet<>(curentAddresses.length);
5959
for (InetAddress address : curentAddresses) {
6060
current.add(address);
6161
if (!knownAddresses.contains(address)) {
6262
topologyListener.inetAddressAdded(address);
6363
}
6464
}
65-
for (InetAddress address : knownAddresses) {
66-
if (!current.contains(address)) {
67-
topologyListener.inetAddressRemoved(address);
68-
}
69-
}
65+
knownAddresses.stream().filter(address -> !current.contains(address)).forEach(topologyListener::inetAddressRemoved);
7066
knownAddresses = current;
7167
} catch (Exception e) {
7268
e.printStackTrace();

arduino-core/src/cc/arduino/packages/discoverers/serial/SerialBoardsLister.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void run() {
6666
return;
6767
}
6868

69-
List<BoardPort> boardPorts = new LinkedList<BoardPort>();
69+
List<BoardPort> boardPorts = new LinkedList<>();
7070

7171
List<String> ports = Serial.list();
7272

arduino-core/src/cc/arduino/packages/ssh/SCP.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ public void open() throws IOException {
6161
}
6262
}
6363

64-
public void close() throws IOException {
64+
public void close() {
6565
IOUtils.closeQuietly(out);
6666
IOUtils.closeQuietly(in);
6767
if (channel != null) {
6868
channel.disconnect();
6969
}
7070
}
7171

72-
protected void ensureAcknowledged() throws IOException {
72+
private void ensureAcknowledged() throws IOException {
7373
out.flush();
7474

7575
int b = in.read();

arduino-core/src/cc/arduino/packages/ssh/SSH.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
public class SSH {
4343

44-
protected final Session session;
44+
final Session session;
4545

4646
public SSH(Session session) {
4747
this.session = session;
@@ -79,7 +79,7 @@ public boolean execSyncCommand(String command, PrintStream stdoutConsumer, Print
7979
}
8080
}
8181

82-
protected int consumeOutputSyncAndReturnExitCode(Channel channel, InputStream stdout, PrintStream stdoutConsumer, InputStream stderr, PrintStream stderrConsumer) throws IOException {
82+
private int consumeOutputSyncAndReturnExitCode(Channel channel, InputStream stdout, PrintStream stdoutConsumer, InputStream stderr, PrintStream stderrConsumer) throws IOException {
8383
byte[] tmp = new byte[102400];
8484
while (true) {
8585
consumeStream(tmp, stdout, stdoutConsumer);
@@ -96,7 +96,7 @@ protected int consumeOutputSyncAndReturnExitCode(Channel channel, InputStream st
9696
}
9797
}
9898

99-
protected void consumeStream(byte[] buffer, InputStream in, PrintStream out) throws IOException {
99+
private void consumeStream(byte[] buffer, InputStream in, PrintStream out) throws IOException {
100100
while (in.available() > 0) {
101101
int length = in.read(buffer, 0, buffer.length);
102102
if (length < 0) {

arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
7575

7676
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
7777
PreferencesMap prefs = PreferencesData.getMap();
78-
prefs.putAll(BaseNoGui.getBoardPreferences());
78+
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
79+
if (boardPreferences != null) {
80+
prefs.putAll(boardPreferences);
81+
}
7982
String tool = prefs.getOrExcept("upload.tool");
8083
if (tool.contains(":")) {
8184
String[] split = tool.split(":", 2);
@@ -136,11 +139,7 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
136139
throw new RunnerException(e);
137140
} finally {
138141
if (scp != null) {
139-
try {
140-
scp.close();
141-
} catch (IOException e) {
142-
throw new RunnerException(e);
143-
}
142+
scp.close();
144143
}
145144
if (session != null) {
146145
session.disconnect();

arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private String waitForUploadPort(String uploadPort, List<String> before) throws
204204
int elapsed = 0;
205205
while (elapsed < 10000) {
206206
List<String> now = Serial.list();
207-
List<String> diff = new ArrayList<String>(now);
207+
List<String> diff = new ArrayList<>(now);
208208
diff.removeAll(before);
209209
if (verbose) {
210210
System.out.print("PORTS {");
@@ -245,7 +245,7 @@ private String waitForUploadPort(String uploadPort, List<String> before) throws
245245
throw new RunnerException(_("Couldn't find a Board on the selected port. Check that you have the correct port selected. If it is correct, try pressing the board's reset button after initiating the upload."));
246246
}
247247

248-
public boolean uploadUsingProgrammer(String buildPath, String className) throws Exception {
248+
private boolean uploadUsingProgrammer(String buildPath, String className) throws Exception {
249249

250250
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
251251
String programmer = PreferencesData.get("programmer");

0 commit comments

Comments
 (0)