Skip to content

Commit

Permalink
Merge pull request #17 from CS2103-AY1819S2-W16-4/master
Browse files Browse the repository at this point in the history
Updates are taken
  • Loading branch information
barisbatuhan authored Apr 13, 2019
2 parents 275cbd8 + 726dcc5 commit 39f072a
Show file tree
Hide file tree
Showing 29 changed files with 513 additions and 168 deletions.
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 @@ -5,6 +5,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_EDUCATION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GPA;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DEGREE;
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_POS;
Expand All @@ -29,6 +30,7 @@ public class AddCommand extends Command {
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_EDUCATION + "EDUCATION "
+ PREFIX_GPA + "Gpa "
+ PREFIX_DEGREE + "DEGREE "
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_SKILL + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
Expand All @@ -37,6 +39,7 @@ public class AddCommand extends Command {
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_EDUCATION + "NUS "
+ PREFIX_GPA + "3 "
+ PREFIX_DEGREE + "Bachelors "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_SKILL + "Java "
+ PREFIX_POS + "Software Engineer";
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_EDUCATION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GPA;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DEGREE;
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_SKILL;
Expand All @@ -25,6 +26,7 @@
import seedu.address.model.person.Education;
import seedu.address.model.person.Email;
import seedu.address.model.person.Gpa;
import seedu.address.model.person.Degree;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
Expand All @@ -46,6 +48,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_EDUCATION + "EDUCATION] "
+ "[" + PREFIX_GPA + "Gpa] "
+ "[" + PREFIX_DEGREE + "DEGREE] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_SKILL + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
Expand Down Expand Up @@ -94,7 +97,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
Set<SkillsTag> editedTags = new HashSet<>(changedPerson.getTags());
editedTags.addAll(endorsements);
Person editedPerson = new Person(changedPerson.getName(), changedPerson.getPhone(), changedPerson.getEmail(),
changedPerson.getEducation(), changedPerson.getGpa(), changedPerson.getAddress(), editedTags);
changedPerson.getEducation(), changedPerson.getGpa(), changedPerson.getDegree(), changedPerson.getAddress(), editedTags);


if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) {
Expand All @@ -118,11 +121,12 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Education updatedEducation = editPersonDescriptor.getEducation().orElse(personToEdit.getEducation());
Gpa updatedGpa = editPersonDescriptor.getGpa().orElse(personToEdit.getGpa());
Degree updatedDegree = editPersonDescriptor.getDegree().orElse(personToEdit.getDegree());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Set<SkillsTag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());

return new Person(updatedName, updatedPhone, updatedEmail, updatedEducation,
updatedGpa, updatedAddress, updatedTags);
updatedGpa, updatedDegree, updatedAddress, updatedTags);
}

@Override
Expand Down Expand Up @@ -153,6 +157,7 @@ public static class EditPersonDescriptor {
private Email email;
private Education education;
private Gpa gpa;
private Degree degree;
private Address address;
private Set<SkillsTag> tags;

Expand All @@ -168,6 +173,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setEmail(toCopy.email);
setEducation(toCopy.education);
setGpa(toCopy.gpa);
setDegree(toCopy.degree);
setAddress(toCopy.address);
setTags(toCopy.tags);
}
Expand All @@ -176,7 +182,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, education, gpa, address, tags);
return CollectionUtil.isAnyNonNull(name, phone, email, education, gpa, degree, address, tags);
}

public void setName(Name name) {
Expand Down Expand Up @@ -219,6 +225,14 @@ public Optional<Gpa> getGpa() {
return Optional.ofNullable(gpa);
}

public void setDegree(Degree degree) {
this.degree = degree;
}

public Optional<Degree> getDegree() {
return Optional.ofNullable(degree);
}

public void setAddress(Address address) {
this.address = address;
}
Expand Down Expand Up @@ -264,6 +278,7 @@ && getPhone().equals(e.getPhone())
&& getEmail().equals(e.getEmail())
&& getEducation().equals(e.getEducation())
&& getGpa().equals(e.getGpa())
&& getDegree().equals(e.getDegree())
&& getAddress().equals(e.getAddress())
&& getTags().equals(e.getTags());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
}

Person editedPerson = new Person(personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(),
personToEdit.getEducation(), personToEdit.getGpa(), personToEdit.getAddress(), personTags);
personToEdit.getEducation(), personToEdit.getGpa(), personToEdit.getDegree(), personToEdit.getAddress(), personTags);


