Skip to content

Commit

Permalink
Merge pull request #264 from AY2324S2-CS2103T-W12-3/160-improve-code-…
Browse files Browse the repository at this point in the history
…quality

Improve overall code quality
  • Loading branch information
bryanyee33 authored Apr 12, 2024
2 parents b4ddc7a + 8260eb4 commit 558851f
Show file tree
Hide file tree
Showing 30 changed files with 187 additions and 178 deletions.
14 changes: 9 additions & 5 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public class MainApp extends Application {

private static final Logger logger = LogsCenter.getLogger(MainApp.class);

private static final String ADDRESS_BOOK_LOAD_SUCCESSFUL =
"Data file loaded successfully.";
private static final String ADDRESS_BOOK_LOAD_UNSUCCESSFUL =
"WARNING!! Entering a command will override the old data file.";

private Ui ui;
private Storage storage;
private Model model;
Expand Down Expand Up @@ -148,18 +153,17 @@ private static UserPrefs initPrefs(UserPrefsStorage storage) {
/**
* Reads the filepath stored within a {@code Storage} object and returns a {@code ReadOnlyAddressBook}.
*
* @param storage the storage object.
* @return a read-only address book.
* @param storage The storage object.
* @return A read-only address book.
*/
private ReadOnlyAddressBook initAddressBook(Storage storage) {
ReadOnlyAddressBook initialAddressBook;
try {
initialAddressBook = storage.readInitialAddressBook();
initialWelcomeMessage = "Data file loaded successfully.";
initialWelcomeMessage = ADDRESS_BOOK_LOAD_SUCCESSFUL;
} catch (DataLoadingException e) {
initialAddressBook = new AddressBook();
initialWelcomeMessage = "WARNING!! Entering a command will override the old data file.\n"
+ e.getMessage();
initialWelcomeMessage = ADDRESS_BOOK_LOAD_UNSUCCESSFUL + "\n" + e.getMessage();
}
return initialAddressBook;
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/seedu/address/commons/core/GuiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public GuiSettings() {
/**
* Constructs a {@code GuiSettings} with the specified parameters.
*
* @param windowWidth the window's width.
* @param windowHeight the window's height.
* @param xPosition the window's x-coordinate on the screen.
* @param yPosition the window's y-coordinate on the screen.
* @param isMaximized whether the window is maximized.
* @param splitPaneDividerPosition the height of the TextArea resultDisplay.
* @param windowWidth The window's width.
* @param windowHeight The window's height.
* @param xPosition The window's x-coordinate on the screen.
* @param yPosition The window's y-coordinate on the screen.
* @param isMaximized Whether the window is maximized.
* @param splitPaneDividerPosition The height of the TextArea resultDisplay.
*/
public GuiSettings(double windowWidth, double windowHeight, int xPosition, int yPosition,
boolean isMaximized, double splitPaneDividerPosition) {
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/seedu/address/logic/CommandHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import seedu.address.commons.exceptions.CommandHistoryException;

//@@author aureliony
/**
* Represents an abstraction for a command history data structure.
*/
Expand All @@ -19,8 +20,8 @@ public class CommandHistory {
/**
* Get the previous command text.
*
* @return the previous command text.
* @throws CommandHistoryException if the message history is empty or the index is already at the start.
* @return The previous command text.
* @throws CommandHistoryException If the message history is empty or the index is already at the start.
*/
public String getPrevious() throws CommandHistoryException {
assert 0 <= index && index <= commandHistory.size();
Expand All @@ -40,8 +41,8 @@ public String getPrevious() throws CommandHistoryException {
/**
* Get the next command text.
*
* @return the next command text.
* @throws CommandHistoryException if the index is already at the end.
* @return The next command text.
* @throws CommandHistoryException If the index is already at the end.
*/
public String getNext() throws CommandHistoryException {
assert 0 <= index && index <= commandHistory.size();
Expand All @@ -62,7 +63,7 @@ public String getNext() throws CommandHistoryException {
/**
* Add a valid command text to the command history.
*
* @param commandText the command text string.
* @param commandText The command text string.
*/
public void add(String commandText) {
commandHistory.add(commandText);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface Logic {
/**
* Executes the command and returns the result.
* @param commandText The command as entered by the user.
* @return the result of the command execution.
* @return The result of the command execution.
* @throws CommandException If an error occurs during command execution.
* @throws ParseException If an error occurs during parsing.
*/
Expand All @@ -27,16 +27,16 @@ public interface Logic {
/**
* Gets the previous command's text.
*
* @return the previous command's text.
* @throws CommandHistoryException if the message history is empty or the index is already at the start.
* @return The previous command's text.
* @throws CommandHistoryException If the message history is empty or the index is already at the start.
*/
String getPreviousCommandText() throws CommandHistoryException;

/**
* Gets the next command's text.
*
* @return the next command's text.
* @throws CommandHistoryException if the index is already at the end.
* @return The next command's text.
* @throws CommandHistoryException If the index is already at the end.
*/
String getNextCommandText() throws CommandHistoryException;

Expand Down
19 changes: 6 additions & 13 deletions src/main/java/seedu/address/model/UserPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

import seedu.address.commons.core.GuiSettings;

//@@author
/**
* Represents User's preferences.
*/
public class UserPrefs implements ReadOnlyUserPrefs {

private GuiSettings guiSettings = new GuiSettings();
private Path addressBookFilePath = Paths.get("data" , "assetbook.json");
private Path assetBookFilePath = Paths.get("data" , "assetbook.json");

/**
* Creates a {@code UserPrefs} with default values.
Expand Down Expand Up @@ -48,12 +49,12 @@ public void setGuiSettings(GuiSettings guiSettings) {
}

public Path getAddressBookFilePath() {
return addressBookFilePath;
return assetBookFilePath;
}

public void setAddressBookFilePath(Path addressBookFilePath) {
requireNonNull(addressBookFilePath);
this.addressBookFilePath = addressBookFilePath;
this.assetBookFilePath = addressBookFilePath;
}

@Override
Expand All @@ -69,20 +70,12 @@ public boolean equals(Object other) {

UserPrefs otherUserPrefs = (UserPrefs) other;
return guiSettings.equals(otherUserPrefs.guiSettings)
&& addressBookFilePath.equals(otherUserPrefs.addressBookFilePath);
&& assetBookFilePath.equals(otherUserPrefs.assetBookFilePath);
}

@Override
public int hashCode() {
return Objects.hash(guiSettings, addressBookFilePath);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Gui Settings : " + guiSettings);
sb.append("\nLocal data file location : " + addressBookFilePath);
return sb.toString();
return Objects.hash(guiSettings, assetBookFilePath);
}

}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/asset/Asset.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static boolean isValid(String test) {
* Parses a {@code String} of format {@code NAME[#ID]} into a {@code Asset}.
* Leading and trailing whitespaces of each field will be trimmed.
*
* @throws IllegalArgumentException if the given {@code name} is invalid.
* @throws IllegalArgumentException If the given {@code name} is invalid.
*/
public static Asset of(String assetDescription) throws IllegalArgumentException {
requireNonNull(assetDescription);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public Person(Name name, Phone phone, Email email, Address address, Tags tags, A
this.assets = assets;
}

//@@author aureliony
@JsonCreator
private Person(@JsonProperty("name") String name, @JsonProperty("phone") String phone,
@JsonProperty("email") String email, @JsonProperty("address") String address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ public class PersonMatchesQueryPredicate implements Predicate<Person> {

/**
* Processes the query string and constructs the object.
* @param query the query string.
* @throws NullPointerException if the query string is null.
* @throws AssertionError if the query string is empty.
* @param query The query string.
* @throws NullPointerException If the query string is null.
* @throws AssertionError If the query string is empty.
*/
public PersonMatchesQueryPredicate(String query) {
requireNonNull(query);
assert !query.isEmpty();
this.query = processString(query);
}

/**
* Converts the input {@code str} to lowercase and removes all whitespaces.
*/
private static String processString(String str) {
return str.toLowerCase().replaceAll(STRIP_WHITESPACE_REGEX, EMPTY_STRING);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.List;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

Expand All @@ -24,9 +23,12 @@ public UniquePersonListDeserializer(Class<?> vc) {

@Override
public UniquePersonList deserialize(JsonParser parser,
DeserializationContext context) throws IOException, JsonProcessingException {
DeserializationContext context) throws IOException {
// read the JSON content and deserialize it
List<Person> persons = context.readValue(parser,
context.getTypeFactory().constructCollectionType(List.class, Person.class));

// initialize and update the UniquePersonList
UniquePersonList upl = new UniquePersonList();
upl.setPersons(persons);
return upl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static boolean isValid(String test) {
* Parses a {@code String address} into an {@code Address}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws IllegalArgumentException if the given {@code address} is invalid.
* @throws IllegalArgumentException If the given {@code address} is invalid.
*/
public static Address of(String address) throws IllegalArgumentException {
requireNonNull(address);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/person/fields/Assets.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public boolean contains(Asset asset) {

/**
* Changes name of an asset.
* @param target asset to be edited
* @param editedAsset new asset name
* @param target The asset to be edited.
* @param editedAsset The new asset name.
*/
public Assets edit(Asset target, Asset editedAsset) {
requireAllNonNull(target, editedAsset);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/fields/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static boolean isValid(String test) {
* Parses a {@code String email} into an {@code Email}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws IllegalArgumentException if the given {@code email} is invalid.
* @throws IllegalArgumentException If the given {@code email} is invalid.
*/
public static Email of(String email) throws IllegalArgumentException {
requireNonNull(email);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/fields/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static boolean isValid(String test) {
* Parses a {@code String name} into a {@code Name}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws IllegalArgumentException if the given {@code name} is invalid.
* @throws IllegalArgumentException If the given {@code name} is invalid.
*/
public static Name of(String name) throws IllegalArgumentException {
requireNonNull(name);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/model/person/fields/Tags.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import seedu.address.model.tag.Tag;

//@@author aureliony
/**
* Represents an abstraction for a list of tags.
*/
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/ui/CommandBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private void handleKeyPressed(KeyEvent event) {
}

if (commandText != null) {
// update the command box and relocate the caret appropriately
commandTextField.setText(commandText);
commandTextField.positionCaret(commandTextField.getLength());
logger.info("commandTextField set to \"" + commandText + "\"");
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/ui/CommandExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ public interface CommandExecutor {
/**
* Gets the previous command's text.
*
* @return the previous command's text.
* @throws CommandHistoryException if the message history is empty or the index is already at the start.
* @return The previous command's text.
* @throws CommandHistoryException If the message history is empty or the index is already at the start.
*/
String getPreviousCommandText() throws CommandHistoryException;

/**
* Gets the next command's text.
*
* @return the next command's text.
* @throws CommandHistoryException if the index is already at the end.
* @return The next command's text.
* @throws CommandHistoryException If the index is already at the end.
*/
String getNextCommandText() throws CommandHistoryException;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void setAccelerators() {

/**
* Sets the accelerator of a MenuItem.
* @param keyCombination the KeyCombination value of the accelerator
* @param keyCombination The KeyCombination value of the accelerator.
*/
private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) {
menuItem.setAccelerator(keyCombination);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"isMaximized" : false,
"splitPaneDividerPosition" : 0.75
},
"addressBookFilePath" : "data\\assetbook.json"
"assetBookFilePath" : "data\\assetbook.json"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"isMaximized" : false,
"splitPaneDividerPosition" : 0.75
},
"addressBookFilePath" : "data\\assetbook.json"
"assetBookFilePath" : "data\\assetbook.json"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class GuiSettingsTest {

@Test
void testEquals() {
void equals() {
GuiSettings guiSettings = new GuiSettings();

assertFalse(guiSettings.equals(null));
Expand Down
Loading

0 comments on commit 558851f

Please sign in to comment.