Skip to content

Commit

Permalink
Merge pull request #3 from rexkoh425/branch-A-JavaDoc
Browse files Browse the repository at this point in the history
Branch a java doc
  • Loading branch information
rexkoh425 authored Sep 23, 2024
2 parents 2ba59c4 + 29fde76 commit e1bee70
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 21 deletions.
44 changes: 34 additions & 10 deletions src/main/java/TheThinker/Parser/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import java.time.LocalDate;
import java.time.format.DateTimeParseException;

public class Date {
public interface Date {

public static DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HHmm");
public static DateTimeFormatter resultDateTimeFormatter = DateTimeFormatter.ofPattern("dd MMMM yyyy , h a");
public static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HHmm");
DateTimeFormatter resultDateTimeFormatter = DateTimeFormatter.ofPattern("dd MMMM yyyy , h a");
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");

private static LocalDateTime parseIntoDateTimeObject(String date){
return LocalDateTime.parse(date, dateTimeFormatter);
Expand All @@ -21,7 +21,15 @@ private static String toString(String date) {
return dateObject.format(resultDateTimeFormatter); // -> Oct 15 2019
}

public static String convertDateFormat(String date) {
/**
* Converts date from format of dd/MM/yyyy HHmm to dd MMMM yyyy , h a.
* If date is not of dd/MM/yyyy HHmm format, the original string is returned.
*
* @param date deadline of task extracted from user input
* @return date of string type with format e.g. 15 October 2019 , 6 pm.
*
*/
static String convertDateFormat(String date) {
String[] dateParameters = date.split("/");
if(dateParameters.length != 3 || !isDateTimeFormat(date)) {
return date;
Expand Down Expand Up @@ -50,22 +58,38 @@ private static int isValidDay(String day) {
return dayInt;
}

public static boolean isMatchingDate(String specifiedDate , String taskDate) {
/**
* Returns boolean if day , month and year of both parameters are same , ignoring time.
*
* @param specifiedDate date in format of dd/MM/yyyy.
* @param taskDate date in format of dd MMMM yyyy , h a.
* @return boolean
*
*/
private static boolean isMatchingDate(String specifiedDate , String taskDate) {
LocalDate parsedDate = LocalDate.parse(specifiedDate, dateFormatter);
LocalDateTime parsedDateTime = LocalDateTime.parse(taskDate, resultDateTimeFormatter);
return parsedDate.getMonthValue() == parsedDateTime.getMonthValue() &&
parsedDate.getDayOfMonth() == parsedDateTime.getDayOfMonth() &&
parsedDate.getYear() == parsedDateTime.getYear();
}

public static boolean isMatchingDateByType(Task task , String specifiedDate){
/**
* Returns true if day , month and year matches according to deadlines by task type.
* If task type is not event or deadline, return false.
*
* @param task Object of type task and subclasses.
* @param specifiedDate date in format of dd/MM/yyyy.
* @return boolean
*/
static boolean isMatchingDateByType(Task task , String specifiedDate){
if((task.getTaskType() == 'D' || task.getTaskType() == 'E') && isResultDateTimeFormat(task.getTaskDate())){
return isMatchingDate(specifiedDate , task.getTaskDate());
}
return false;
}

public static boolean isDateOnlyFormat(String dateStr){
static boolean isDateOnlyFormat(String dateStr){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");

try {
Expand All @@ -76,7 +100,7 @@ public static boolean isDateOnlyFormat(String dateStr){
}
}

public static boolean isDateTimeFormat(String dateStr){
static boolean isDateTimeFormat(String dateStr){

try {
LocalDate date = LocalDate.parse(dateStr, dateTimeFormatter);
Expand All @@ -86,7 +110,7 @@ public static boolean isDateTimeFormat(String dateStr){
}
}

public static boolean isResultDateTimeFormat(String dateStr){
static boolean isResultDateTimeFormat(String dateStr){

try {
LocalDate date = LocalDate.parse(dateStr, resultDateTimeFormatter);
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/TheThinker/Parser/UserInputParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Scanner;

public class UserInputParser {

public static String userInput;
public static final Scanner scanner = new Scanner(System.in);
public static final int LENGTH_OF_TODO = 4;
Expand All @@ -23,6 +24,12 @@ public class UserInputParser {
public static final String GET_FORMAT = "Please follow format : get [dd/mm/yyyy]";
public static final String FIND_FORMAT = "Please follow format : find [keyword]";

/**
* Parse user input based on the format of To-do and use the result to create To-do object
*
* @return To-do Object
* @throws FormattingException if task description is not provided in user input
*/
public static Task parseTodo() throws FormattingException {

String taskDescription = userInput.substring(LENGTH_OF_TODO).trim();
Expand All @@ -34,6 +41,13 @@ public static Task parseTodo() throws FormattingException {
return new Todo(taskDescription);
}

/**
* Parse user input based on the format of Event and use the result to create Event object.
*
* @return Event Object.
* @throws FormattingException If /from , /to , task description , start time and end time
* is missing from user input
*/
public static Event parseEvent() throws FormattingException{

String remainingTaskDescription = userInput.substring(LENGTH_OF_EVENT).trim();
Expand Down Expand Up @@ -71,6 +85,12 @@ public static Event parseEvent() throws FormattingException{
return new Event(taskDescription , startTime, endTime);
}

/**
* Parse user input based on the format of Deadline and use the result to create Deadline object.
*
* @return Deadline Object.
* @throws FormattingException If /by , task description , deadline is missing from user input
*/
public static Deadline parseDeadline() throws FormattingException{

String remainingTaskDescription = userInput.substring(LENGTH_OF_DEADLINE).trim();
Expand Down Expand Up @@ -106,6 +126,13 @@ public static String parseUserAction(){
return wordsInUserInput[0];
}

/**
* Parses the task number after unmark or mark command
*
* @return Task number
* @throws NumberFormatException If task number string provided is not a number.
* @throws FormattingException If no task or multiple task number is provided.
*/
public static int parseNumberAfterTask() throws NumberFormatException , FormattingException{
String[] parsedInputs = userInput.split(" ");

Expand All @@ -121,6 +148,12 @@ public static int parseNumberAfterTask() throws NumberFormatException , Formatti
return Integer.parseInt(numberToMark);
}

/**
* Parse date after get command
*
* @return date in dd/MM/yyyy format
* @throws FormattingException If date is missing or in the wrong format
*/
public static String parseDateAfterGet() throws FormattingException{
String[] parsedInputs = userInput.split(" ");
if(parsedInputs.length != 2){
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/TheThinker/Tasks/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package TheThinker.Tasks;

/**
* Represents a deadline type task. A deadline object contains
* task type , task description ,
* deadline of format dd/MMMM/yyyy h a.
*
*/
public class Deadline extends Task{
public String deadline;

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/TheThinker/Tasks/Event.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package TheThinker.Tasks;

/**
* Represents an event type task. An event object contains
* task type , task description ,
* start time and end time of format dd/MMMM/yyyy h a.
*
*/
public class Event extends Task{
public String startTime;
public String endTime;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/TheThinker/Tasks/Task.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package TheThinker.Tasks;

/**
* Represents an event type task. A Task object contains
* task type , task description.
*/
public class Task {
public String taskDescription;
public boolean isMarkedAsDone;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/TheThinker/Tasks/TaskList.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package TheThinker.Tasks;

import TheThinker.Parser.Date;

import java.util.ArrayList;

public class TaskList {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/TheThinker/Tasks/Todo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package TheThinker.Tasks;

/**
* Represents a to-do type task. A to-do object contains
* task type , task description.
*/
public class Todo extends Task{

public Todo(String taskDescription){
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/TheThinker/Ui/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
import TheThinker.Tasks.TaskList;
import java.io.IOException;

public class CommandLine {

public static void pollForUserInputTillBye(NewFile data) {
/**
* CommandLine handles all the commandLine related method
*/
public interface CommandLine {

/**
* Checks for user input and do corresponding command
* and write task to file till bye command.
*
* @param data File created to accept task input
*/
static void pollForUserInputTillBye(NewFile data) {
String userInput;
do{
userInput = getUserInputAndDoTask();
Expand All @@ -20,6 +29,11 @@ public static void pollForUserInputTillBye(NewFile data) {
}while(!userInput.equals("bye"));
}

/**
* Checks for user input and do corresponding command and write task to file.
*
* @return the original trimmed user input
*/
private static String getUserInputAndDoTask() {
String userInput;
userInput = UserInputParser.getUserInput();
Expand All @@ -28,6 +42,11 @@ private static String getUserInputAndDoTask() {
return userInput;
}

/**
* Do corresponding actions depending on the command by the user.
*
* @param userAction the first word of the user input.
*/
private static void doTaskAccordingToUserAction(String userAction){
UiControl.printSeparation();
try {
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/TheThinker/Ui/UiControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@

import TheThinker.Command.TheThinker;

public class UiControl {
/**
* Interface controls all the Ui methods
*/
public interface UiControl {

public static void printGreeting() {
static void printGreeting() {
UiControl.printSeparation();
System.out.println("Hello! I'm " + TheThinker.NAME);
System.out.println("What can I do for you?");
UiControl.printSeparation();
}

public static void printBye() {
static void printBye() {
System.out.println("Bye. Hope to see you again soon!");
}

public static void printSeparation() {
static void printSeparation() {
System.out.println("_".repeat(60));
}

public static void printHelp(){
static void printHelp(){
System.out.println("Formats for the commands are : ");
System.out.println("mark : mark [number]");
System.out.println("unmark : unmark [number]");
Expand All @@ -31,15 +34,15 @@ public static void printHelp(){
System.out.println("find : find [keyword]");
}

public static void printCommands(){
static void printCommands(){
System.out.println("Command entered is not valid. Available commands are");
String[] commands = {"mark" , "unmark" , "todo" , "delete", "event" , "deadline" , "list" , "bye" , "get" , "find", "help (get format)"};
for(String command : commands){
System.out.println("- " + command);
}
}

public static void printLoadingText(){
static void printLoadingText(){
System.out.println("Loading file now........");
}
}

0 comments on commit e1bee70

Please sign in to comment.