model.setPerson(personToEdit, editedPerson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
import java.util.LinkedHashSet;
import java.util.List;

import seedu.address.model.person.Address;
import seedu.address.model.person.Education;
import seedu.address.model.person.Email;
import seedu.address.model.person.Gpa;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.*;
import seedu.address.model.tag.SkillsTag;

/**
Expand Down Expand Up @@ -61,11 +55,12 @@ private List<Person> orderPersonsTags(List<Person> lastShownList, String prefix)
Email email = person.getEmail();
Education education = person.getEducation();
Gpa gpa = person.getGpa();
Degree degree = person.getDegree();
Address address = person.getAddress();
//change list back to set
LinkedHashSet<SkillsTag> tagSet = SortUtil.toTags(individualSortedTags);

Person newPerson = new Person(name, phone, email, education, gpa, address, tagSet);
Person newPerson = new Person(name, phone, email, education, gpa, degree, address, tagSet);
personsWithCorrectTagOrder.add(newPerson);
}
return personsWithCorrectTagOrder;
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.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_EDUCATION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GPA;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DEGREE;
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_POS;
Expand All @@ -21,6 +22,7 @@
import seedu.address.model.person.Education;
import seedu.address.model.person.Email;
import seedu.address.model.person.Gpa;
import seedu.address.model.person.Degree;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
Expand All @@ -39,11 +41,12 @@ 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_SKILL, PREFIX_POS, PREFIX_GPA, PREFIX_EDUCATION);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_EDUCATION, PREFIX_GPA, PREFIX_DEGREE, PREFIX_ADDRESS,
PREFIX_SKILL, PREFIX_POS);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_GPA, PREFIX_EDUCATION)
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_EDUCATION, PREFIX_GPA, PREFIX_DEGREE, PREFIX_ADDRESS)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}
Expand All @@ -52,17 +55,19 @@ 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());
Gpa gpa = ParserUtil.parseGpa(argMultimap.getValue(PREFIX_GPA).get());
Education education = ParserUtil.parseEducation(argMultimap.getValue(PREFIX_EDUCATION).get());
Degree degree = ParserUtil.parseDegree(argMultimap.getValue(PREFIX_DEGREE).get());

Set<SkillsTag> skillList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_SKILL), "skill");
Set<SkillsTag> posList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_POS), "pos");

Set<SkillsTag> tagList = new HashSet<>();
tagList.addAll(skillList);
tagList.addAll(posList);
Gpa gpa = ParserUtil.parseGpa(argMultimap.getValue(PREFIX_GPA).get());
Education education = ParserUtil.parseEducation(argMultimap.getValue(PREFIX_EDUCATION).get());

Person person = new Person(name, phone, email, education, gpa, address, tagList);

Person person = new Person(name, phone, email, education, gpa, degree, address, tagList);

return new AddCommand(person);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class CliSyntax {
public static final Prefix PREFIX_POS = new Prefix("position/");
public static final Prefix PREFIX_GPA = new Prefix("g/");
public static final Prefix PREFIX_EDUCATION = new Prefix("d/");
public static final Prefix PREFIX_DEGREE = new Prefix("deg/");

/* Prefix for Filtering definitions */
public static final Prefix PREFIX_FILTER_NAME = new Prefix("name<");
Expand All @@ -33,6 +34,8 @@ public class CliSyntax {
public static final Prefix PREFIX_FILTER_ENDORSEMENT_REVERSE = new Prefix(">end");
public static final Prefix PREFIX_FILTER_GPA = new Prefix("gpa<");
public static final Prefix PREFIX_FILTER_GPA_REVERSE = new Prefix(">gpa");
public static final Prefix PREFIX_FILTER_DEGREE = new Prefix("deg<");
public static final Prefix PREFIX_FILTER_GPA_DEGREE = new Prefix(">deg");
public static final Prefix PREFIX_FILTER_EDUCATION = new Prefix("edu<");
public static final Prefix PREFIX_FILTER_EDUCATION_REVERSE = new Prefix(">edu");

Expand All @@ -42,13 +45,15 @@ public class CliSyntax {
public static final SortWord SORTWORD_ENDORSEMENTS = new SortWord("endorsements");
public static final SortWord SORTWORD_ENDORSEMENT_NUMBER = new SortWord("endorsement number");
public static final SortWord SORTWORD_GPA = new SortWord("gpa");
public static final SortWord SORTWORD_DEGREE = new SortWord("degree");
public static final SortWord SORTWORD_NAME = new SortWord("name");
public static final SortWord SORTWORD_POSITION_NUMBER = new SortWord("position number");
public static final SortWord SORTWORD_POSITIONS = new SortWord("positions");
public static final SortWord SORTWORD_REVERSE_EDUCATION = new SortWord("reverse education");
public static final SortWord SORTWORD_REVERSE_ENDORSEMENTS = new SortWord("reverse endorsements");
public static final SortWord SORTWORD_REVERSE_ENDORSEMENT_NUMBER = new SortWord("reverse endorsement number");
public static final SortWord SORTWORD_REVERSE_GPA = new SortWord("reverse gpa");
public static final SortWord SORTWORD_REVERSE_DEGREE = new SortWord("reverse degree");
public static final SortWord SORTWORD_REVERSE_NAME = new SortWord("reverse name");
public static final SortWord SORTWORD_REVERSE_POSITION_NUMBER = new SortWord("reverse position number");
public static final SortWord SORTWORD_REVERSE_POSITIONS = new SortWord("reverse positions");
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_EDUCATION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GPA;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DEGREE;
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_POS;
Expand Down Expand Up @@ -40,7 +41,7 @@ public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_EDUCATION,
PREFIX_GPA, PREFIX_ADDRESS, PREFIX_SKILL, PREFIX_POS);
PREFIX_GPA, PREFIX_DEGREE, PREFIX_ADDRESS, PREFIX_SKILL, PREFIX_POS);

Index index;

Expand All @@ -65,6 +66,10 @@ public EditCommand parse(String args) throws ParseException {
editPersonDescriptor.setGpa(ParserUtil.parseGpa(argMultimap.getValue(PREFIX_GPA).get()));
}

if (argMultimap.getValue(PREFIX_DEGREE).isPresent()) {
editPersonDescriptor.setDegree(ParserUtil.parseDegree(argMultimap.getValue(PREFIX_DEGREE).get()));
}

if (argMultimap.getValue(PREFIX_EDUCATION).isPresent()) {
editPersonDescriptor.setEducation(ParserUtil.parseEducation(argMultimap.getValue(PREFIX_EDUCATION).get()));
}
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
import seedu.address.model.person.Education;
import seedu.address.model.person.Email;
import seedu.address.model.person.Gpa;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.person.*;
import seedu.address.model.tag.SkillsTag;

/**
Expand Down Expand Up @@ -143,6 +138,21 @@ public static Education parseEducation(String education) throws ParseException {
return new Education(trimmedEducation);
}

/**
* Parses the degree field
* @param degree
* @return
* @throws ParseException
*/
public static Degree parseDegree(String degree) throws ParseException {
requireNonNull(degree);
String trimmedDegree = degree.trim();
if (!Degree.isValidDegree(trimmedDegree)) {
throw new ParseException(Degree.MESSAGE_CONSTRAINTS);
}
return new Degree(trimmedDegree);
}

/**
* Parses {@code Collection<String> tags} into a {@code Set<SkillsTag>}.
*/
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/seedu/address/model/person/Degree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package seedu.address.model.person;

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

/**
* Represents a Person's name in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidDegree)}
*/
public class Degree {

public static final String MESSAGE_CONSTRAINTS =
"Degree should be the highest level of completed education, and it should not be blank \n"
+ "Can only be either: High school, Associates, Bachelors, Masters or PHD" ;

/*
* The first character of the Degree must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/

//public static final String VALIDATION_REGEX = ;

public final String value;

/**
* Constructs a {@code Degree}.
*
* @param degree A valid degree.
*/
public Degree(String degree) {
requireNonNull(degree);
checkArgument(isValidDegree(degree), MESSAGE_CONSTRAINTS);
value = degree;
}

/**
* Returns true if a given string is a valid name.
*/
public static boolean isValidDegree(String test) {

if(test.equalsIgnoreCase("High School")){
return true;
}
if(test.equalsIgnoreCase("Associates")){
return true;
}
if(test.equalsIgnoreCase("Bachelors")){
return true;
}
if(test.equalsIgnoreCase("Masters")){
return true;
}
if(test.equalsIgnoreCase("PHD")){
return true;
}
return false;

}


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

//unsure if needed bc people can have the same???
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Degree // instanceof handles nulls
&& value.equals(((Degree) other).value)); // state check
}

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

}


Loading

0 comments on commit 39f072a

Please sign in to comment.