Skip to content

Commit

Permalink
Fix package violation
Browse files Browse the repository at this point in the history
  • Loading branch information
daryltay415 committed Apr 1, 2024
1 parent e852cb0 commit f9f62f5
Show file tree
Hide file tree
Showing 12 changed files with 546 additions and 542 deletions.
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
package seedu.omnitravel.error_handlers;

import seedu.omnitravel.ui.Ui;

import java.io.IOException;
import java.time.DateTimeException;
import java.util.NoSuchElementException;

import static seedu.omnitravel.parser.Parser.isNumeric;

public class CheckParameters {

/**
* Checks for all possible input errors that users may make and throws the corresponding exceptions
*
* @param input Input array that users placed into the chatbot
* @throws OmniException when any of the corresponding input format is wrong
*/
public static void addExceptions(String[] input) throws OmniException{
if (input.length >= 4 && input[1].isBlank()) {
throw new OmniException("The description cannot be empty!");
} else if (input.length >= 4 && input[2].isBlank()) {
throw new OmniException("The date cannot be empty!");
} else if (input.length >= 4 && input[3].isBlank()) {
throw new OmniException("The duration cannot be empty!");
} else if (input.length >= 5 && input[4].isBlank()) {
throw new OmniException("The tag cannot be empty!");
} else if (input.length < 4 || input[3].contains("/tag")){
throw new OmniException("Please check that your add command is in this format: add DESCRIPTION " +
"/date YYYY-MM-DD /duration DURATION"
+ " or add DESCRIPTION /date YYYY-MM-DD /duration DURATION /tag TAG");
}
}

/**
* Checks for all possible input errors that users may make when updating and throws the corresponding exceptions
*
* @param command Command array that users placed into the chatbot
* @throws OmniException when any of the corresponding input format is wrong
*/
public static void updateExceptions(String[] command) throws OmniException {
if (command.length >= 4 && (command[1].isBlank() || !isNumeric(command[1]))) {
throw new OmniException("The update index cannot be empty or non numerical!");
} else if (command.length >= 4 && command[2].isBlank()) {
throw new OmniException("The date cannot be empty!");
} else if (command.length >= 4 && command[3].isBlank()) {
throw new OmniException("The duration cannot be empty!");
} else if(command.length >= 5 && command[4].isBlank()){
throw new OmniException("The tag cannot be empty!");
} else if (command.length >= 4 && !command[3].contains("/tag")) {
throw new OmniException("Please check that your update command is in this format: update INDEX " +
"/date YYYY-MM-DD /duration DURATION"
+ " or update INDEX /date YYYY-MM-DD /duration DURATION /tag TAG");
}
}

/**
* Checks for all format errors in the user input and throes the correct exceptions
*
* @param exception Exception thrown
*/
public static void handleException(Exception exception) {
if (exception instanceof OmniException) {
Ui.printException((OmniException) exception);
} else if (exception instanceof NoSuchElementException) {
Ui.printNoSuchElementException((NoSuchElementException) exception);
} else if (exception instanceof NumberFormatException) {
Ui.printNumberTooLargeException((NumberFormatException) exception);
} else if (exception instanceof DateTimeException) {
Ui.printDateTimeExceptionError();
} else if (exception instanceof IOException) {
Ui.printSavingError();
}
}
}
package seedu.omnitravel.errorhandlers;

import seedu.omnitravel.ui.Ui;

import java.io.IOException;
import java.time.DateTimeException;
import java.util.NoSuchElementException;

import static seedu.omnitravel.parser.Parser.isNumeric;

