Skip to content

Commit 3ecf0fb

Browse files
authored
Merge pull request #33 from JermyTan/master
Code cleanup
2 parents 0f6e270 + 3bb2cd9 commit 3ecf0fb

File tree

193 files changed

+2934
-3146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+2934
-3146
lines changed

README.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ifndef::env-github[]
1111
image::images/Ui.png[width="600"]
1212
endif::[]
1313

14-
Have you ever lost track of your items' expiry dates and end up throwing the items away? Have you ever open your fridge to search for your favourite chocolate, only to realise that it has already expired? Fret not! Xpire is here to save you! With features to help you keep track of your items' expiry dates as well as to remind you of soon-expiring items, you will never have to face any expired items ever again.
14+
Have you ever lost track of your items' expiry dates and end up throwing the items away? Have you ever open your fridge to search for your favourite chocolate, only to realise that it has already expired? Fret not! Xpire is here to save you! With features to help you keep track of your items' expiry dates as well as to remind you of soon-expiring items, you will never have to worry about when your items are expiring again. Next time, you will be sure to eat that chocolate before it expires!
1515

1616
Interested to try out our application? Head over to the <<UserGuide#, UserGuide>> to get started!
1717

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ plugins {
1515
}
1616

1717
// Specifies the entry point of the application
18-
mainClassName = 'seedu.address.Main'
18+
mainClassName = 'io.xpire.Main'
1919

2020
sourceCompatibility = JavaVersion.VERSION_11
2121
targetCompatibility = JavaVersion.VERSION_11

docs/UserGuide.adoc

+13-14
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ e.g. typing *`help`* and pressing kbd:[Enter] will open the help window.
4747
====
4848
*Command Format*
4949
50-
* Words that are enclosed with `<` and `>` are the parameters to be supplied by the user e.g. in `add|<item name>|<expiry date>`, `<item name>` and `<expiry date>` are parameters which can be used as `add|banana|25/09/2019`.
51-
* Items in square brackets are optional e.g `add|<item name>|<expiry date>|[#tag]` can be used as `add|strawberry|10/10/2019|#Fruit`.
52-
* Items with `…`​ after them can be used multiple times including zero times e.g. `tag|<index>|#tag...` can be used as `tag|1|#Fruit #Frozen #Cold`, `tag|1`, or `tag|1|#Fruit` etc.
53-
//* Parameters can be in any order e.g. if the command specifies `n/NAME p/PHONE_NUMBER`, `p/PHONE_NUMBER n/NAME` is also acceptable.
50+
* Words that are enclosed with `<` and `>` are the parameters to be supplied by the user e.g. in `set reminder|<index>|<threshold>`, `<index>` and `<threshold>` are parameters which can be used as `set reminder|1|7`.
51+
* Parameters in square brackets are optional e.g `check[|<days>]` can be used as `check|7` or `check`.
52+
* Optional parameters with `…`​ after them can be used multiple times including zero times e.g. `tag|<index>|[<tag>]...` can be used as `tag|1|#Fruit #Frozen #Cold`, `tag|1`, or `tag|1|#Fruit`.
5453
====
5554

5655
=== Viewing help : `help`
@@ -60,7 +59,7 @@ Format: `help`
6059
=== Adding an item: `add`
6160

6261
Adds item to list +
63-
Format: `add|<item name>|<expiry date>[|#tag...]`
62+
Format: `add|<item name>|<expiry date>|[<tag>]...`
6463

