Skip to content

Commit

Permalink
Abstract check to StringUtil class
Browse files Browse the repository at this point in the history
  • Loading branch information
jingting1412 committed Oct 16, 2023
1 parent 7e016e1 commit 63b0ab9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/staffsnap/commons/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static boolean containsWordIgnoreCase(String sentence, String word) {
String[] wordsInPreppedSentence = preppedSentence.split("\\s+");

return Arrays.stream(wordsInPreppedSentence)
.anyMatch(preppedWord::equalsIgnoreCase);
.anyMatch(sentenceWord -> sentenceWord.toLowerCase().contains(preppedWord.toLowerCase()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.function.Predicate;

import seedu.staffsnap.commons.util.StringUtil;
import seedu.staffsnap.commons.util.ToStringBuilder;

/**
Expand All @@ -18,7 +19,7 @@ public NameContainsKeywordsPredicate(List<String> keywords) {
@Override
public boolean test(Applicant applicant) {
return keywords.stream()
.anyMatch(keyword -> applicant.getName().fullName.toLowerCase().contains(keyword.toLowerCase()));
.anyMatch(keyword -> StringUtil.containsWordIgnoreCase(applicant.getName().fullName, keyword));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public void containsWordIgnoreCase_validInputs_correctResult() {
assertFalse(StringUtil.containsWordIgnoreCase("", "abc")); // Boundary case
assertFalse(StringUtil.containsWordIgnoreCase(" ", "123"));

// Matches a partial word only
assertFalse(StringUtil.containsWordIgnoreCase("aaa bbb ccc", "bb")); // Sentence word bigger than query word
// Matches a partial word only, returns true under new function
assertTrue(StringUtil.containsWordIgnoreCase("aaa bbb ccc", "bb")); // Sentence word bigger than query word
assertFalse(StringUtil.containsWordIgnoreCase("aaa bbb ccc", "bbbb")); // Query word bigger than sentence word

// Matches word in the sentence, different upper/lower case letters
Expand Down

0 comments on commit 63b0ab9

Please sign in to comment.