Skip to content

Commit

Permalink
Rename format number of tasks/events string
Browse files Browse the repository at this point in the history
  • Loading branch information
irvinlim committed Nov 5, 2016
1 parent 493c2be commit 4317579
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 38 deletions.
18 changes: 9 additions & 9 deletions src/main/java/seedu/todo/commons/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static String replaceEmpty(String string, String replaceString) {
return (string == null || string.isEmpty()) ? replaceString : string;
}

/*
/**
* Format the display message depending on the number of tasks and events
*
* @param numTasks
Expand All @@ -59,33 +59,33 @@ public static String replaceEmpty(String string, String replaceString) {
*
* @return the display message for console message output
*/
public static String formatNumberOfTaskAndEventWithPuralizer (int numTasks, int numEvents) {
public static String formatNumTasksEvents(int numTasks, int numEvents) {
if (numTasks != 0 && numEvents != 0) {
return String.format("%s and %s.", formatNumberOfTaskWithPuralizer(numTasks), formatNumberOfEventWithPuralizer(numEvents));
return String.format("%s and %s.", formatNumTasks(numTasks), formatNumEvents(numEvents));
} else if (numTasks != 0) {
return formatNumberOfTaskWithPuralizer(numTasks);
return formatNumTasks(numTasks);
} else {
return formatNumberOfEventWithPuralizer(numEvents);
return formatNumEvents(numEvents);
}
}

/*
/**
* Format the number of events found based on the events found
*
* @param numEvents
* the number of events found
*/
public static String formatNumberOfEventWithPuralizer (int numEvents) {
public static String formatNumEvents(int numEvents) {
return String.format("%d %s", numEvents, pluralizer(numEvents, "event", "events"));
}

/*
/**
* Format the number of tasks found based on the tasks found
*
* @param numTasks
* the number of tasks found
*/
public static String formatNumberOfTaskWithPuralizer (int numTasks) {
public static String formatNumTasks(int numTasks) {
return String.format("%d %s", numTasks, pluralizer(numTasks, "task", "tasks"));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/todo/controllers/ClearController.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private void destroyByRange(TodoListDB db, LocalDateTime dateFrom, LocalDateTime

//save and render
db.save();
Renderer.renderIndex(db, String.format(MESSAGE_CLEAR_SUCCESS, StringUtil.formatNumberOfTaskAndEventWithPuralizer(numTasks, numEvents)));
Renderer.renderIndex(db, String.format(MESSAGE_CLEAR_SUCCESS, StringUtil.formatNumTasksEvents(numTasks, numEvents)));
}


Expand Down Expand Up @@ -278,7 +278,7 @@ private void destroyBySelectedDate(TodoListDB db, LocalDateTime givenDate, boole

//save and render
db.save();
Renderer.renderIndex(db, String.format(MESSAGE_CLEAR_SUCCESS, StringUtil.formatNumberOfTaskAndEventWithPuralizer(numTasks, numEvents)));
Renderer.renderIndex(db, String.format(MESSAGE_CLEAR_SUCCESS, StringUtil.formatNumTasksEvents(numTasks, numEvents)));
}

/**
Expand Down
29 changes: 2 additions & 27 deletions src/main/java/seedu/todo/controllers/ListController.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
package seedu.todo.controllers;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.ArrayUtils;

import com.joestelmach.natty.DateGroup;
import com.joestelmach.natty.Parser;

import seedu.todo.commons.exceptions.AmbiguousEventTypeException;
import seedu.todo.commons.exceptions.InvalidNaturalDateException;
import seedu.todo.commons.exceptions.ParseException;
import seedu.todo.commons.util.DateUtil;
import seedu.todo.commons.util.StringUtil;
import seedu.todo.controllers.concerns.Tokenizer;
import seedu.todo.controllers.concerns.CalendarItemFilter;
import seedu.todo.controllers.concerns.DateParser;
import seedu.todo.controllers.concerns.Renderer;
import seedu.todo.models.Event;
import seedu.todo.models.Task;
Expand All @@ -41,7 +30,7 @@ public class ListController implements Controller {
private static final String MESSAGE_LISTING_ALL = "Showing all tasks and events.\n\n"
+ "You have a total of %d incomplete tasks, %d overdue tasks, "
+ "and %d upcoming events.";
private static final String MESSAGE_LISTING_FILTERED = "Showing a subset of all %s.\n\nYour query: %s";
private static final String MESSAGE_LISTING_FILTERED = "Showing %s.\n\nYour query: %s";

private static CommandDefinition commandDefinition =
new CommandDefinition(NAME, DESCRIPTION, COMMAND_SYNTAX);
Expand Down Expand Up @@ -113,7 +102,7 @@ public void process(String input) throws ParseException {
}

// Render the new view with filtered tasks.
String consoleMessage = String.format(MESSAGE_LISTING_FILTERED, formatShowingWhat(isTask, isEvent), input);
String consoleMessage = String.format(MESSAGE_LISTING_FILTERED, StringUtil.formatNumTasksEvents(filteredTasks.size(), filteredEvents.size()), input);
Renderer.renderSelected(TodoListDB.getInstance(), consoleMessage, filteredTasks, filteredEvents);
}

Expand All @@ -126,18 +115,4 @@ private boolean containsTokens(Collection<String[]> tokensCollection) {

return false;
}

private String formatShowingWhat(boolean isTask, boolean isEvent) {
ArrayList<String> showingWhat = new ArrayList<>();

if (isTask) {
showingWhat.add("tasks");
}

if (isEvent) {
showingWhat.add("events");
}

return String.join(" and ", showingWhat);
}
}

0 comments on commit 4317579

Please sign in to comment.