6564
[TIP]
6665
An item can have any number of tags (including 0)
@@ -102,7 +101,7 @@ Format: `view`
102101
=== Listing expiring items : `check`
103102
104103
Shows expiring items in the list. +
105-
Format: `check|<days>`
104+
Format: `check[|<days>]`
106105
107106
****
108107
* Lists items expiring within the specified number of `<days>`
@@ -117,7 +116,7 @@ Lists items expiring in the next 20 days.
117116
=== Sorting all items : `sort`
118117
119118
Sorts all items in the list by either name or date. +
120-
Format: `sort|<method>`
119+
Format: `sort|<key>`
121120
122121
****
123122
* Sorting by both name and date is done in ascending order.
@@ -133,7 +132,7 @@ Examples:
133132
=== Searching item by name: `search`
134133
135134
Search items whose names contain any of the given keywords. +
136-
Format: `search|<keyword>|[other keywords...]`
135+
Format: `search|<keyword>[|<other keywords>]...`
137136
138137
****
139138
* The search is case insensitive. e.g `ham` will match `Ham`
@@ -179,7 +178,7 @@ Deletes the 1st item in the results of the `search` command.
179178
=== Tagging an item : `tag`
180179
181180
Tags an item from the list according to user input or clears item of tags. +
182-
Format: `tag|<index>|#tag...`
181+
Format: `tag|<index>|[<tag>]...`
183182
184183
****
185184
* Tags the item at the specified `<index>`.
@@ -226,21 +225,21 @@ There is no need to save manually.
226225
227226
== Command Summary
228227
229-
* *Add* `add|<item name>|<expiry date>` +
228+
* *Add* `add|<item name>|<expiry date>|[<tag>]...` +
230229
e.g. `add|durian|30/9/2019`
231230
* *Clear* : `clear`
232231
* *Delete* : `delete|<index>` +
233232
e.g. `delete|3`
234233
* *List* : `list`
235-
* *Sort* : `sort|<method>`+
234+
* *Sort* : `sort|<key>`+
236235
e.g. `sort|date`
237236
//* *Edit* : `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]...` +
238237
//e.g. `edit 2 n/James Lee e/jameslee@example.com`
239-
* *Search* : `search|<keyword>|[other keywords...]` +
238+
* *Search* : `search|<keyword>[|<other keywords>]...` +
240239
e.g. `search|milk|tea|pearls`
241-
* *Tag* : `tag|<index>|#tag...`
240+
* *Tag* : `tag|<index>|[<tag>]...`
242241
* *View* : `view`
243-
* *Check* : `check|<days>` +
242+
* *Check* : `check[|<days>]` +
244243
e.g. `check|20`
245244
* *Help* : `help`
246245

src/main/java/seedu/address/AppParameters.java src/main/java/io/xpire/AppParameters.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
package seedu.address;
1+
package io.xpire;
22

33
import java.nio.file.Path;
44
import java.nio.file.Paths;
55
import java.util.Map;
66
import java.util.Objects;
77
import java.util.logging.Logger;
88

9+
import io.xpire.commons.core.LogsCenter;
10+
import io.xpire.commons.util.FileUtil;
911
import javafx.application.Application;
10-
import seedu.address.commons.core.LogsCenter;
11-
import seedu.address.commons.util.FileUtil;
1212

