From 39b00669d968ec533deb62573f43a395590f6d49 Mon Sep 17 00:00:00 2001 From: jessica2828 Date: Mon, 11 Nov 2024 07:50:35 +0800 Subject: [PATCH] Update module filter matching --- .../model/person/ModuleContainsKeywordsPredicate.java | 11 ++++++----- .../person/ModuleContainsKeywordsPredicateTest.java | 3 --- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/seedu/address/model/person/ModuleContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/person/ModuleContainsKeywordsPredicate.java index efa638e3209..ff1af354012 100644 --- a/src/main/java/seedu/address/model/person/ModuleContainsKeywordsPredicate.java +++ b/src/main/java/seedu/address/model/person/ModuleContainsKeywordsPredicate.java @@ -14,11 +14,12 @@ public ModuleContainsKeywordsPredicate(String keyword) { this.keyword = keyword; } - @Override - public boolean test(Person person) { - return person.getModules().stream() - .anyMatch(module -> module.toString().toLowerCase().contains(keyword.toLowerCase())); - } +@Override +public boolean test(Person person) { + String regex = "\\b" + keyword.toLowerCase() + "\\b"; + return person.getModules().stream() + .anyMatch(module -> module.toString().toLowerCase().matches(".*" + regex + ".*")); +} @Override public boolean equals(Object other) { diff --git a/src/test/java/seedu/address/model/person/ModuleContainsKeywordsPredicateTest.java b/src/test/java/seedu/address/model/person/ModuleContainsKeywordsPredicateTest.java index 0b3680ee138..ec5b61d9491 100644 --- a/src/test/java/seedu/address/model/person/ModuleContainsKeywordsPredicateTest.java +++ b/src/test/java/seedu/address/model/person/ModuleContainsKeywordsPredicateTest.java @@ -45,9 +45,6 @@ public void test_moduleContainsKeyword_returnsTrue() { predicate = new ModuleContainsKeywordsPredicate("cs1010"); assertTrue(predicate.test(new PersonBuilder().addUngradedModule("CS1010").build())); - - predicate = new ModuleContainsKeywordsPredicate("1010"); - assertTrue(predicate.test(new PersonBuilder().addUngradedModule("CS1010").build())); } @Test