forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into user-guide
- Loading branch information
Showing
18 changed files
with
169 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package seedu.address.history; | ||
|
||
import seedu.address.history.exceptions.HistoryException; | ||
|
||
/** | ||
* The `BufferedHistory` class manages the history of states in the ConnectCare application, with a buffer. | ||
* It allows for rolling back and rolling forward to previous states. | ||
*/ | ||
public interface BufferedHistory<T> extends History<T> { | ||
public T getCurrStateHasBuffer() throws HistoryException; | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/seedu/address/history/BufferedHistoryManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package seedu.address.history; | ||
|
||
import seedu.address.history.exceptions.HistoryException; | ||
|
||
/** | ||
* @param <T> The type of state that the abstract class keeps track of | ||
*/ | ||
public class BufferedHistoryManager<T> extends HistoryManager<T> implements BufferedHistory<T> { | ||
|
||
/** | ||
* Constructs a new HistoryManager with a starting state. | ||
* | ||
* @param startState The initial state of the history. | ||
*/ | ||
public BufferedHistoryManager(T startState) { | ||
super(startState); | ||
} | ||
|
||
@Override | ||
public void addState(T state) { | ||
pullForwardPointer(); | ||
T buffer = states.get(states.size() - 1); | ||
states.remove(states.size() - 1); | ||
states.add(state); | ||
states.add(buffer); | ||
currStateIdx++; | ||
} | ||
|
||
private void pullForwardPointer() { | ||
currStateIdx = states.size() - 1; | ||
} | ||
|
||
@Override | ||
public T getCurrStateHasBuffer() throws HistoryException { | ||
if (currStateIdx == states.size() - 1) { | ||
throw new HistoryException("Cannot read from buffer"); | ||
} | ||
return states.get(currStateIdx); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 3 additions & 34 deletions
37
src/main/java/seedu/address/model/person/AddressContainsKeywordsPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,18 @@ | ||
package seedu.address.model.person; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import seedu.address.commons.util.StringUtil; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
|
||
/** | ||
* Tests that a {@code Person}'s {@code Address} matches any of the keywords given. | ||
*/ | ||
public class AddressContainsKeywordsPredicate implements Predicate<Person> { | ||
private final List<String> keywords; | ||
public class AddressContainsKeywordsPredicate extends KeywordMatcherPredicate { | ||
|
||
public AddressContainsKeywordsPredicate(List<String> keywords) { | ||
this.keywords = keywords; | ||
super(keywords); | ||
} | ||
|
||
@Override | ||
public boolean test(Person person) { | ||
if (keywords.isEmpty()) { | ||
return false; | ||
} | ||
boolean personmatches = keywords.stream() | ||
.anyMatch( | ||
keyword -> StringUtil.containsWordIgnoreCase(person.getAddress().get().toString(), keyword)); | ||
return personmatches; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AddressContainsKeywordsPredicate)) { | ||
return false; | ||
} | ||
|
||
AddressContainsKeywordsPredicate otherAddContainsKeywordsPredicate = (AddressContainsKeywordsPredicate) other; | ||
return keywords.equals(otherAddContainsKeywordsPredicate.keywords); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this).add("keywords", keywords).toString(); | ||
return super.matchesKeywords(person.getAddress().get().toString()); | ||
} | ||
} |
36 changes: 3 additions & 33 deletions
36
src/main/java/seedu/address/model/person/DescriptionContainsKeywordsPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,20 @@ | ||
package seedu.address.model.person; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import seedu.address.commons.util.StringUtil; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
|
||
/** | ||
* Tests that a {@code Person}'s {@code Description} matches any of the | ||
* keywords given. | ||
*/ | ||
public class DescriptionContainsKeywordsPredicate implements Predicate<Person> { | ||
private final List<String> keywords; | ||
public class DescriptionContainsKeywordsPredicate extends KeywordMatcherPredicate { | ||
|
||
public DescriptionContainsKeywordsPredicate(List<String> keywords) { | ||
this.keywords = keywords; | ||
super(keywords); | ||
} | ||
|
||
@Override | ||
public boolean test(Person person) { | ||
if (keywords.isEmpty()) { | ||
return false; | ||
} | ||
boolean personmatches = keywords.stream() | ||
.anyMatch( | ||
keyword -> StringUtil.containsWordIgnoreCase(person.getDescription().get().toString(), keyword)); | ||
return personmatches; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof DescriptionContainsKeywordsPredicate)) { | ||
return false; | ||
} | ||
|
||
DescriptionContainsKeywordsPredicate otherDescPredicate = (DescriptionContainsKeywordsPredicate) other; | ||
return keywords.equals(otherDescPredicate.keywords); | ||
return super.matchesKeywords(person.getDescription().get().toString()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this).add("keywords", keywords).toString(); | ||
} | ||
} |
Oops, something went wrong.