1313
/**
1414
* Represents the parsed command-line parameters given to the application.

src/main/java/seedu/address/Main.java src/main/java/io/xpire/Main.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package seedu.address;
1+
package io.xpire;
22

33
import javafx.application.Application;
44

src/main/java/seedu/address/MainApp.java src/main/java/io/xpire/MainApp.java

+36-36
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
package seedu.address;
1+
package io.xpire;
22

33
import java.io.IOException;
44
import java.nio.file.Path;
55
import java.util.Optional;
66
import java.util.logging.Logger;
77

8+
import io.xpire.commons.core.Config;
9+
import io.xpire.commons.core.LogsCenter;
10+
import io.xpire.commons.core.Version;
11+
import io.xpire.commons.exceptions.DataConversionException;
12+
import io.xpire.commons.util.ConfigUtil;
13+
import io.xpire.commons.util.StringUtil;
14+
import io.xpire.logic.Logic;
15+
import io.xpire.logic.LogicManager;
16+
import io.xpire.model.Model;
17+
import io.xpire.model.ModelManager;
18+
import io.xpire.model.ReadOnlyUserPrefs;
19+
import io.xpire.model.ReadOnlyXpire;
20+
import io.xpire.model.UserPrefs;
21+
import io.xpire.model.Xpire;
22+
import io.xpire.model.util.SampleDataUtil;
23+
import io.xpire.storage.JsonUserPrefsStorage;
24+
import io.xpire.storage.JsonXpireStorage;
25+
import io.xpire.storage.Storage;
26+
import io.xpire.storage.StorageManager;
27+
import io.xpire.storage.UserPrefsStorage;
28+
import io.xpire.storage.XpireStorage;
29+
import io.xpire.ui.Ui;
30+
import io.xpire.ui.UiManager;
831
import javafx.application.Application;
932
import javafx.stage.Stage;
10-
import seedu.address.commons.core.Config;
11-
import seedu.address.commons.core.LogsCenter;
12-
import seedu.address.commons.core.Version;
13-
import seedu.address.commons.exceptions.DataConversionException;
14-
import seedu.address.commons.util.ConfigUtil;
15-
import seedu.address.commons.util.StringUtil;
16-
import seedu.address.logic.Logic;
17-
import seedu.address.logic.LogicManager;
18-
import seedu.address.model.ExpiryDateTracker;
19-
import seedu.address.model.Model;
20-
import seedu.address.model.ModelManager;
21-
import seedu.address.model.ReadOnlyExpiryDateTracker;
22-
import seedu.address.model.ReadOnlyUserPrefs;
23-
import seedu.address.model.UserPrefs;
24-
import seedu.address.model.util.SampleDataUtil;
25-
import seedu.address.storage.ExpiryDateTrackerStorage;
26-
import seedu.address.storage.JsonExpiryDateTrackerStorage;
27-
import seedu.address.storage.JsonUserPrefsStorage;
28-
import seedu.address.storage.Storage;
29-
import seedu.address.storage.StorageManager;
30-
import seedu.address.storage.UserPrefsStorage;
31-
import seedu.address.ui.Ui;
32-
import seedu.address.ui.UiManager;
3333

3434
/**
3535
* Runs the application.
@@ -48,18 +48,18 @@ public class MainApp extends Application {
4848

4949
@Override
5050
public void init() throws Exception {
51-
logger.info("=============================[ Initializing ExpiryDateTracker ]===========================");
51+
logger.info("=============================[ Initializing Xpire ]===========================");
5252
super.init();
5353

5454
AppParameters appParameters = AppParameters.parse(getParameters());
5555
config = initConfig(appParameters.getConfigPath());
5656

5757
UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath());
5858
UserPrefs userPrefs = initPrefs(userPrefsStorage);
59-
ExpiryDateTrackerStorage expiryDateTrackerStorage = new JsonExpiryDateTrackerStorage(
60-
userPrefs.getExpiryDateTrackerFilePath()
59+
XpireStorage xpireStorage = new JsonXpireStorage(
60+
userPrefs.getXpireFilePath()
6161
);
62-
storage = new StorageManager(expiryDateTrackerStorage, userPrefsStorage);
62+
storage = new StorageManager(xpireStorage, userPrefsStorage);
6363

6464
initLogging(config);
6565

@@ -77,20 +77,20 @@ public void init() throws Exception {
7777
* {@code storage}'s expiry date tracker.
7878
*/
7979
private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
80-
Optional<ReadOnlyExpiryDateTracker> expiryDateTrackerOptional;
81-
ReadOnlyExpiryDateTracker initialData;
80+
Optional<ReadOnlyXpire> expiryDateTrackerOptional;
81+
ReadOnlyXpire initialData;
8282
try {
83-
expiryDateTrackerOptional = storage.readExpiryDateTracker();
83+
expiryDateTrackerOptional = storage.readXpire();
8484
if (!expiryDateTrackerOptional.isPresent()) {
8585
logger.info("Data file not found. Will be starting with a sample Expiry Date Tracker");
8686
}
87-
initialData = expiryDateTrackerOptional.orElseGet(SampleDataUtil::getSampleExpiryDateTracker);
87+
initialData = expiryDateTrackerOptional.orElseGet(SampleDataUtil::getSampleXpire);
8888
} catch (DataConversionException e) {
8989
logger.warning("Data file not in the correct format. Will be starting with an empty Expiry Date Tracker");
90-
initialData = new ExpiryDateTracker();
90+
initialData = new Xpire();
9191
} catch (IOException e) {
9292
logger.warning("Problem while reading from the file. Will be starting with an empty Expiry Date Tracker");
93-
initialData = new ExpiryDateTracker();
93+
initialData = new Xpire();
9494
}
9595

