Skip to content

Commit

Permalink
Merge pull request #73 from wilfredbtan/master
Browse files Browse the repository at this point in the history
Resolved conflicts between AddCommand, EditCommand, ListCommand. Pass Tests except List Tests
  • Loading branch information
wilfredbtan committed Oct 17, 2019
2 parents 7af1826 + 5000861 commit 14b14a9
Show file tree
Hide file tree
Showing 37 changed files with 470 additions and 662 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class MainApp extends Application {

@Override
public void init() throws Exception {
logger.info("=============================[ Initializing AddressBook ]===========================");
logger.info("=============================[ Initializing Revision Tool ]===========================");
super.init();

AppParameters appParameters = AppParameters.parse(getParameters());
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_QUESTION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DIFFICULTY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
Expand All @@ -21,14 +20,12 @@ public class AddCommand extends Command {
+ "Parameters: "
+ PREFIX_QUESTION + "QUESTION "
+ PREFIX_DIFFICULTY + "DIFFICULTY "
+ PREFIX_CATEGORY + "CATEGORY "
+ "[" + PREFIX_TAG + "category]...\n"
+ "[" + PREFIX_CATEGORY + "category]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_QUESTION + "Which of the following is a valid sequence diagram? "
+ PREFIX_DIFFICULTY + "3 "
+ PREFIX_CATEGORY + "UML "
+ PREFIX_TAG + "UML "
+ PREFIX_TAG + "graphical";
+ PREFIX_CATEGORY + "graphical";

public static final String MESSAGE_SUCCESS = "New question added: %1$s";
public static final String MESSAGE_DUPLICATE_ANSWERABLE = "This question already exists in the test bank";
Expand Down
59 changes: 26 additions & 33 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_QUESTION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DIFFICULTY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_ANSWERABLE;

import java.util.Collections;
Expand All @@ -22,7 +21,6 @@
import seedu.address.model.answerable.Answerable;
import seedu.address.model.answerable.Difficulty;
import seedu.address.model.answerable.Mcq;
import seedu.address.model.answerable.AnswerSet;
import seedu.address.model.answerable.Question;
import seedu.address.model.category.Category;

Expand All @@ -40,7 +38,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_QUESTION + "QUESTION] "
+ "[" + PREFIX_DIFFICULTY + "DIFFICULTY] "
+ "[" + PREFIX_CATEGORY + "ADDRESS] "
+ "[" + PREFIX_TAG + "category]...\n"
+ "[" + PREFIX_CATEGORY + "category]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_DIFFICULTY + "91234567 ";

Expand Down Expand Up @@ -92,14 +90,17 @@ private static Answerable createEditedAnswerable(Answerable answerableToEdit, Ed
assert answerableToEdit != null;

Question updatedQuestion = editAnswerableDescriptor.getQuestion().orElse(answerableToEdit.getQuestion());
AnswerSet updatedAnswerSet = editAnswerableDescriptor.getAnswerSet().orElse(answerableToEdit.getAnswerSet());
Difficulty updatedDifficulty = editAnswerableDescriptor.getDifficulty().orElse(answerableToEdit.getDifficulty());
Set<Category> updatedCategories = editAnswerableDescriptor.getCategories().orElse(answerableToEdit.getCategories());


AnswerSet mcqAnswer = (AnswerSet) updatedAnswerSet;

return new Mcq(updatedQuestion, mcqAnswer, updatedDifficulty, updatedCategories);
Set<Answer> updatedCorrectAnswerSet = editAnswerableDescriptor.getCorrectAnswerSet()
.orElse(answerableToEdit.getCorrectAnswerSet());
Set<Answer> updatedWrongAnswerSet = editAnswerableDescriptor.getWrongAnswerSet()
.orElse(answerableToEdit.getWrongAnswerSet());
Difficulty updatedDifficulty = editAnswerableDescriptor.getDifficulty().orElse(answerableToEdit
.getDifficulty());
Set<Category> updatedCategories = editAnswerableDescriptor.getCategories().orElse(answerableToEdit
.getCategories());

return new Mcq(updatedQuestion, updatedCorrectAnswerSet, updatedWrongAnswerSet, updatedDifficulty,
updatedCategories);
}

@Override
Expand All @@ -126,12 +127,12 @@ public boolean equals(Object other) {
*/
public static class EditAnswerableDescriptor {
private Question question;
private AnswerSet answerSet;
private Set<Answer> correctAnswerSet;
private Set<Answer> wrongAnswerSet;
private Difficulty difficulty;
private Set<Category> categories;

public EditAnswerableDescriptor() {
// answerSet = new AnswerSet();
}

/**
Expand All @@ -140,7 +141,8 @@ public EditAnswerableDescriptor() {
*/
public EditAnswerableDescriptor(EditAnswerableDescriptor toCopy) {
setQuestion(toCopy.question);
setAnswerSet(toCopy.answerSet);
setCorrectAnswerSet(toCopy.correctAnswerSet);
setWrongAnswerSet(toCopy.wrongAnswerSet);
setDifficulty(toCopy.difficulty);
setCategories(toCopy.categories);
}
Expand All @@ -149,7 +151,7 @@ public EditAnswerableDescriptor(EditAnswerableDescriptor toCopy) {
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(question, answerSet, difficulty, categories);
return CollectionUtil.isAnyNonNull(question, correctAnswerSet, wrongAnswerSet, difficulty, categories);
}

public void setQuestion(Question question) {
Expand All @@ -160,30 +162,20 @@ public Optional<Question> getQuestion() {
return Optional.ofNullable(question);
}

public void setAnswerSet(AnswerSet answerSet) {
this.answerSet = answerSet;
public void setCorrectAnswerSet(Set<Answer> correctAnswerSet) {
this.correctAnswerSet = correctAnswerSet;
}

public void setCorrectAnswerSet(Set<Answer> correctAnswerSet) {
if (answerSet == null) {
this.answerSet = new AnswerSet();
this.answerSet.setCorrectAnswerSet(correctAnswerSet);
} else {
this.answerSet.setCorrectAnswerSet(correctAnswerSet);
}
public Optional<Set<Answer>> getCorrectAnswerSet() {
return Optional.ofNullable(correctAnswerSet);
}

public void setWrongAnswerSet(Set<Answer> wrongAnswerSet) {
if (answerSet == null) {
this.answerSet = new AnswerSet();
this.answerSet.setWrongAnswerSet(wrongAnswerSet);
} else {
this.answerSet.setWrongAnswerSet(wrongAnswerSet);
}
this.wrongAnswerSet = wrongAnswerSet;
}

public Optional<AnswerSet> getAnswerSet() {
return Optional.ofNullable(answerSet);
public Optional<Set<Answer>> getWrongAnswerSet() {
return Optional.ofNullable(wrongAnswerSet);
}

public void setDifficulty(Difficulty difficulty) {
Expand Down Expand Up @@ -224,7 +216,8 @@ public boolean equals(Object other) {
EditAnswerableDescriptor e = (EditAnswerableDescriptor) other;

return getQuestion().equals(e.getQuestion())
&& getAnswerSet().equals(e.getAnswerSet())
&& getCorrectAnswerSet().equals(e.getCorrectAnswerSet())
&& getWrongAnswerSet().equals(e.getWrongAnswerSet())
&& getDifficulty().equals(e.getDifficulty())
&& getCategories().equals(e.getCategories());
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,23 @@ public class ListCommand extends Command {
+ PREFIX_CATEGORY + "UML "
+ PREFIX_DIFFICULTY + "2 ";


public static final String MESSAGE_SUCCESS = "Listed all answerables";

private final CategoryPredicate categoryPredicate;
private final DifficultyPredicate difficultyPredicate;
private CategoryPredicate categoryPredicate;
private DifficultyPredicate difficultyPredicate;

public ListCommand(CategoryPredicate categoryPredicate, DifficultyPredicate difficultyPredicate) {
this.categoryPredicate = categoryPredicate;
this.difficultyPredicate = difficultyPredicate;
}

public ListCommand(CategoryPredicate categoryPredicate) {
this.categoryPredicate = categoryPredicate;
}

public ListCommand(DifficultyPredicate difficultyPredicate) {
this.difficultyPredicate = difficultyPredicate;
}

@Override
public CommandResult execute(Model model) {
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_QUESTION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_QUESTION_TYPE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DIFFICULTY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_WRONG;

import java.util.Set;
Expand All @@ -18,7 +17,6 @@
import seedu.address.model.answerable.Answerable;
import seedu.address.model.answerable.Difficulty;
import seedu.address.model.answerable.Mcq;
import seedu.address.model.answerable.AnswerSet;
import seedu.address.model.answerable.Question;
import seedu.address.model.category.Category;

Expand All @@ -35,7 +33,7 @@ public class AddCommandParser implements Parser<AddCommand> {
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_QUESTION_TYPE, PREFIX_QUESTION, PREFIX_CORRECT, PREFIX_WRONG,
PREFIX_DIFFICULTY, PREFIX_CATEGORY, PREFIX_TAG);
PREFIX_DIFFICULTY, PREFIX_CATEGORY);

if (!arePrefixesPresent(argMultimap, PREFIX_QUESTION, PREFIX_CORRECT, PREFIX_WRONG, PREFIX_CATEGORY,
PREFIX_DIFFICULTY) || !argMultimap.getPreamble().isEmpty()) {
Expand All @@ -47,19 +45,17 @@ public AddCommand parse(String args) throws ParseException {
Set<Answer> correctAnswerSet = ParserUtil.parseAnswers(argMultimap.getAllValues(PREFIX_CORRECT));
Set<Answer> wrongAnswerSetSet = ParserUtil.parseAnswers(argMultimap.getAllValues(PREFIX_WRONG));
Difficulty difficulty = ParserUtil.parseDifficulty(argMultimap.getValue(PREFIX_DIFFICULTY).get());
Set<Category> categoryList = ParserUtil.parseCategories(argMultimap.getAllValues(PREFIX_CATEGORY));
Set<Category> categories = ParserUtil.parseCategories(argMultimap.getAllValues(PREFIX_CATEGORY));

Answerable answerable;

switch (questionType.getType()) {
case "mcq":
AnswerSet mcqAnswers = new AnswerSet(correctAnswerSet, wrongAnswerSetSet);
answerable = new Mcq(question, mcqAnswers, difficulty, categoryList);
answerable = new Mcq(question, correctAnswerSet, wrongAnswerSetSet, difficulty, categories);
return new AddCommand(answerable);
// case "saq":
// //TODO: Implement Saq
// AnswerSet saqAnswers = new AnswerSet(); //stub
// answerable = new Saq(question, saqAnswers, difficulty, category, tagList);
// answerable = new Saq(question, correctAnsweSet, difficulty, category, tagList);
// return new AddCommand(answerable);
default:
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
Expand Down
1 change: 0 additions & 1 deletion src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ public class CliSyntax {
public static final Prefix PREFIX_WRONG = new Prefix("x/");
public static final Prefix PREFIX_DIFFICULTY = new Prefix("diff/");
public static final Prefix PREFIX_CATEGORY = new Prefix("cat/");
public static final Prefix PREFIX_TAG = new Prefix("t/");

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_DIFFICULTY).isPresent()) {
editAnswerableDescriptor.setDifficulty(ParserUtil.parseDifficulty(argMultimap.getValue(PREFIX_DIFFICULTY).get()));
}


parseCategoriesForEdit(argMultimap.getAllValues(PREFIX_CATEGORY)).ifPresent(editAnswerableDescriptor::setCategories);

Expand All @@ -79,8 +78,7 @@ private Optional<Set<Category>> parseCategoriesForEdit(Collection<String> catego
if (categories.isEmpty()) {
return Optional.empty();
}
Collection<String> categorySet = categories.size() == 1 && categories.contains("") ? Collections.emptySet() : categories;
return Optional.of(ParserUtil.parseCategories(categorySet));
return Optional.of(ParserUtil.parseCategories(categories));
}

}
80 changes: 0 additions & 80 deletions src/main/java/seedu/address/model/answerable/AnswerSet.java

This file was deleted.

Loading

0 comments on commit 14b14a9

Please sign in to comment.