Skip to content

Commit

Permalink
modified plannedDate to Date class
Browse files Browse the repository at this point in the history
  • Loading branch information
tharshita committed Mar 31, 2020
1 parent c32ea07 commit e475550
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 52 deletions.
6 changes: 3 additions & 3 deletions src/main/java/seedu/recipe/logic/commands/PlanCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import seedu.recipe.commons.core.Messages;
import seedu.recipe.commons.core.index.Index;
import seedu.recipe.logic.commands.exceptions.CommandException;
import seedu.recipe.model.Date;
import seedu.recipe.model.Model;
import seedu.recipe.model.plan.PlannedDate;
import seedu.recipe.model.plan.PlannedRecipe;
import seedu.recipe.model.recipe.Recipe;

Expand All @@ -33,12 +33,12 @@ public class PlanCommand extends Command {
public static final String MESSAGE_SUCCESS = "Recipe planned: %1$s, %2$s";

private final Index index;
private final PlannedDate atDate;
private final Date atDate;

/**
* Creates an PlanCommand to set the specified {@code Recipe} on a certain date
*/
public PlanCommand(Index index, PlannedDate date) {
public PlanCommand(Index index, Date date) {
requireNonNull(index);
requireNonNull(date);
this.index = index;
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/seedu/recipe/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
import seedu.recipe.commons.core.index.Index;
import seedu.recipe.commons.util.StringUtil;
import seedu.recipe.logic.parser.exceptions.ParseException;
import seedu.recipe.model.Date;
import seedu.recipe.model.goal.Goal;
import seedu.recipe.model.plan.PlannedDate;
import seedu.recipe.model.recipe.Name;
import seedu.recipe.model.recipe.Step;
import seedu.recipe.model.recipe.Time;

import seedu.recipe.model.recipe.ingredient.Fruit;
import seedu.recipe.model.recipe.ingredient.Grain;
import seedu.recipe.model.recipe.ingredient.Ingredient;
Expand Down Expand Up @@ -514,16 +513,16 @@ public static Set<Other> parseOthersNameOnly(Collection<String> others) throws P
}

/**
* Parses {@code String date} into a {@code PlannedDate}.
* Parses {@code String date} into a {@code Date}.
*
* @throws ParseException if the given {@code date} is invalid.
*/
public static PlannedDate parseDate(String date) throws ParseException {
public static Date parseDate(String date) throws ParseException {
requireNonNull(date);
String trimmedDate = date.trim();
if (!PlannedDate.isValidDate(trimmedDate)) {
throw new ParseException(PlannedDate.MESSAGE_CONSTRAINTS);
if (!Date.isValidDate(trimmedDate)) {
throw new ParseException(Date.MESSAGE_CONSTRAINTS);
}
return new PlannedDate(trimmedDate);
return new Date(trimmedDate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import seedu.recipe.commons.core.index.Index;
import seedu.recipe.logic.commands.PlanCommand;
import seedu.recipe.logic.parser.exceptions.ParseException;
import seedu.recipe.model.plan.PlannedDate;
import seedu.recipe.model.Date;

/**
* Parses input arguments and creates a new PlanCommand object
Expand All @@ -35,7 +35,7 @@ public PlanCommand parse(String args) throws ParseException {
if (!arePrefixesPresent(argMultimap, PREFIX_DATE)) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, PlanCommand.MESSAGE_USAGE));
}
PlannedDate date = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get());
Date date = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get());

return new PlanCommand(index, date);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import seedu.recipe.logic.commands.ViewCommand;
import seedu.recipe.logic.parser.exceptions.ParseException;
import seedu.recipe.model.plan.PlannedDate;
import seedu.recipe.model.Date;
import seedu.recipe.model.plan.PlannedRecipeWithinDateRangePredicate;

/**
Expand All @@ -27,7 +27,7 @@ public ViewCommand parse(String args) throws ParseException {
}

PlannedRecipeWithinDateRangePredicate predicate = new PlannedRecipeWithinDateRangePredicate(
new PlannedDate(LocalDate.parse("2020-03-30")), new PlannedDate(LocalDate.parse("2020-04-06")));
new Date(LocalDate.parse("2020-03-30")), new Date(LocalDate.parse("2020-04-06")));
// model.updateFilteredRecipeList(predicate);
return new ViewCommand(predicate);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package seedu.recipe.model.plan;
package seedu.recipe.model;

import static java.time.temporal.TemporalAdjusters.lastDayOfMonth;
import static java.util.Objects.requireNonNull;
Expand All @@ -9,14 +9,14 @@
import java.time.format.DateTimeParseException;

/**
* Represents a date in the planned recipes book.
* Represents a date in the recipes book.
* Guarantees: immutable; is valid as declared in {@link #isValidDate(String)}
*/
public class PlannedDate implements Comparable<PlannedDate> {
public class Date implements Comparable<seedu.recipe.model.Date> {


public static final String MESSAGE_CONSTRAINTS =
"PlannedDate should be written in the format YYYY-MM-DD";
"Date should be written in the format YYYY-MM-DD";

public static final String VALIDATION_REGEX = "^[0-9-]+";
public static final DateTimeFormatter DAY_OF_WEEK = DateTimeFormatter.ofPattern("EEEE");
Expand All @@ -25,17 +25,17 @@ public class PlannedDate implements Comparable<PlannedDate> {
private final LocalDate date;

/**
* Constructs a {@code PlannedDate}.
* Constructs a {@code Date}.
*
* @param date A valid date.
*/
public PlannedDate(String date) {
public Date(String date) {
requireNonNull(date);
checkArgument(isValidDate(date), MESSAGE_CONSTRAINTS);
this.date = LocalDate.parse(date);
}

public PlannedDate(LocalDate date) {
public Date(LocalDate date) {
requireNonNull(date);
this.date = date;
}
Expand All @@ -57,12 +57,12 @@ public static boolean isValidDate(String test) {
}
}

public PlannedDate onFirstDayOfMonth() {
return new PlannedDate(date.withDayOfMonth(1));
public seedu.recipe.model.Date onFirstDayOfMonth() {
return new seedu.recipe.model.Date(date.withDayOfMonth(1));
}

public PlannedDate onLastDayOfMonth() {
return new PlannedDate(date.with(lastDayOfMonth()));
public seedu.recipe.model.Date onLastDayOfMonth() {
return new seedu.recipe.model.Date(date.with(lastDayOfMonth()));
}

public int getDateOfMonth() {
Expand All @@ -73,7 +73,7 @@ public int getDateOfMonth() {
*
* Not inclusive!
*/
public boolean isWithinRange(PlannedDate start, PlannedDate end) {
public boolean isWithinRange(seedu.recipe.model.Date start, seedu.recipe.model.Date end) {
return date.isAfter(start.date) && date.isBefore(end.date);
}

Expand All @@ -82,7 +82,7 @@ public String toStringForJson() {
}

@Override
public int compareTo(PlannedDate other) {
public int compareTo(seedu.recipe.model.Date other) {
LocalDate otherLocalDate = other.date;
if (date.isBefore(otherLocalDate)) {
return -1;
Expand All @@ -101,14 +101,14 @@ public String toString() {
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof PlannedDate // instanceof handles nulls
&& date.equals(((PlannedDate) other).date)); // state check
|| (other instanceof seedu.recipe.model.Date // instanceof handles nulls
&& date.equals(((seedu.recipe.model.Date) other).date)); // state check
}

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


}

9 changes: 5 additions & 4 deletions src/main/java/seedu/recipe/model/plan/PlannedRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Objects;

import seedu.recipe.model.Date;
import seedu.recipe.model.recipe.Recipe;

/**
Expand All @@ -11,9 +12,9 @@
public class PlannedRecipe {

private Recipe recipe;
private PlannedDate date;
private Date date;

public PlannedRecipe(Recipe recipe, PlannedDate date) {
public PlannedRecipe(Recipe recipe, Date date) {
this.recipe = recipe;
this.date = date;
}
Expand All @@ -26,14 +27,14 @@ public void setRecipe(Recipe recipe) {
this.recipe = recipe;
}

public PlannedDate getDate() {
public Date getDate() {
return date;
}

/**
* Checks whether the date of this planned recipe falls within the {@code start} date and the {@code end} date.
*/
public boolean isWithinRange(PlannedDate start, PlannedDate end) {
public boolean isWithinRange(Date start, Date end) {
return date.isWithinRange(start, end);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import java.util.function.Predicate;

import seedu.recipe.model.Date;

/**
* Tests that a {@code PlannedRecipe}'s {@code PlannedDate} falls within the specified PlannedDate range.
* Tests that a {@code PlannedRecipe}'s {@code Date} falls within the specified Date range.
*/
public class PlannedRecipeWithinDateRangePredicate implements Predicate<PlannedRecipe> {

private PlannedDate start;
private PlannedDate end;
private Date start;
private Date end;

public PlannedRecipeWithinDateRangePredicate(PlannedDate start, PlannedDate end) {
public PlannedRecipeWithinDateRangePredicate(Date start, Date end) {
this.start = start;
this.end = end;
}
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/seedu/recipe/storage/plan/JsonAdaptedPlannedDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import com.fasterxml.jackson.annotation.JsonValue;

import seedu.recipe.commons.exceptions.IllegalValueException;
import seedu.recipe.model.plan.PlannedDate;
import seedu.recipe.model.Date;

/**
* Jackson-friendly version of {@link PlannedDate}.
* Jackson-friendly version of {@link Date}.
*/
public class JsonAdaptedPlannedDate {

Expand All @@ -24,7 +24,7 @@ public JsonAdaptedPlannedDate(String plannedDate) {
/**
* Converts a given {@code plannedDate} into this class for Jackson use.
*/
public JsonAdaptedPlannedDate(PlannedDate plannedDate) {
public JsonAdaptedPlannedDate(Date plannedDate) {
date = plannedDate.toStringForJson();
}

Expand All @@ -34,15 +34,15 @@ public String getDate() {
}

/**
* Converts this Jackson-friendly adapted plannedDate object into the model's {@code PlannedDate} object.
* @return PlannedDate object that the adapted plannedDate was converted into.
* @throws IllegalValueException if there were any data constraints violated in the adapted PlannedDate.
* Converts this Jackson-friendly adapted plannedDate object into the model's {@code Date} object.
* @return Date object that the adapted plannedDate was converted into.
* @throws IllegalValueException if there were any data constraints violated in the adapted Date.
*/
public PlannedDate toModelType() throws IllegalValueException {
if (!PlannedDate.isValidDate(date)) {
throw new IllegalValueException(PlannedDate.MESSAGE_CONSTRAINTS);
public Date toModelType() throws IllegalValueException {
if (!Date.isValidDate(date)) {
throw new IllegalValueException(Date.MESSAGE_CONSTRAINTS);
}

return new PlannedDate(date);
return new Date(date);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;

import seedu.recipe.commons.exceptions.IllegalValueException;
import seedu.recipe.model.plan.PlannedDate;
import seedu.recipe.model.Date;
import seedu.recipe.model.plan.PlannedRecipe;
import seedu.recipe.model.recipe.Recipe;
import seedu.recipe.storage.JsonAdaptedRecipe;
Expand Down Expand Up @@ -43,7 +43,7 @@ public JsonAdaptedPlannedRecipe(PlannedRecipe plannedRecipe) {
*/
public PlannedRecipe toModelType() throws IllegalValueException {
Recipe modelRecipe = recipe.toModelType();
PlannedDate modelPlannedDate = date.toModelType();
Date modelPlannedDate = date.toModelType();
return new PlannedRecipe(modelRecipe, modelPlannedDate);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/recipe/ui/PlanningListCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import seedu.recipe.model.plan.PlannedDate;
import seedu.recipe.model.Date;
import seedu.recipe.model.plan.PlannedRecipe;
import seedu.recipe.model.recipe.Recipe;

Expand All @@ -36,7 +36,7 @@ public class PlanningListCard extends UiPart<Region> {
*/

public final PlannedRecipe plannedRecipeObject;
public final PlannedDate plannedDate;
public final Date plannedDate;
public final Recipe recipe;
private final String styleIngredientsAndSteps = "-fx-font-size: 11pt;\n"
+ "-fx-font-family: \"Segoe UI\";\n"
Expand Down

0 comments on commit e475550

Please sign in to comment.