Skip to content

Commit

Permalink
Merge 9794d8d into ef1dc62
Browse files Browse the repository at this point in the history
  • Loading branch information
teojunjie committed Nov 5, 2018
2 parents ef1dc62 + 9794d8d commit 733c574
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ dependencies {
implementation group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.3.0'
implementation group: 'javax.activation', name: 'activation', version: '1.1.1'

implementation 'me.xdrop:fuzzywuzzy:1.2.0'
implementation group: 'org.mindrot', name: 'jbcrypt', version: '0.4'


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import seedu.address.logic.commands.CommandResult;
import seedu.address.model.Model;
import seedu.address.model.machine.MachineNameContainsKeywordsPredicate;


import seedu.address.model.machine.MachineNameFuzzyWuzzyPredicate;


/**
Expand All @@ -26,15 +25,21 @@ public class FindMachineCommand extends Command {
+ "Example: " + COMMAND_WORD + " machine1 machine2 machine3";

private final MachineNameContainsKeywordsPredicate predicate;
private final MachineNameFuzzyWuzzyPredicate fuzzyWuzzyPredicate;

public FindMachineCommand(MachineNameContainsKeywordsPredicate predicate) {
public FindMachineCommand(MachineNameContainsKeywordsPredicate predicate,
MachineNameFuzzyWuzzyPredicate fuzzyWuzzyPredicate) {
this.predicate = predicate;
this.fuzzyWuzzyPredicate = fuzzyWuzzyPredicate;
}

@Override
public CommandResult execute(Model model, CommandHistory history) {
requireNonNull(model);
model.updateFilteredMachineList(predicate);
if (model.getFilteredMachineList().size() < predicate.getNumberOfKeywords()) {
model.updateFilteredMachineList(fuzzyWuzzyPredicate);
}
return new CommandResult(
String.format(Messages.MESSAGE_MACHINE_LISTED_OVERVIEW, model.getFilteredMachineList().size()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seedu.address.logic.parser.Parser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.machine.MachineNameContainsKeywordsPredicate;
import seedu.address.model.machine.MachineNameFuzzyWuzzyPredicate;

/**
* Parses input arguments and creates a new FindMachineCommand object
Expand All @@ -28,7 +29,8 @@ public FindMachineCommand parse(String args) throws ParseException {

String[] nameKeywords = trimmedArgs.split("\\s+");

return new FindMachineCommand(new MachineNameContainsKeywordsPredicate(Arrays.asList(nameKeywords)));
return new FindMachineCommand(new MachineNameContainsKeywordsPredicate(Arrays.asList(nameKeywords)),
new MachineNameFuzzyWuzzyPredicate(Arrays.asList(nameKeywords)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
public class MachineNameContainsKeywordsPredicate implements Predicate<Machine> {
private final List<String> keywords;


public MachineNameContainsKeywordsPredicate(List<String> keywords) {
this.keywords = keywords;
}

public Integer getNumberOfKeywords () {
return keywords.size();
}

@Override
public boolean test(Machine machine) {
return keywords.stream()
.anyMatch(keyword -> StringUtil.containsWordIgnoreCase(machine.getName().fullName, keyword));
.anyMatch(keyword -> StringUtil.containsWordIgnoreCase(machine.getName().fullName, keyword));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package seedu.address.model.machine;

import java.util.List;
import java.util.function.Predicate;

import me.xdrop.fuzzywuzzy.FuzzySearch;

/**
* Tests that a {@code Machines}'s {@code Name} fufills the fuzzywuzzy minimum ration.
*/
public class MachineNameFuzzyWuzzyPredicate implements Predicate<Machine> {

private final List<String> keywords;

public MachineNameFuzzyWuzzyPredicate(List<String> keywords) {
this.keywords = keywords;
}

@Override
public boolean test(Machine machine) {
return keywords.stream()
.anyMatch(keyword -> FuzzySearch.partialRatio(machine.getName().fullName, keyword) > 50);
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof MachineNameFuzzyWuzzyPredicate // instanceof handles nulls
&& keywords.equals(((MachineNameFuzzyWuzzyPredicate) other).keywords)); // state check
}
}

0 comments on commit 733c574

Please sign in to comment.