Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add temperature #66

Merged
merged 4 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TEMPERATURE;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
Expand All @@ -24,12 +25,14 @@ public class AddCommand extends Command {
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ PREFIX_TEMPERATURE + "TEMPERATURE "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_TEMPERATURE + "36.5 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";

Expand Down
23 changes: 20 additions & 3 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TEMPERATURE;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_STUDENTS;

import java.util.Collections;
Expand All @@ -25,6 +26,7 @@
import seedu.address.model.student.Phone;
import seedu.address.model.student.Remark;
import seedu.address.model.student.Student;
import seedu.address.model.student.Temperature;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -42,6 +44,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_PHONE + "PHONE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_TEMPERATURE + "TEMPERATURE] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
Expand All @@ -55,7 +58,7 @@ public class EditCommand extends Command {
private final EditStudentDescriptor editStudentDescriptor;

/**
* @param index of the student in the filtered student list to edit
* @param index of the student in the filtered student list to edit
* @param editStudentDescriptor details to edit the student with
*/
public EditCommand(Index index, EditStudentDescriptor editStudentDescriptor) {
Expand Down Expand Up @@ -98,10 +101,12 @@ private static Student createEditedStudent(Student studentToEdit, EditStudentDes
Phone updatedPhone = editStudentDescriptor.getPhone().orElse(studentToEdit.getPhone());
Email updatedEmail = editStudentDescriptor.getEmail().orElse(studentToEdit.getEmail());
Address updatedAddress = editStudentDescriptor.getAddress().orElse(studentToEdit.getAddress());
Temperature updatedTemperature = editStudentDescriptor.getTemperature().orElse(studentToEdit.getTemperature());
Remark updatedRemark = studentToEdit.getRemark(); // edit command does not allow editing remarks
Set<Tag> updatedTags = editStudentDescriptor.getTags().orElse(studentToEdit.getTags());

return new Student(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedRemark, updatedTags);
return new Student(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTemperature, updatedRemark,
updatedTags);
}

@Override
Expand Down Expand Up @@ -131,6 +136,7 @@ public static class EditStudentDescriptor {
private Phone phone;
private Email email;
private Address address;
private Temperature temperature;
private Set<Tag> tags;

public EditStudentDescriptor() {
Expand All @@ -145,14 +151,16 @@ public EditStudentDescriptor(EditStudentDescriptor toCopy) {
setPhone(toCopy.phone);
setEmail(toCopy.email);
setAddress(toCopy.address);
setTemperature(toCopy.temperature);
setTags(toCopy.tags);
}

/**
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags);
return CollectionUtil.isAnyNonNull(name, phone, email, address, temperature,
tags);
}

public void setName(Name name) {
Expand Down Expand Up @@ -187,6 +195,14 @@ public Optional<Address> getAddress() {
return Optional.ofNullable(address);
}

public void setTemperature(Temperature temperature) {
this.temperature = temperature;
}

public Optional<Temperature> getTemperature() {
return Optional.ofNullable(temperature);
}

/**
* Sets {@code tags} to this object's {@code tags}.
* A defensive copy of {@code tags} is used internally.
Expand Down Expand Up @@ -223,6 +239,7 @@ public boolean equals(Object other) {
&& getPhone().equals(e.getPhone())
&& getEmail().equals(e.getEmail())
&& getAddress().equals(e.getAddress())
&& getTemperature().equals(e.getTemperature())
&& getTags().equals(e.getTags());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public CommandResult execute(Model model) throws CommandException {

Student studentToEdit = lastShownList.get(index.getZeroBased());
Student editedStudent = new Student(studentToEdit.getName(), studentToEdit.getPhone(), studentToEdit.getEmail(),
studentToEdit.getAddress(), remark, studentToEdit.getTags());
studentToEdit.getAddress(), studentToEdit.getTemperature(), remark, studentToEdit.getTags());

model.setStudent(studentToEdit, editedStudent);
model.updateFilteredStudentList(PREDICATE_SHOW_ALL_STUDENTS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TEMPERATURE;

import java.util.Set;
import java.util.stream.Stream;
Expand All @@ -18,6 +19,7 @@
import seedu.address.model.student.Phone;
import seedu.address.model.student.Remark;
import seedu.address.model.student.Student;
import seedu.address.model.student.Temperature;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -33,7 +35,8 @@ public class AddCommandParser implements Parser<AddCommand> {
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_TEMPERATURE, PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME)
|| !argMultimap.getPreamble().isEmpty()) {
Expand All @@ -44,11 +47,11 @@ public AddCommand parse(String args) throws ParseException {
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());

Temperature temperature = ParserUtil.parseTemperature(argMultimap.getValue(PREFIX_TEMPERATURE).get());
Remark remark = new Remark(""); // add command does not allow adding remarks straight away
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Student student = new Student(name, phone, email, address, remark, tagList);
Student student = new Student(name, phone, email, address, temperature, remark, tagList);

return new AddCommand(student);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public Optional<String> getValue(Prefix prefix) {
case ("e/"):
Optional<String> missingEmailString = Optional.of("Insert email here!");
return missingEmailString;
case ("temp/"):
Optional<String> missingTemperatureString = Optional.of("Insert temperature here!");
return missingTemperatureString;
default:
List<String> values = getAllValues(prefix);
return values.isEmpty() ? Optional.empty() : Optional.of(values.get(values.size() - 1));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public class CliSyntax {
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_REMARK = new Prefix("r/");
public static final Prefix PREFIX_TEMPERATURE = new Prefix("temp/");

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TEMPERATURE;

import java.util.Collection;
import java.util.Collections;
Expand All @@ -32,7 +33,8 @@ public class EditCommandParser implements Parser<EditCommand> {
public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_TEMPERATURE, PREFIX_TAG);

Index index;

Expand All @@ -55,6 +57,10 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) {
editStudentDescriptor.setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()));
}
if (argMultimap.getValue(PREFIX_TEMPERATURE).isPresent()) {
editStudentDescriptor.setTemperature(ParserUtil.parseTemperature(argMultimap.getValue(PREFIX_TEMPERATURE)
.get()));
}
parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editStudentDescriptor::setTags);

if (!editStudentDescriptor.isAnyFieldEdited()) {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import seedu.address.model.student.Email;
import seedu.address.model.student.Name;
import seedu.address.model.student.Phone;
import seedu.address.model.student.Temperature;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -96,6 +97,21 @@ public static Email parseEmail(String email) throws ParseException {
return new Email(trimmedEmail);
}

/**
* Parses a {@code String temperature} into an {@code Temperature}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code temperature} is invalid.
*/
public static Temperature parseTemperature(String temperature) throws ParseException {
requireNonNull(temperature);
String trimmedTemperature = temperature.trim();
if (!Temperature.isValidTemperature(trimmedTemperature)) {
throw new ParseException(Temperature.MESSAGE_CONSTRAINTS);
}
return new Temperature(trimmedTemperature);
}

/**
* Parses a {@code String tag} into a {@code Tag}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
1 change: 0 additions & 1 deletion src/main/java/seedu/address/model/student/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
public class Phone {


public static final String MESSAGE_CONSTRAINTS =
"Phone numbers should only contain numbers, and it should be at least 3 digits long";
public static final String VALIDATION_REGEX = "\\d{3,}";
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/seedu/address/model/student/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ public class Student {

// Data fields
private final Address address;
private final Temperature temperature;
private final Remark remark;
private final Set<Tag> tags = new HashSet<>();

/**
* Every field must be present and not null.
*/
public Student(Name name, Phone phone, Email email, Address address, Remark remark, Set<Tag> tags) {
public Student(Name name, Phone phone, Email email, Address address, Temperature temperature, Remark remark,
Set<Tag> tags) {
requireAllNonNull(name, phone, email, tags);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.temperature = temperature;
this.remark = remark;
this.tags.addAll(tags);
}
Expand All @@ -54,6 +57,10 @@ public Address getAddress() {
return address;
}

public Temperature getTemperature() {
return temperature;
}

public Remark getRemark() {
return remark;
}
Expand Down Expand Up @@ -99,13 +106,14 @@ public boolean equals(Object other) {
&& otherStudent.getPhone().equals(getPhone())
&& otherStudent.getEmail().equals(getEmail())
&& otherStudent.getAddress().equals(getAddress())
&& otherStudent.getTemperature().equals(getTemperature())
&& otherStudent.getTags().equals(getTags());
}

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(name, phone, email, address, tags);
return Objects.hash(name, phone, email, address, temperature, remark, tags);
}

@Override
Expand All @@ -118,6 +126,8 @@ public String toString() {
.append(getEmail())
.append(" Address: ")
.append(getAddress())
.append(" Temperature: ")
.append(getTemperature())
.append(" Remark: ")
.append(getRemark())
.append(" Tags: ");
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/seedu/address/model/student/Temperature.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package seedu.address.model.student;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a Student's temperature in the address book.
*/
public class Temperature {

public static final String MESSAGE_CONSTRAINTS =
"Temperature should only contain a 2 digits number followed by 1 decimal place";
public static final String VALIDATION_REGEX = "\\d{2}" + "\\." + "\\d";
public final String value;

/**
* Constructs a {@code Temperature}.
*
* @param temperature A valid temperature.
*/
public Temperature(String temperature) {
requireNonNull(temperature);
checkArgument(isValidTemperature(temperature), MESSAGE_CONSTRAINTS);
value = temperature;
}

/**
* Returns true if a given string is a valid temperature.
*/
public static boolean isValidTemperature(String test) {
if (test.equals("Insert temperature here!")) {
return true;
} else {
return test.matches(VALIDATION_REGEX);
}
}

@Override
public String toString() {
return value;
}

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

@Override
public int hashCode() {
return value.hashCode();
}
}
Loading