-
Notifications
You must be signed in to change notification settings - Fork 5
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
finished list /date /sort #218
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,15 @@ | |
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
|
||
/** | ||
* The TravelActivityList class represents the list of travel activities that the user inputs. | ||
* Methods include adding, removing, listing, expensing, updating, tagging, and filtering travel activities. | ||
* | ||
*/ | ||
public class TravelActivityList { | ||
private static Logger logger = Logger.getLogger("TravelActivityListLogger"); | ||
/** Array of travel activity */ | ||
|
@@ -42,19 +47,41 @@ public void addTravelActivity(TravelActivity travelActivity){ | |
} | ||
|
||
/** | ||
* Prints out all the travel activities | ||
* Prints out all the travel activities. | ||
* If sort is enabled, the list will be printed out from oldest to newest date. | ||
* If filterDate is enabled and a date is provided, only activities from that date will be printed | ||
* | ||
* @param sort boolean indicating if list should be sorted | ||
* @param filterDate boolean indicating if list should be filtered by date | ||
* @param date the date to be filtered by | ||
*/ | ||
public void listTravelActivities(){ | ||
public void listTravelActivities(boolean sort, boolean filterDate, LocalDate date){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good enhancement to the current list feature |
||
ArrayList<TravelActivity> activities = new ArrayList<>(); | ||
if (filterDate) { | ||
for (TravelActivity a: travelActivities) { | ||
if (a.getDate().equals(date)) { | ||
activities.add(a); | ||
} | ||
} | ||
} else { | ||
activities = travelActivities; | ||
} | ||
if (sort) { | ||
Collections.sort(activities, Comparator.comparing(TravelActivity::getDate)); | ||
} | ||
int activityCount = 0; | ||
for (TravelActivity activity: travelActivities) { | ||
for (TravelActivity activity: activities) { | ||
if (activity == null) { | ||
break; | ||
} | ||
activityCount++; | ||
Ui.printActivity(activity, activityCount); | ||
} | ||
if (activityCount == 0) { | ||
System.out.println("There are no activities to list"); | ||
} | ||
int finalActivityCount = noOfActivities; | ||
assert finalActivityCount == activityCount : "Index out of bounds while listing activities"; | ||
assert finalActivityCount >= activityCount : "Index out of bounds while listing activities"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion will cause it to fail as it will check that finalActivityCount >= activityCount. Since that is false it will cause the assertion to happen |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job adding javadocs