Skip to content

Commit

Permalink
codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
tatayu committed Nov 11, 2019
1 parent 5a6de7c commit b24257f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 46 deletions.
6 changes: 3 additions & 3 deletions src/main/java/dolla/Dolla.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ private void verifyIsExit(String string) {
}

private void run() throws DollaException {
LogsCentre.logSetter();
LogsCentre.setLogger.info("***********************DOLLA RUNNING***********************");
LogsCentreUtil.logSetter();
LogsCentreUtil.setLogger.info("***********************DOLLA RUNNING***********************");
Reminder reminder = new Reminder(MODE_DEBT);
reminder.showReminder(dollaData);
Scanner input = new Scanner(System.in); // TODO: Add to Ui or MainParser instead?
Expand All @@ -40,7 +40,7 @@ private void run() throws DollaException {
Command c = MainParser.handleInput(mode, inputLine);
c.execute(dollaData);
}
LogsCentre.setLogger.info("************************DOLLA TERMINATED************************");
LogsCentreUtil.setLogger.info("************************DOLLA TERMINATED************************");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.logging.SimpleFormatter;


public class LogsCentre {
public class LogsCentreUtil {

public static final Logger setLogger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);

Expand All @@ -19,13 +19,9 @@ public class LogsCentre {
public static void logSetter() {
LogManager.getLogManager().reset();
setLogger.setLevel(Level.ALL);
// ConsoleHandler ch = new ConsoleHandler();
// ch.setLevel(Level.FINEST);
// setLogger.addHandler(ch);

try {
FileHandler fh = new FileHandler("./data/dollaLogger.log",true);
fh.setLevel(Level.FINE);
fh.setLevel(Level.INFO);
fh.setFormatter(new SimpleFormatter());
setLogger.addHandler(fh);
} catch (IOException e) {
Expand Down
54 changes: 27 additions & 27 deletions src/main/java/dolla/parser/Parser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dolla.parser;

import dolla.LogsCentre;
import dolla.LogsCentreUtil;
import dolla.ModeStringList;
import dolla.Time;
import dolla.model.RecordList;
Expand Down Expand Up @@ -87,7 +87,7 @@ protected void extractDescTime() throws Exception {
date = Time.readDate(dateString.trim());
} catch (DateTimeParseException e) {
Ui.printDateFormatError();
LogsCentre.setLogger.log(Level.SEVERE, "Invalid date.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid date.", e);
throw new DollaException(INVALID_DATE_EXCEPTION);
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@ public static double stringToDouble(String str) throws Exception {
}
} catch (NumberFormatException e) {
Ui.printInvalidNumberError(str);
LogsCentre.setLogger.log(Level.SEVERE, "Invalid amount", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid amount", e);
throw new NumberFormatException(INVALID_AMOUNT_EXCEPTION);
}
return newDouble;
Expand All @@ -145,7 +145,7 @@ private static String verifyAddType(String s) throws Exception {
return s;
} else {
EntryUi.printInvalidEntryType();
LogsCentre.setLogger.log(Level.SEVERE, "Invalid entry type.");
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid entry type.");
throw new DollaException(DollaException.invalidType());
}
}
Expand All @@ -162,10 +162,10 @@ protected boolean verifyAddCommand() {
extractDescTime();
} catch (IndexOutOfBoundsException e) {
EntryUi.printInvalidEntryFormatError();
LogsCentre.setLogger.log(Level.SEVERE, "Invalid entry format.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid entry format.", e);
return false;
} catch (Exception e) {
LogsCentre.setLogger.log(Level.SEVERE, "Error occurs.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Error occurs.", e);
return false; // If error occurs, stop the method!
}
return true;
Expand All @@ -184,7 +184,7 @@ public boolean verifyDebtCommand() {
DebtUi.printInvalidNameMessage();
return false;
} catch (Exception ignored) {
LogsCentre.setLogger.log(Level.SEVERE, "Error occurs");
LogsCentreUtil.setLogger.log(Level.SEVERE, "Error occurs");
//do nothing
}
amount = stringToDouble(inputArray[2]);
Expand All @@ -194,7 +194,7 @@ public boolean verifyDebtCommand() {
return checkDate(dateString[1]);
} catch (Exception e) {
DebtUi.printInvalidDebtFormatError();
LogsCentre.setLogger.log(Level.SEVERE, "Invalid debt format", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid debt format", e);
return false;
}
}
Expand All @@ -210,7 +210,7 @@ private boolean checkDate(String dateString) {
date = Time.readDate(dateString);
} catch (DateTimeParseException e) {
Ui.printDateFormatError();
LogsCentre.setLogger.log(Level.SEVERE, "Date format error", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Date format error", e);
return false;
}
return true;
Expand Down Expand Up @@ -284,7 +284,7 @@ protected boolean verifyRemove() {
return false;
}
} catch (NumberFormatException e) {
LogsCentre.setLogger.log(Level.SEVERE, "Invalid remove message.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid remove message.", e);
RemoveUi.printInvalidRemoveMessage();
return false;
}
Expand All @@ -303,7 +303,7 @@ protected boolean verifyRemoveForDebtMode() {
return false;
}
} catch (NumberFormatException e) {
LogsCentre.setLogger.log(Level.SEVERE, "Invalid number.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid number.", e);
return false;
}
return true;
Expand Down Expand Up @@ -347,7 +347,7 @@ protected boolean verifyRemoveBill(RecordList recordList) {
return true;
}
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
LogsCentre.setLogger.log(Level.SEVERE, "Invalid number.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid number.", e);
return false;
}
} else {
Expand All @@ -373,7 +373,7 @@ protected boolean verifyShortcut() {
}
} catch (NumberFormatException e) {
ShortcutUi.printInvalidShortcutMessage();
LogsCentre.setLogger.log(Level.SEVERE, "Invalid shortcut", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid shortcut", e);
return false;
}
return true;
Expand All @@ -392,7 +392,7 @@ protected boolean verifyFullModifyCommand() {
Integer.parseInt(inputArray[1]);
} catch (Exception e) {
ModifyUi.printInvalidFullModifyFormatError();
LogsCentre.setLogger.log(Level.SEVERE, "Invalid full modify format.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid full modify format.", e);
return false;
}
return true;
Expand All @@ -417,7 +417,7 @@ protected boolean verifyPartialModifyCommand() {
modifyRecordNum = Integer.parseInt(inputArray[1]);
} catch (Exception e) {
ModifyUi.printInvalidPartialModifyFormatError();
LogsCentre.setLogger.log(Level.SEVERE, "Invalid partial modify format", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid partial modify format", e);
return false;
}

Expand Down Expand Up @@ -464,14 +464,14 @@ private boolean findComponents() {

} catch (ArrayIndexOutOfBoundsException e) {
ModifyUi.printMissingComponentInfoError(currStr);
LogsCentre.setLogger.log(Level.SEVERE, "Missing component information error", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Missing component information error", e);
return false;
} catch (DateTimeParseException e) {
LogsCentre.setLogger.log(Level.SEVERE, "Date format error", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Date format error", e);
Ui.printDateFormatError();
return false;
} catch (Exception e) {
LogsCentre.setLogger.log(Level.SEVERE, "Error occurs", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Error occurs", e);
return false;
}

Expand Down Expand Up @@ -663,7 +663,7 @@ protected Boolean verifyPaidNumberAndName() {
return true;
}
} catch (Exception e) {
LogsCentre.setLogger.log(Level.SEVERE, "Error occurs.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Error occurs.", e);
return false;
}
}
Expand Down Expand Up @@ -701,7 +701,7 @@ protected Boolean verifyDebtSearchCommand() {
}
} catch (IndexOutOfBoundsException | NullPointerException e) {
SearchUi.printInvalidSearchFormat();
LogsCentre.setLogger.log(Level.SEVERE, "Invalid search format.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid search format.", e);
return false;
}
}
Expand All @@ -719,7 +719,7 @@ protected Boolean verifyEntrySearchCommand() {
return false;
}
} catch (IndexOutOfBoundsException | NullPointerException e) {
LogsCentre.setLogger.log(Level.SEVERE, "Invalid search format.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid search format.", e);
SearchUi.printInvalidSearchFormat();
return false;
}
Expand All @@ -739,7 +739,7 @@ protected Boolean verifyLimitSearchCommand() {
}
} catch (IndexOutOfBoundsException | NullPointerException e) {
SearchUi.printInvalidSearchFormat();
LogsCentre.setLogger.log(Level.SEVERE, "Invalid search format.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid search format.", e);
return false;
}
}
Expand All @@ -758,7 +758,7 @@ protected Boolean verifyShortcutSearchCommand() {
}
} catch (IndexOutOfBoundsException | NullPointerException e) {
SearchUi.printInvalidSearchFormat();
LogsCentre.setLogger.log(Level.SEVERE, "Invalid search format.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid search format.", e);
return false;
}
}
Expand Down Expand Up @@ -800,7 +800,7 @@ protected Boolean verifyBillPeopleAndAmount() {
stringToDouble(inputArray[2]);
} catch (Exception e) {
DebtUi.printInvalidBillFormatError();
LogsCentre.setLogger.log(Level.SEVERE, "Invalid bill format.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid bill format.", e);
return false;
}
return true;
Expand Down Expand Up @@ -830,10 +830,10 @@ protected Boolean verifyAddBillCommand(ArrayList<String> nameList) {
}
} catch (IndexOutOfBoundsException e) {
DebtUi.printWrongPeopleNumberMessage(Integer.parseInt(inputArray[1]));
LogsCentre.setLogger.log(Level.SEVERE, "Wrong people number.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Wrong people number.", e);
return false;
} catch (Exception e) {
LogsCentre.setLogger.log(Level.SEVERE, "Error occurs.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Error occurs.", e);
return false;
}
return true;
Expand All @@ -846,7 +846,7 @@ protected Boolean verifySetCommand() {
amount = stringToDouble(inputArray[2]);
duration = verifyLimitDuration(inputArray[3]);
} catch (Exception e) {
LogsCentre.setLogger.log(Level.SEVERE, "Error occurs", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Error occurs", e);
return false;
}
return true;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/dolla/storage/Storage.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package dolla.storage;

import dolla.LogsCentre;
import dolla.LogsCentreUtil;
import dolla.model.Record;
import dolla.ui.Ui;

import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.logging.Level;

Expand All @@ -30,7 +29,7 @@ protected static double stringToDouble(String str) {
newDouble = Double.parseDouble(str);
} catch (NumberFormatException e) {
Ui.printInvalidNumberError(str);
LogsCentre.setLogger.log(Level.SEVERE, "Invalid number.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Invalid number.", e);
}
return newDouble;
}
Expand Down Expand Up @@ -86,7 +85,7 @@ public static void clearStorage() {
file.close();
} catch (IOException e) {
e.printStackTrace();
LogsCentre.setLogger.log(Level.SEVERE, "Clear storage fail.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Clear storage fail.", e);
}
}
}
8 changes: 4 additions & 4 deletions src/main/java/dolla/storage/StorageRead.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dolla.storage;

