Skip to content

Commit

Permalink
Merge ee18e6f into ef1dc62
Browse files Browse the repository at this point in the history
  • Loading branch information
teojunjie committed Nov 6, 2018
2 parents ef1dc62 + ee18e6f commit 22f9cce
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 20 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 @@ -104,11 +104,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
return new CommandResult(String.format(MESSAGE_MACHINE_NOT_FLUSHED, machineToManage));
}
} else if (flushAutoOption.equals(OPTION_FLUSH_AUTO)) {
Machine mostFreeMachine = model.getMostFreeMachine();
if (mostFreeMachine.equals(machineToManage)) {
throw new CommandException(MESSAGE_NO_MORE_MACHINES);
}
model.autoMoveJobs(machineToManage, mostFreeMachine);
model.autoMoveJobs(machineToManage);
model.updateFilteredMachineList(PREDICATE_SHOW_ALL_MACHINES);
model.updateFilteredJobListInAllMachines(PREDICATE_SHOW_ALL_JOBS);
return new CommandResult(String.format(MESSAGE_AUTO_FLUSHING_MACHINE, machineToManage));
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)));
}

}
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.function.Predicate;

import javafx.collections.ObservableList;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.admin.Admin;
import seedu.address.model.admin.Username;
import seedu.address.model.job.Job;
Expand Down Expand Up @@ -94,7 +95,7 @@ public interface Model {

void moveJobToMachine(Job job, Machine targetMachine);

void autoMoveJobs(Machine currentMachine, Machine targetMachine);
void autoMoveJobs(Machine currentMachine) throws CommandException;

// ============================== Machine methods ======================================= //
/**
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
import static seedu.address.logic.commands.machine.ManageMachineCommand.MESSAGE_NO_MORE_MACHINES;

import java.util.Timer;
import java.util.TimerTask;
Expand All @@ -18,6 +19,7 @@
import seedu.address.commons.events.model.AdminListChangedEvent;
import seedu.address.commons.events.model.JobListChangedEvent;
import seedu.address.commons.events.model.MachineListChangedEvent;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.admin.Admin;
import seedu.address.model.admin.Username;
import seedu.address.model.job.Job;
Expand Down Expand Up @@ -259,9 +261,13 @@ public void moveJobToMachine(Job job, Machine targetMachine) {
}

@Override
public void autoMoveJobs(Machine currentMachine, Machine targetMachine) {
public void autoMoveJobs(Machine currentMachine) throws CommandException {
for (Job j : currentMachine.getJobs()) {
moveJobToMachine(j, targetMachine);
Machine mostFreeMachine = getMostFreeMachine();
if (mostFreeMachine.equals(currentMachine)) {
throw new CommandException(MESSAGE_NO_MORE_MACHINES);
}
moveJobToMachine(j, mostFreeMachine);
}
flushMachine(currentMachine);
indicateMachineListChanged();
Expand Down
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void moveJobToMachine(Job job, Machine targetMachine) {
}

@Override
public void autoMoveJobs(Machine currentMachine, Machine targetMachine) {
public void autoMoveJobs(Machine currentMachine) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public void moveJobToMachine(Job job, Machine targetMachine) {
}

@Override
public void autoMoveJobs(Machine currentMachine, Machine targetMachine) {
public void autoMoveJobs(Machine currentMachine) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void moveJobToMachine(Job job, Machine targetMachine) {
}

@Override
public void autoMoveJobs(Machine currentMachine, Machine targetMachine) {
public void autoMoveJobs(Machine currentMachine) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void moveJobToMachine(Job job, Machine targetMachine) {
}

@Override
public void autoMoveJobs(Machine currentMachine, Machine targetMachine) {
public void autoMoveJobs(Machine currentMachine) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void moveJobToMachine(Job job, Machine targetMachine) {
}

@Override
public void autoMoveJobs(Machine currentMachine, Machine targetMachine) {
public void autoMoveJobs(Machine currentMachine) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void moveJobToMachine(Job job, Machine targetMachine) {
}

@Override
public void autoMoveJobs(Machine currentMachine, Machine targetMachine) {
public void autoMoveJobs(Machine currentMachine) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void moveJobToMachine(Job job, Machine targetMachine) {
}

@Override
public void autoMoveJobs(Machine currentMachine, Machine targetMachine) {
public void autoMoveJobs(Machine currentMachine) {

}

Expand Down

0 comments on commit 22f9cce

Please sign in to comment.