Skip to content

Commit

Permalink
Add itinerary methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaoosuuu committed Oct 22, 2022
1 parent 515dfa2 commit 8aada29
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/main/java/seedu/waddle/commons/core/index/MultiIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public Index getIndex(int pos) {
return indices.get(pos - 1);
}

public Index getDayIndex() {
return getIndex(1);
}

public Index getTaskIndex() {
return getIndex(2);
}



private boolean isValidPos(int pos) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/waddle/model/item/Day.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public Item removeItem(Index index) {
return removedItem;
}

public Item getItem(Index index) {
return this.itemList.get(index.getZeroBased());
}

/**
* Deletes the day. Resets the startTime field of all items in this day.
*
Expand Down
44 changes: 37 additions & 7 deletions src/main/java/seedu/waddle/model/itinerary/Itinerary.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.List;
import java.util.Objects;

import seedu.waddle.commons.core.index.MultiIndex;
import seedu.waddle.logic.commands.exceptions.CommandException;
import seedu.waddle.model.item.Day;
import seedu.waddle.model.item.Item;
import seedu.waddle.model.item.UniqueItemList;
Expand Down Expand Up @@ -124,6 +126,22 @@ public void setItem(Item target, Item editedItem) {
unscheduledItemList.setItem(target, editedItem);
}

public void setItem(Item target, Item editedItem, MultiIndex index) throws CommandException {
if (index.getDayIndex() == null) {
this.unscheduledItemList.setItem(target, editedItem);
sortUnscheduledItemList();
} else {
Day day = this.days.get(index.getDayIndex().getZeroBased());
day.removeItem(index.getTaskIndex());
try {
day.addItem(editedItem);
} catch (CommandException e) {
day.addItem(target);
throw e;
}
}
}

public int getItemSize() {
return this.unscheduledItemList.getSize();
}
Expand All @@ -136,15 +154,26 @@ private void sortUnscheduledItemList() {
this.unscheduledItemList.sort(priorityComparator);
}

/* public void unplanItem(MultiIndex index) {
Day day = this.days.get(index.getDayIndex());
/**
* Unplan an item.
* @param index A multiIndex to locate the day and index of task within the day
*/
public void unplanItem(MultiIndex index) {
Day day = this.days.get(index.getDayIndex().getZeroBased());
Item unplannedItem = day.removeItem(index.getTaskIndex());
addItem(unplannedItem);
this.unscheduledItemList.sort(priorityComparator);
sortUnscheduledItemList();
this.budget.updateSpending(-unplannedItem.getCost().getValue());
}

public void planItem(int itemIndex, int dayIndex, int startTime) {
/**
* Plan an item.
* @param itemIndex Index of item in unscheduled list.
* @param dayIndex Day to include this item.
* @param startTime startTime of the item.
* @throws CommandException When adding item to specific day leads to conflict in time.
*/
public void planItem(int itemIndex, int dayIndex, int startTime) throws CommandException {
Item item = this.unscheduledItemList.get(itemIndex);
Day day = this.days.get(dayIndex);
day.addItem(item);
Expand All @@ -154,12 +183,13 @@ public void planItem(int itemIndex, int dayIndex, int startTime) {

public Item getItem(MultiIndex index) {
if (index.getDayIndex() == null) {
return this.unscheduledItemList.get(index.getTaskIndex());
return this.unscheduledItemList.get(index.getTaskIndex().getZeroBased());
} else {
Day day = this.days.get(index.getDayIndex());
Day day = this.days.get(index.getDayIndex().getZeroBased());
return day.getItem(index.getTaskIndex());
}
} */
}

/**
* Returns true if both itineraries have the same identity and data fields.
* This defines a stronger notion of equality between two itineraries.
Expand Down

0 comments on commit 8aada29

Please sign in to comment.