Skip to content

Commit

Permalink
Merge pull request AY2324S1-CS2103T-T13-0#108 from marquestye/info-co…
Browse files Browse the repository at this point in the history
…mmand

Info command and checkstyle fixes
  • Loading branch information
xCOLOURx authored Oct 18, 2023
2 parents f8a02f2 + fadadda commit 0c4e2a8
Show file tree
Hide file tree
Showing 36 changed files with 304 additions and 192 deletions.
32 changes: 16 additions & 16 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.Logic;
import seedu.address.logic.LogicManager;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.UserPrefs;
import seedu.address.model.moduleplan.ReadOnlyModulePlan;
Expand Down Expand Up @@ -76,20 +74,22 @@ public void init() throws Exception {
private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
logger.info("Using data file : " + storage.getAddressBookFilePath());

// Optional<ReadOnlyAddressBook> addressBookOptional;
// ReadOnlyAddressBook initialData;
// try {
// addressBookOptional = storage.readAddressBook();
// if (!addressBookOptional.isPresent()) {
// logger.info("Creating a new data file " + storage.getAddressBookFilePath()
// + " populated with a sample AddressBook.");
// }
// initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
// } catch (DataLoadingException e) {
// logger.warning("Data file at " + storage.getAddressBookFilePath() + " could not be loaded."
// + " Will be starting with an empty AddressBook.");
// initialData = new AddressBook();
// }
/*
Optional<ReadOnlyAddressBook> addressBookOptional;
ReadOnlyAddressBook initialData;
try {
addressBookOptional = storage.readAddressBook();
if (!addressBookOptional.isPresent()) {
logger.info("Creating a new data file " + storage.getAddressBookFilePath()
+ " populated with a sample AddressBook.");
}
initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
} catch (DataLoadingException e) {
logger.warning("Data file at " + storage.getAddressBookFilePath() + " could not be loaded."
+ " Will be starting with an empty AddressBook.");
initialData = new AddressBook();
}
*/

//TODO implement loading from storage for ModulePlan.
ReadOnlyModulePlan initialData = SampleDataUtil.getSampleModulePlan();
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.module.Module;
import seedu.address.model.moduleplan.ModulePlanSemester;
import seedu.address.model.moduleplan.ReadOnlyModulePlan;

Expand Down
21 changes: 9 additions & 12 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package seedu.address.logic;

import java.io.IOException;
import java.nio.file.AccessDeniedException;
import java.nio.file.Path;
import java.util.logging.Logger;

Expand All @@ -11,12 +9,9 @@
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.AddressBookParser;
import seedu.address.logic.parser.ModulePlanParser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.module.Module;
import seedu.address.model.moduleplan.ModulePlanSemester;
import seedu.address.model.moduleplan.ReadOnlyModulePlan;
import seedu.address.storage.Storage;
Expand Down Expand Up @@ -55,13 +50,15 @@ public CommandResult execute(String commandText) throws CommandException, ParseE


//TODO implement save to storage for ModulePlan
// try {
// storage.saveAddressBook(model.getAddressBook());
// } catch (AccessDeniedException e) {
// throw new CommandException(String.format(FILE_OPS_PERMISSION_ERROR_FORMAT, e.getMessage()), e);
// } catch (IOException ioe) {
// throw new CommandException(String.format(FILE_OPS_ERROR_FORMAT, ioe.getMessage()), ioe);
// }
/*
try {
storage.saveAddressBook(model.getAddressBook());
} catch (AccessDeniedException e) {
throw new CommandException(String.format(FILE_OPS_PERMISSION_ERROR_FORMAT, e.getMessage()), e);
} catch (IOException ioe) {
throw new CommandException(String.format(FILE_OPS_ERROR_FORMAT, ioe.getMessage()), ioe);
}
*/

return commandResult;
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.*;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CODE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SEMESTER;
import static seedu.address.logic.parser.CliSyntax.PREFIX_YEAR;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import seedu.address.model.Model;

/**
* Deletes a person identified using it's displayed index from the address book.
* Calculates the user's CAP from each module's grade.
*/
public class CalculateCAPCommand extends Command {
public class CalculateCapCommand extends Command {

public static final String COMMAND_WORD = "calculateCAP";
public static final String MESSAGE_CALCULATION_SUCCESS = "Calculated value: %1$s";
Expand All @@ -19,10 +19,10 @@ public CommandResult execute(Model model) throws CommandException {

int modularCredits = model.totalModularCredits();

Float gradePointsByUnits = model.totalGradePointsByUnits();
Float gradePointsByUnits = model.totalGradePointsByUnits();

Float calculatedCAPValue = gradePointsByUnits / modularCredits;
Float calculatedCapValue = gradePointsByUnits / modularCredits;

return new CommandResult(String.format(MESSAGE_CALCULATION_SUCCESS, calculatedCAPValue));
return new CommandResult(String.format(MESSAGE_CALCULATION_SUCCESS, calculatedCapValue));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;

public class CalculateMCCommand extends Command {
/**
* Calculates the user's total modular credits from their modules taken.
*/
public class CalculateMcCommand extends Command {

public static final String COMMAND_WORD = "calculateMC";
public static final String MESSAGE_CALCULATION_SUCCESS = "Calculated value: %1$s";

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import static java.util.Objects.requireNonNull;

import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.module.Module;
import seedu.address.model.moduleplan.ModulePlan;

/**
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,20 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SEMESTER;
import static seedu.address.logic.parser.CliSyntax.PREFIX_YEAR;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_MODULES;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import seedu.address.commons.util.CollectionUtil;
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.module.Grade;
import seedu.address.model.module.Module;
import seedu.address.model.module.ModuleCode;
import seedu.address.model.module.Semester;
import seedu.address.model.module.Year;
import seedu.address.model.module.Module;
import seedu.address.model.module.exceptions.ModuleNotFoundException;

/**
* Edits the details of an existing person in the address book.
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.module.NameContainsKeywordsPredicate;
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/seedu/address/logic/commands/InfoCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.module.ModuleCode;

/**
* Displays information of a module identified using it's module code.
*/
public class InfoCommand extends Command {

public static final String COMMAND_WORD = "info";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Shows information on the module identified by the module code. "
+ "Example: " + COMMAND_WORD + " " + "CS1101S ";
public static final String MESSAGE_INFO_MODULE_SUCCESS = "%1$s: %2$s \n"
+ "%3$s \n"
+ "%4$s \n";
public static final String MESSAGE_INFO_MODULE_SUCCESS_SAMPLE = "CS1101S : Programming Methodology \n"
+ "4MCs \n"
+ "This course introduces the concepts of programming and computational problem solving. "
+ "Starting from a small core of fundamental abstractions, the course introduces"
+ " programming as a method for communicating computational processes. \n";

public static final String MESSAGE_NOT_FOUND_MODULE = "This module is not found.";

private final ModuleCode moduleCode;

/**
* @param moduleCode of the module to be shown
*/
public InfoCommand(ModuleCode moduleCode) {
this.moduleCode = moduleCode;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

// TODO: Call a method in model to get the module information

return new CommandResult(MESSAGE_INFO_MODULE_SUCCESS_SAMPLE);
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof InfoCommand)) {
return false;
}

InfoCommand otherInfoCommand = (InfoCommand) other;
return moduleCode.equals(otherInfoCommand.moduleCode);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("moduleCode", moduleCode)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_MODULES;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package seedu.address.logic.parser;

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.*;

import static seedu.address.logic.parser.CliSyntax.PREFIX_CODE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SEMESTER;
import static seedu.address.logic.parser.CliSyntax.PREFIX_YEAR;

import java.util.stream.Stream;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.module.Grade;
import seedu.address.model.module.Module;
import seedu.address.model.module.ModuleCode;
import seedu.address.model.module.Semester;
import seedu.address.model.module.Year;
import seedu.address.model.module.Module;

/**
* Parses input arguments and creates a new AddCommand object
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/seedu/address/logic/parser/AddressBookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@

import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.CalculateCAPCommand;
import seedu.address.logic.commands.CalculateMCCommand;
import seedu.address.logic.commands.CalculateCapCommand;
import seedu.address.logic.commands.CalculateMcCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.InfoCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.parser.exceptions.ParseException;

Expand Down Expand Up @@ -64,6 +65,9 @@ public Command parseCommand(String userInput) throws ParseException {
case DeleteCommand.COMMAND_WORD:
return new DeleteCommandParser().parse(arguments);

case InfoCommand.COMMAND_WORD:
return new InfoCommandParser().parse(arguments);

case ClearCommand.COMMAND_WORD:
return new ClearCommand();

Expand All @@ -79,11 +83,11 @@ public Command parseCommand(String userInput) throws ParseException {
case HelpCommand.COMMAND_WORD:
return new HelpCommand();

case CalculateCAPCommand.COMMAND_WORD:
return new CalculateCAPCommand();
case CalculateCapCommand.COMMAND_WORD:
return new CalculateCapCommand();

case CalculateMCCommand.COMMAND_WORD:
return new CalculateMCCommand();
case CalculateMcCommand.COMMAND_WORD:
return new CalculateMcCommand();


default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_SEMESTER;
import static seedu.address.logic.parser.CliSyntax.PREFIX_YEAR;

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;

import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.EditCommand.EditModuleDescriptor;
import seedu.address.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -41,8 +36,7 @@ public EditCommand parse(String args) throws ParseException {

if (argMultimap.getValue(PREFIX_CODE).isPresent()) {
moduleCode = ParserUtil.parseModuleCode(argMultimap.getValue(PREFIX_CODE).get());
}
else {
} else {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE),
new ParseException(MESSAGE_INVALID_MODULE_CODE));
Expand Down
Loading

0 comments on commit 0c4e2a8

Please sign in to comment.