import dolla.LogsCentre;
import dolla.LogsCentreUtil;
import dolla.Time;
import dolla.parser.MainParser;
import dolla.model.Debt;
Expand Down Expand Up @@ -96,13 +96,13 @@ public static void load() {
addToList(type, newRecord);
}
StorageWrite.save();
LogsCentre.setLogger.log(Level.INFO,"Save file successfully loaded.");
LogsCentreUtil.setLogger.log(Level.INFO,"Save file successfully loaded.");
} catch (FileNotFoundException e) {
StorageUi.printCreateFolderMessage();
LogsCentre.setLogger.log(Level.SEVERE, "Create a new save file.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Create a new save file.", e);
} catch (IOException e) {
StorageUi.printErrorReadingSaveMessage();
LogsCentre.setLogger.log(Level.SEVERE, "Error reading dolla.txt.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Error reading dolla.txt.", e);
MainParser.exit(); // TODO: Find out what is supposed to happen here
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dolla/storage/StorageWrite.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dolla.storage;

import dolla.LogsCentre;
import dolla.LogsCentreUtil;
import dolla.model.Record;
import dolla.ui.StorageUi;

Expand Down Expand Up @@ -77,7 +77,7 @@ protected static void save() {

} catch (IOException e) {
StorageUi.printErrorWritingSaveMessage();
LogsCentre.setLogger.log(Level.SEVERE, "Error writing to Dolla.", e);
LogsCentreUtil.setLogger.log(Level.SEVERE, "Error writing to Dolla.", e);
}
}
}

0 comments on commit b24257f

Please sign in to comment.