Skip to content

Instantly share code, notes, and snippets.

@rowillia
Created September 1, 2015 17:56
Show Gist options
  • Save rowillia/248c1b1eaa70b00dc788 to your computer and use it in GitHub Desktop.
Save rowillia/248c1b1eaa70b00dc788 to your computer and use it in GitHub Desktop.
package infer_test;
public class Test {
public static final String[] PREFIXES = {"A", "B"};
private String currentValue;
private String newerValue;
private static class Strings {
public static boolean isNullOrBlank(String string) {
return string == null || string.trim().length() == 0;
}
public static boolean hasAnyPrefix(String newerValue, String... prefixes) {
if (newerValue == null) {
return false;
}
for (String prefix : prefixes) {
if (newerValue.startsWith(prefix)) {
return true;
}
}
return false;
}
}
public String getValue() {
if (Strings.isNullOrBlank(currentValue) && !Strings.isNullOrBlank(newerValue)) {
if (Strings.hasAnyPrefix(newerValue, PREFIXES)) {
return "a";
}
}
return newerValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment