Skip to content

Commit a08908a

Browse files
Pieter12345cmaglie
authored andcommitted
Replace StringUtils.stringContainsOneOf() with library call
Use Apache commons.lang3 instead of own implementation.
1 parent e6e10cd commit a08908a

File tree

2 files changed

+10
-35
lines changed

2 files changed

+10
-35
lines changed

arduino-core/src/cc/arduino/packages/Uploader.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,35 @@
3737
import processing.app.debug.MessageConsumer;
3838
import processing.app.debug.MessageSiphon;
3939
import processing.app.helpers.ProcessUtils;
40-
import processing.app.helpers.StringUtils;
4140

4241
import java.io.File;
43-
import java.util.Arrays;
4442
import java.util.Collection;
4543
import java.util.List;
4644
import java.util.concurrent.TimeUnit;
4745

46+
import org.apache.commons.lang3.StringUtils;
47+
4848
import static processing.app.I18n.tr;
4949

5050
public abstract class Uploader implements MessageConsumer {
5151

52-
private static final List<String> STRINGS_TO_SUPPRESS;
53-
private static final List<String> AVRDUDE_PROBLEMS;
52+
private static final String[] STRINGS_TO_SUPPRESS;
53+
private static final String[] AVRDUDE_PROBLEMS;
5454

5555
static {
56-
STRINGS_TO_SUPPRESS = Arrays.asList("Connecting to programmer:",
56+
STRINGS_TO_SUPPRESS = new String[] {"Connecting to programmer:",
5757
"Found programmer: Id = \"CATERIN\"; type = S",
5858
"Software Version = 1.0; No Hardware Version given.",
5959
"Programmer supports auto addr increment.",
6060
"Programmer supports buffered memory access with buffersize=128 bytes.",
61-
"Programmer supports the following devices:", "Device code: 0x44");
61+
"Programmer supports the following devices:", "Device code: 0x44"};
6262

63-
AVRDUDE_PROBLEMS = Arrays.asList("Programmer is not responding",
63+
AVRDUDE_PROBLEMS = new String[] {"Programmer is not responding",
6464
"programmer is not responding",
6565
"protocol error", "avrdude: ser_open(): can't open device",
6666
"avrdude: ser_drain(): read error",
6767
"avrdude: ser_send(): write error",
68-
"avrdude: error: buffered memory access not supported.");
68+
"avrdude: error: buffered memory access not supported."};
6969
}
7070

7171
protected final boolean verbose;
@@ -155,7 +155,7 @@ public String getFailureMessage() {
155155
@Override
156156
public void message(String s) {
157157
// selectively suppress a bunch of avrdude output for AVR109/Caterina that should already be quelled but isn't
158-
if (!verbose && StringUtils.stringContainsOneOf(s, STRINGS_TO_SUPPRESS)) {
158+
if (!verbose && StringUtils.containsAny(s, STRINGS_TO_SUPPRESS)) {
159159
s = "";
160160
}
161161

@@ -175,7 +175,7 @@ public void message(String s) {
175175
error = tr("Device is not responding, check the right serial port is selected or RESET the board right before exporting");
176176
return;
177177
}
178-
if (StringUtils.stringContainsOneOf(s, AVRDUDE_PROBLEMS)) {
178+
if (StringUtils.containsAny(s, AVRDUDE_PROBLEMS)) {
179179
error = tr("Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.");
180180
return;
181181
}

arduino-core/src/processing/app/helpers/StringUtils.java

-25
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,7 @@
11
package processing.app.helpers;
22

3-
import java.util.List;
4-
53
public class StringUtils {
64

7-
public static boolean stringContainsOneOf(String input, List<String> listOfStrings) {
8-
for (String string : listOfStrings) {
9-
if (input.contains(string)) {
10-
return true;
11-
}
12-
}
13-
return false;
14-
}
15-
16-
/**
17-
* Tries to match <b>input</b> with <b>pattern</b>. The pattern can use the
18-
* "*" and "?" globs to match any-char-sequence and any-char respectively.
19-
*
20-
* @param input The string to be checked
21-
* @param pattern The pattern to match
22-
* @return <b>true</b> if the <b>input</b> matches the <b>pattern</b>,
23-
* <b>false</b> otherwise.
24-
*/
25-
public static boolean wildcardMatch(String input, String pattern) {
26-
String regex = pattern.replace("?", ".?").replace("*", ".*?");
27-
return input.matches(regex);
28-
}
29-
305
/**
316
* Returns the string without trailing whitespace characters
327
*

0 commit comments

Comments
 (0)