public class CheckParameters {

/**
* Checks for all possible input errors that users may make and throws the corresponding exceptions
*
* @param input Input array that users placed into the chatbot
* @throws OmniException when any of the corresponding input format is wrong
*/
public static void addExceptions(String[] input) throws OmniException{
if (input.length >= 4 && input[1].isBlank()) {
throw new OmniException("The description cannot be empty!");
} else if (input.length >= 4 && input[2].isBlank()) {
throw new OmniException("The date cannot be empty!");
} else if (input.length >= 4 && input[3].isBlank()) {
throw new OmniException("The duration cannot be empty!");
} else if (input.length >= 5 && input[4].isBlank()) {
throw new OmniException("The tag cannot be empty!");
} else if (input.length < 4 || input[3].contains("/tag")){
throw new OmniException("Please check that your add command is in this format: add DESCRIPTION " +
"/date YYYY-MM-DD /duration DURATION"
+ " or add DESCRIPTION /date YYYY-MM-DD /duration DURATION /tag TAG");
}
}

/**
* Checks for all possible input errors that users may make when updating and throws the corresponding exceptions
*
* @param command Command array that users placed into the chatbot
* @throws OmniException when any of the corresponding input format is wrong
*/
public static void updateExceptions(String[] command) throws OmniException {
if (command.length >= 4 && (command[1].isBlank() || !isNumeric(command[1]))) {
throw new OmniException("The update index cannot be empty or non numerical!");
} else if (command.length >= 4 && command[2].isBlank()) {
throw new OmniException("The date cannot be empty!");
} else if (command.length >= 4 && command[3].isBlank()) {
throw new OmniException("The duration cannot be empty!");
} else if(command.length >= 5 && command[4].isBlank()){
throw new OmniException("The tag cannot be empty!");
} else if (command.length >= 4 && !command[3].contains("/tag")) {
throw new OmniException("Please check that your update command is in this format: update INDEX " +
"/date YYYY-MM-DD /duration DURATION"
+ " or update INDEX /date YYYY-MM-DD /duration DURATION /tag TAG");
}
}

/**
* Checks for all format errors in the user input and throes the correct exceptions
*
* @param exception Exception thrown
*/
public static void handleException(Exception exception) {
if (exception instanceof OmniException) {
Ui.printException((OmniException) exception);
} else if (exception instanceof NoSuchElementException) {
Ui.printNoSuchElementException((NoSuchElementException) exception);
} else if (exception instanceof NumberFormatException) {
Ui.printNumberTooLargeException((NumberFormatException) exception);
} else if (exception instanceof DateTimeException) {
Ui.printDateTimeExceptionError();
} else if (exception instanceof IOException) {
Ui.printSavingError();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.omnitravel.error_handlers;

public class OmniException extends Exception {
public OmniException(String errorMessage){
super(errorMessage);
}
}
package seedu.omnitravel.errorhandlers;

public class OmniException extends Exception {
public OmniException(String errorMessage){
super(errorMessage);
}
}
6 changes: 3 additions & 3 deletions src/main/java/seedu/omnitravel/omnitravel/OmniTravel.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package seedu.omnitravel.omnitravel;
import seedu.omnitravel.parser.Parser;
import seedu.omnitravel.travel_activity_types.TravelActivityList;
import seedu.omnitravel.travelactivitytypes.TravelActivityList;
import seedu.omnitravel.ui.Ui;
import seedu.omnitravel.error_handlers.CheckParameters;
import seedu.omnitravel.error_handlers.OmniException;
import seedu.omnitravel.errorhandlers.CheckParameters;
import seedu.omnitravel.errorhandlers.OmniException;
import seedu.omnitravel.storage.FileSave;

import java.io.IOException;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/seedu/omnitravel/parser/Parser.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package seedu.omnitravel.parser;
import seedu.omnitravel.travel_activity_types.TravelActivityList;
import seedu.omnitravel.error_handlers.CheckParameters;
import seedu.omnitravel.error_handlers.OmniException;
import seedu.omnitravel.travel_activity_types.Accommodation;
import seedu.omnitravel.travel_activity_types.Food;
import seedu.omnitravel.travel_activity_types.Landmark;
import seedu.omnitravel.travel_activity_types.TravelActivity;
import seedu.omnitravel.travelactivitytypes.TravelActivityList;
import seedu.omnitravel.errorhandlers.CheckParameters;
import seedu.omnitravel.errorhandlers.OmniException;
import seedu.omnitravel.travelactivitytypes.Accommodation;
import seedu.omnitravel.travelactivitytypes.Food;
import seedu.omnitravel.travelactivitytypes.Landmark;
import seedu.omnitravel.travelactivitytypes.TravelActivity;
import seedu.omnitravel.ui.Ui;

import java.time.LocalDate;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/omnitravel/storage/FileSave.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package seedu.omnitravel.storage;
import seedu.omnitravel.travel_activity_types.TravelActivityList;
import seedu.omnitravel.travel_activity_types.Accommodation;
import seedu.omnitravel.travel_activity_types.Food;
import seedu.omnitravel.travel_activity_types.Landmark;
import seedu.omnitravel.travel_activity_types.TravelActivity;
import seedu.omnitravel.travelactivitytypes.TravelActivityList;
import seedu.omnitravel.travelactivitytypes.Accommodation;
import seedu.omnitravel.travelactivitytypes.Food;
import seedu.omnitravel.travelactivitytypes.Landmark;
import seedu.omnitravel.travelactivitytypes.TravelActivity;

import java.io.FileWriter;
import java.io.FileNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package seedu.omnitravel.travel_activity_types;

import java.time.LocalDate;

public class Accommodation extends TravelActivity {
private LocalDate date;
private String duration;

public Accommodation(String line, LocalDate date, String duration, String tag, String expense){
super(line, date, duration, tag, expense);
}

@Override
public String toString(){
return "Accommodation: " + super.toString();
}

}
package seedu.omnitravel.travelactivitytypes;

import java.time.LocalDate;

public class Accommodation extends TravelActivity {
private LocalDate date;
private String duration;

public Accommodation(String line, LocalDate date, String duration, String tag, String expense){
super(line, date, duration, tag, expense);
}

@Override
public String toString(){
return "Accommodation: " + super.toString();
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package seedu.omnitravel.travel_activity_types;

import java.time.LocalDate;

public class Food extends TravelActivity {
public Food(String line, LocalDate date, String duration, String tag, String expense){
super(line, date, duration, tag, expense);
}

@Override
public String toString(){
return "Food: " + super.toString();
}
}
package seedu.omnitravel.travelactivitytypes;

import java.time.LocalDate;

public class Food extends TravelActivity {
public Food(String line, LocalDate date, String duration, String tag, String expense){
super(line, date, duration, tag, expense);
}

@Override
public String toString(){
return "Food: " + super.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package seedu.omnitravel.travel_activity_types;

import java.time.LocalDate;

public class Landmark extends TravelActivity {
public Landmark(String line, LocalDate date, String duration, String tag, String expense){
super(line, date, duration, tag, expense);
}
@Override
public String toString(){
return "Landmark: " + super.toString();
}
}
package seedu.omnitravel.travelactivitytypes;

import java.time.LocalDate;

public class Landmark extends TravelActivity {
public Landmark(String line, LocalDate date, String duration, String tag, String expense){
super(line, date, duration, tag, expense);
}
@Override
public String toString(){
return "Landmark: " + super.toString();
}
}
Loading

0 comments on commit f9f62f5

Please sign in to comment.