suggested refactor
This commit is contained in:
parent
8c18214c55
commit
2a308c51cb
@ -15,8 +15,7 @@ public class MatchWords {
|
|||||||
public static boolean containsWordsIndexOf(String inputString, String[] words) {
|
public static boolean containsWordsIndexOf(String inputString, String[] words) {
|
||||||
boolean found = true;
|
boolean found = true;
|
||||||
for (String word : words) {
|
for (String word : words) {
|
||||||
int index = inputString.indexOf(word);
|
if (inputString.indexOf(word) == -1) {
|
||||||
if (index == -1) {
|
|
||||||
found = false;
|
found = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -64,21 +63,19 @@ public class MatchWords {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Pattern pattern = Pattern.compile(regexp.toString());
|
Pattern pattern = Pattern.compile(regexp.toString());
|
||||||
if (pattern.matcher(inputString).find()) {
|
|
||||||
return true;
|
return pattern.matcher(inputString).find();
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean containsWordsJava8(String inputString, String[] words) {
|
public static boolean containsWordsJava8(String inputString, String[] words) {
|
||||||
List inputStringList = Arrays.asList(inputString.split(" "));
|
List<String> inputStringList = Arrays.asList(inputString.split(" "));
|
||||||
List<String> wordsList = Arrays.asList(words);
|
List<String> wordsList = Arrays.asList(words);
|
||||||
|
|
||||||
return wordsList.stream().allMatch(inputStringList::contains);
|
return wordsList.stream().allMatch(inputStringList::contains);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean containsWordsArray(String inputString, String[] words) {
|
public static boolean containsWordsArray(String inputString, String[] words) {
|
||||||
List inputStringList = Arrays.asList(inputString.split(" "));
|
List<String> inputStringList = Arrays.asList(inputString.split(" "));
|
||||||
List<String> wordsList = Arrays.asList(words);
|
List<String> wordsList = Arrays.asList(words);
|
||||||
|
|
||||||
return inputStringList.containsAll(wordsList);
|
return inputStringList.containsAll(wordsList);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user