9696
return new ModelManager(initialData, userPrefs);
@@ -170,13 +170,13 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {
170170

171171
@Override
172172
public void start(Stage primaryStage) {
173-
logger.info("Starting ExpiryDateTracker " + MainApp.VERSION);
173+
logger.info("Starting Xpire " + MainApp.VERSION);
174174
ui.start(primaryStage);
175175
}
176176

177177
@Override
178178
public void stop() {
179-
logger.info("============================ [ Stopping ExpiryDateTracker ] =============================");
179+
logger.info("============================ [ Stopping Xpire ] =============================");
180180
try {
181181
storage.saveUserPrefs(model.getUserPrefs());
182182
} catch (IOException e) {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package seedu.address.commons.core;
1+
package io.xpire.commons.core;
22

33
import java.nio.file.Path;
44
import java.nio.file.Paths;
@@ -17,34 +17,32 @@ public class Config {
1717
private Path userPrefsFilePath = Paths.get("preferences.json");
1818

1919
public Level getLogLevel() {
20-
return logLevel;
20+
return this.logLevel;
2121
}
2222

2323
public void setLogLevel(Level logLevel) {
2424
this.logLevel = logLevel;
2525
}
2626

2727
public Path getUserPrefsFilePath() {
28-
return userPrefsFilePath;
28+
return this.userPrefsFilePath;
2929
}
3030

3131
public void setUserPrefsFilePath(Path userPrefsFilePath) {
3232
this.userPrefsFilePath = userPrefsFilePath;
3333
}
3434

3535
@Override
36-
public boolean equals(Object other) {
37-
if (other == this) {
36+
public boolean equals(Object obj) {
37+
if (obj == this) {
3838
return true;
39+
} else if (!(obj instanceof Config)) {
40+
return true;
41+
} else {
42+
Config other = (Config) obj;
43+
return Objects.equals(this.logLevel, other.logLevel)
44+
&& Objects.equals(this.userPrefsFilePath, other.userPrefsFilePath);
3945
}
40-
if (!(other instanceof Config)) { //this handles null as well.
41-
return false;
42-
}
43-
44-
Config o = (Config) other;
45-
46-
return Objects.equals(logLevel, o.logLevel)
47-
&& Objects.equals(userPrefsFilePath, o.userPrefsFilePath);
4846
}
4947

5048
@Override
@@ -55,9 +53,8 @@ public int hashCode() {
5553
@Override
5654
public String toString() {
5755
StringBuilder sb = new StringBuilder();
58-
sb.append("Current log level : " + logLevel);
59-
sb.append("\nPreference file Location : " + userPrefsFilePath);
56+
sb.append("Current log level : " + logLevel + "\n");
57+
sb.append("Preference file Location : " + userPrefsFilePath);
6058
return sb.toString();
6159
}
62-
6360
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package io.xpire.commons.core;
2+
3+
import java.awt.Point;
4+
import java.io.Serializable;
5+
import java.util.Objects;
6+
7+
/**
8+
* A Serializable class that contains the GUI settings.
9+
* Guarantees: immutable.
10+
*/
11+
public class GuiSettings implements Serializable {
12+
13+
private static final double DEFAULT_HEIGHT = 600;
14+
private static final double DEFAULT_WIDTH = 740;
15+
16+
private final double windowWidth;
17+
private final double windowHeight;
18+
private final Point windowCoordinates;
19+
20+
public GuiSettings() {
21+
this.windowWidth = DEFAULT_WIDTH;
22+
this.windowHeight = DEFAULT_HEIGHT;
23+
this.windowCoordinates = null; // null represent no coordinates
24+
}
25+
26+
public GuiSettings(double windowWidth, double windowHeight, int xPosition, int yPosition) {
27+
this.windowWidth = windowWidth;
28+
this.windowHeight = windowHeight;
29+
this.windowCoordinates = new Point(xPosition, yPosition);
30+
}
31+
32+
public double getWindowWidth() {
33+
return this.windowWidth;
34+
}
35+
36+
public double getWindowHeight() {
37+
return this.windowHeight;
38+
}
39+
40+
public Point getWindowCoordinates() {
41+
return this.windowCoordinates != null ? new Point(this.windowCoordinates) : null;
42+
}
43+
44+
@Override
45+
public boolean equals(Object obj) {
46+
if (obj == this) {
47+
return true;
48+
} else if (!(obj instanceof GuiSettings)) {
49+
return false;
50+
} else {
51+
GuiSettings other = (GuiSettings) obj;
52+
return this.windowWidth == other.windowWidth
53+
&& this.windowHeight == other.windowHeight
54+
&& Objects.equals(this.windowCoordinates, other.windowCoordinates);
55+
}
56+
}
57+
58+
@Override
59+
public int hashCode() {
60+
return Objects.hash(this.windowWidth, this.windowHeight, this.windowCoordinates);
61+
}
62+
63+
@Override
64+
public String toString() {
65+
StringBuilder sb = new StringBuilder();
66+
sb.append("Width : " + this.windowWidth + "\n");
67+
sb.append("Height : " + this.windowHeight + "\n");
68+
sb.append("Position : " + this.windowCoordinates);
69+
return sb.toString();
70+
}
71+
}

0 commit comments

Comments
 (0)