1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-02 13:24:12 +01:00

Replace StringUtils.stringContainsOneOf() with library call

Use Apache commons.lang3 instead of own implementation.
This commit is contained in:
Pieter12345 2019-03-21 21:10:08 +01:00 committed by Cristian Maglie
parent e6e10cdeb9
commit a08908a90f
2 changed files with 10 additions and 35 deletions

View File

@ -37,35 +37,35 @@ import processing.app.PreferencesData;
import processing.app.debug.MessageConsumer; import processing.app.debug.MessageConsumer;
import processing.app.debug.MessageSiphon; import processing.app.debug.MessageSiphon;
import processing.app.helpers.ProcessUtils; import processing.app.helpers.ProcessUtils;
import processing.app.helpers.StringUtils;
import java.io.File; import java.io.File;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
import static processing.app.I18n.tr; import static processing.app.I18n.tr;
public abstract class Uploader implements MessageConsumer { public abstract class Uploader implements MessageConsumer {
private static final List<String> STRINGS_TO_SUPPRESS; private static final String[] STRINGS_TO_SUPPRESS;
private static final List<String> AVRDUDE_PROBLEMS; private static final String[] AVRDUDE_PROBLEMS;
static { static {
STRINGS_TO_SUPPRESS = Arrays.asList("Connecting to programmer:", STRINGS_TO_SUPPRESS = new String[] {"Connecting to programmer:",
"Found programmer: Id = \"CATERIN\"; type = S", "Found programmer: Id = \"CATERIN\"; type = S",
"Software Version = 1.0; No Hardware Version given.", "Software Version = 1.0; No Hardware Version given.",
"Programmer supports auto addr increment.", "Programmer supports auto addr increment.",
"Programmer supports buffered memory access with buffersize=128 bytes.", "Programmer supports buffered memory access with buffersize=128 bytes.",
"Programmer supports the following devices:", "Device code: 0x44"); "Programmer supports the following devices:", "Device code: 0x44"};
AVRDUDE_PROBLEMS = Arrays.asList("Programmer is not responding", AVRDUDE_PROBLEMS = new String[] {"Programmer is not responding",
"programmer is not responding", "programmer is not responding",
"protocol error", "avrdude: ser_open(): can't open device", "protocol error", "avrdude: ser_open(): can't open device",
"avrdude: ser_drain(): read error", "avrdude: ser_drain(): read error",
"avrdude: ser_send(): write error", "avrdude: ser_send(): write error",
"avrdude: error: buffered memory access not supported."); "avrdude: error: buffered memory access not supported."};
} }
protected final boolean verbose; protected final boolean verbose;
@ -155,7 +155,7 @@ public abstract class Uploader implements MessageConsumer {
@Override @Override
public void message(String s) { public void message(String s) {
// selectively suppress a bunch of avrdude output for AVR109/Caterina that should already be quelled but isn't // selectively suppress a bunch of avrdude output for AVR109/Caterina that should already be quelled but isn't
if (!verbose && StringUtils.stringContainsOneOf(s, STRINGS_TO_SUPPRESS)) { if (!verbose && StringUtils.containsAny(s, STRINGS_TO_SUPPRESS)) {
s = ""; s = "";
} }
@ -175,7 +175,7 @@ public abstract class Uploader implements MessageConsumer {
error = tr("Device is not responding, check the right serial port is selected or RESET the board right before exporting"); error = tr("Device is not responding, check the right serial port is selected or RESET the board right before exporting");
return; return;
} }
if (StringUtils.stringContainsOneOf(s, AVRDUDE_PROBLEMS)) { if (StringUtils.containsAny(s, AVRDUDE_PROBLEMS)) {
error = tr("Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions."); error = tr("Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.");
return; return;
} }

View File

@ -1,32 +1,7 @@
package processing.app.helpers; package processing.app.helpers;
import java.util.List;
public class StringUtils { public class StringUtils {
public static boolean stringContainsOneOf(String input, List<String> listOfStrings) {
for (String string : listOfStrings) {
if (input.contains(string)) {
return true;
}
}
return false;
}
/**
* Tries to match <b>input</b> with <b>pattern</b>. The pattern can use the
* "*" and "?" globs to match any-char-sequence and any-char respectively.
*
* @param input The string to be checked
* @param pattern The pattern to match
* @return <b>true</b> if the <b>input</b> matches the <b>pattern</b>,
* <b>false</b> otherwise.
*/
public static boolean wildcardMatch(String input, String pattern) {
String regex = pattern.replace("?", ".?").replace("*", ".*?");
return input.matches(regex);
}
/** /**
* Returns the string without trailing whitespace characters * Returns the string without trailing whitespace characters
* *