From 45d520b13c7e00ee0c07eab37e0c5d4c20cb7b53 Mon Sep 17 00:00:00 2001 From: Deculsion Date: Thu, 10 Oct 2019 10:39:16 +0800 Subject: [PATCH 01/16] Added skeleton classes for Parse --- src/main/java/eggventory/Eggventory.java | 1 + src/main/java/eggventory/parsers/ParseAdd.java | 7 +++++++ src/main/java/eggventory/parsers/ParseDelete.java | 7 +++++++ src/main/java/eggventory/parsers/ParseEdit.java | 7 +++++++ src/main/java/eggventory/{ => parsers}/Parser.java | 2 +- 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/main/java/eggventory/parsers/ParseAdd.java create mode 100644 src/main/java/eggventory/parsers/ParseDelete.java create mode 100644 src/main/java/eggventory/parsers/ParseEdit.java rename src/main/java/eggventory/{ => parsers}/Parser.java (99%) diff --git a/src/main/java/eggventory/Eggventory.java b/src/main/java/eggventory/Eggventory.java index 4c5957cb6f..97431ff3c9 100644 --- a/src/main/java/eggventory/Eggventory.java +++ b/src/main/java/eggventory/Eggventory.java @@ -2,6 +2,7 @@ import eggventory.commands.Command; import eggventory.enums.CommandType; +import eggventory.parsers.Parser; /** * Eggventory is a task list that supports 3 types of classes - Todos, deadlines and events. diff --git a/src/main/java/eggventory/parsers/ParseAdd.java b/src/main/java/eggventory/parsers/ParseAdd.java new file mode 100644 index 0000000000..60488204b6 --- /dev/null +++ b/src/main/java/eggventory/parsers/ParseAdd.java @@ -0,0 +1,7 @@ +package eggventory.parsers; + +public class ParseAdd { + public ParseAdd(String input) { + + } +} diff --git a/src/main/java/eggventory/parsers/ParseDelete.java b/src/main/java/eggventory/parsers/ParseDelete.java new file mode 100644 index 0000000000..54315c1a74 --- /dev/null +++ b/src/main/java/eggventory/parsers/ParseDelete.java @@ -0,0 +1,7 @@ +package eggventory.parsers; + +public class ParseDelete { + public ParseDelete(String input) { + + } +} diff --git a/src/main/java/eggventory/parsers/ParseEdit.java b/src/main/java/eggventory/parsers/ParseEdit.java new file mode 100644 index 0000000000..6d6d341e4a --- /dev/null +++ b/src/main/java/eggventory/parsers/ParseEdit.java @@ -0,0 +1,7 @@ +package eggventory.parsers; + +public class ParseEdit { + public ParseEdit(String input) { + + } +} diff --git a/src/main/java/eggventory/Parser.java b/src/main/java/eggventory/parsers/Parser.java similarity index 99% rename from src/main/java/eggventory/Parser.java rename to src/main/java/eggventory/parsers/Parser.java index 76c67fef77..604fc45491 100644 --- a/src/main/java/eggventory/Parser.java +++ b/src/main/java/eggventory/parsers/Parser.java @@ -1,4 +1,4 @@ -package eggventory; +package eggventory.parsers; import eggventory.commands.Command; import eggventory.commands.AddCommand; From 8d3cda2e74011aa8ad3a252299cd3dae2ba459e8 Mon Sep 17 00:00:00 2001 From: Deculsion Date: Mon, 14 Oct 2019 16:07:45 +0800 Subject: [PATCH 02/16] Added toString() and modified some javadocs for it. --- src/main/java/eggventory/StockList.java | 15 +++++++++++++++ src/main/java/eggventory/items/Stock.java | 2 +- src/main/java/eggventory/items/StockType.java | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/eggventory/StockList.java b/src/main/java/eggventory/StockList.java index 3d83d762e5..253dd1c552 100644 --- a/src/main/java/eggventory/StockList.java +++ b/src/main/java/eggventory/StockList.java @@ -60,6 +60,21 @@ public void deleteStock(String stockCode) { } } + /** + * Prints every stock within stocklist. Should only be called by Ui. + * @return The string of the stocklist. + */ + public String toString() { + String ret = ""; + ret += "CURRENT INVENTORY\n"; + for (int i = 0; i < quantity; i++) { + ret += "------------------------\n"; + ret += stockList.get(i).toString() + "\n"; + } + + return ret; + } + /** * Saves the list into a String. * @return The String that will be directly saved into file. diff --git a/src/main/java/eggventory/items/Stock.java b/src/main/java/eggventory/items/Stock.java index bdd9a02d67..a952fca353 100644 --- a/src/main/java/eggventory/items/Stock.java +++ b/src/main/java/eggventory/items/Stock.java @@ -154,7 +154,7 @@ public int numAvailable() { } /** - * Formats all stock details appropriately for Ui output. + * Formats all stock details appropriately for Ui output. Should only be called by Ui and StockType. * @return the stock details string. */ @Override diff --git a/src/main/java/eggventory/items/StockType.java b/src/main/java/eggventory/items/StockType.java index 88fe69863d..fa494f47e2 100644 --- a/src/main/java/eggventory/items/StockType.java +++ b/src/main/java/eggventory/items/StockType.java @@ -88,6 +88,23 @@ public void deleteStock(String stockCode) { this.quantity--; } + /** + * A string of all the stock objects within this stocktype. Should only be called by Ui and StockList. + * @return A string list of all the stock objects and their details. + */ + public String toString() { + String ret = ""; + int i = 1; + + for (Stock stock : stocks) { + ret += String.format("%d. ", i++) + stock.toString() + "\n"; + } + + return ret; + + } + + /** * Creates a String of all Stock objects under this StockType. * @return The String of all Stock objects. From 7f81e83f9f1d32ede3d966554e25120463726763 Mon Sep 17 00:00:00 2001 From: Dana Poon Date: Thu, 31 Oct 2019 16:26:05 +0800 Subject: [PATCH 03/16] docs/User Guide.md created from https://stackedit.io/ --- docs/User Guide.md | 415 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 415 insertions(+) create mode 100644 docs/User Guide.md diff --git a/docs/User Guide.md b/docs/User Guide.md new file mode 100644 index 0000000000..56092b5acd --- /dev/null +++ b/docs/User Guide.md @@ -0,0 +1,415 @@ +--- +extensions: + preset: gfm + +--- + +

Eggventory User Guide

+

By: Team F09-03
+Dated: 24 October 2019

+

Table of contents

+

1. Introduction

+

2. Quick Start

+

3. Features and Command Usage

+
3.1 Viewing help
+
3.2 Working with Stock Types
+
3.3 Working with Stocks
+
3.4 Managing your list of People
+
3.5 Managing your list of Loans
+
3.6 Loaning using Templates (coming in v1.4)
+
3.7 Marking Stock as Lost
+
3.8 Searching the Inventory
+
3.9 Using Undo and Redo Commands
+
3.10 Setting autosave options
+
3.1 Exiting the program: bye
+

4. FAQ

+

5. Command Summary

+

6. Glossary

+

1. Introduction

+

Eggventory is an inventory management system targeted towards engineering laboratory inventories. It is designed to make tracking of stock and inventory fast and painless. There are visual elements for all functionalities which makes learning the system easy, but there are also command-line equivalents that allow advanced users to do everything in one or two short commands.

+

2. Quick start

+
    +
  1. +

    Download and install Java 11 on your machine.

    +
  2. +
  3. +

    Download the latest eggventory.jar the github repository.

    +
  4. +
  5. +

    Copy the file to the folder you want to use as the home folder for your inventory management system.

    +
  6. +
  7. +

    Double-click the file to start the app. The GUI should appear in a few seconds.

    +
  8. +
+

+
    +
  1. +

    Type the command in the command box and press Enter to execute it

    +

    E.g. typing help and pressing Enter will open the help window.

    +
  2. +
  3. +

    Some example commands you can try:

    +
  4. +
+
    +
  • +

    add stocktype Resistors : Creates a category of stock named “Resistors”

    +
  • +
  • +

    add stock R500 200 500-ohm resistor -st Resistors: Creates a new stock item with 200 500-ohm resistors and a stock code of “R500”, under the “Resistors” Stock Type.

    +
  • +
  • +

    edit stock R500 quantity -50 : Reduce the stock count of item R500 (500-ohm resistor) by 50.

    +
  • +
  • +

    add stock C1k 75 1000pF Capacitors : Creates a new stock item with 75 1000pF Capacitors and stock code “C1k”. The stock type will be defaulted to “Uncategorised”.

    +
  • +
  • +

    list stocktype Resistors : Displays all stock that is categorised as Resistors.

    +
  • +
  • +

    exit : exits the app

    +
  • +
+
    +
  1. +

    Refer to Section 3 for a more detailed list of commands you can use.

    +
  2. +
+

3. Features and command usage

+

The following section describes the command line interface commands that Eggventory recognises. Each command you input has to follow a specific format of words and parameters.

+

Command Format

+
    +
  • +

    Text in are mandatory parameter to be supplied by the user. E.g. add stocktype , is a parameter which is the name of the stocktype the user wishes to add.

    +
  • +
  • +

    Parameters in {Braces} can be repeated multiple times in the same command, separated by a comma (,). E.g. loan add <Matric. No> { } , more pairs can be added after the first pair as such: loan add A0191234A R500 20, R250 10, R100 5

    +
  • +
  • +

    [coming in v2.0] Some commands have optional parameters available. Optional parameters are added to the end of the corresponding command, after all mandatory parameters. E.g. add stock R500 50 “500-ohm Resistors” -st Resistors , will create a new stock, and placed under the “Resistors” Stock Type with the “-st” tag.

    +
  • +
+

+

3.1 Viewing help: help

+

General help: Displays a basic list of commands and their input formats.

+

Format: help

+

Specific help: Displays a more detailed list of commands of that type, with information about each input required.

+

Format: help <command>

+

eg. help edit

+
+

3.2 Working with Stock Types

+

Stock Types are the main categories of the inventory, and each Stock Type stores multiple Stocks. For example, your inventory may have Stock Types such as Resistors, Tools or Wires. You are required to add your Stock Types to the inventory before Stocks can be added. By default, Eggventory comes with an Uncategorised Stock Type, where Stocks not assigned to a specified Stock Type are added.

+

Note: Stock Type names are not allowed to have spaces in them.

+

3.2.1 Adding new Stock Types: add stocktype

+

This adds a new category of stock to the inventory.

+

Format: add stocktype

+

eg. add stocktype Resistor

+

3.2.2 Deleting Stock Types: delete stocktype

+

This removes a stocktype from the inventory, and all stock under it.

+

Format: delete stocktype

+

3.2.3 Editing Stock Types: edit stocktype

+

This changes the name of the selected stock type.

+

Format: edit stocktype

+

3.2.4 Listing Stock Types: list stocktype

+

This lists out all Stock Types that are present in the inventory.

+

Format: list stocktype

+
+

3.3 Working with Stocks

+

Stocks are the main types of items that Eggventory helps you to manage. Every Stock belongs to a Stock Type. For example, you may have the Stocks “500 ohm resistor” and “1k ohm resistor” in the Resistor Stock Type.

+

Stocks may be Collective or Unique. Collective stocks consist of items that are not tracked individually. They generally are stocks that do not have each have their own serial number, and are considered interchangeable. Unique stocks are items that are often expensive or limited in quantity. Such stocks usually are each assigned a serial number, and are loaned out and tracked by this number. Stocks are set as Collective by default.

+

Stocks have the following properties:

+ + + + + + + + + + + + + + + + + + + + + + +
PropertyDescription
StockTypeThe category the stock belongs to. The StockType should have previously been added to the inventory system before being referenced.
Stock Codeunique string of numbers and letters, used to identify the stock.
QuantityDescriptionThe common name of the item.

Note: Stock codes are not allowed to have spaces in them, and no two stocks can share the same stock code.

+

3.3.1 Adding new Stocks: add stock

+

This adds a new stock to the inventory.

+

Format: add stock <StockType> <Stock Code> <Quantity> <Description>

+

eg. add stock Resistor R500 1000 500ohm resistor

+

[coming in v2.0]
+In addition to the required parameters, stocks can also be added with the following optional parameters:

+ + + + + + + + + + + + + + + + + + +
FormatPurpose
-mq <Min. Qty>Sets the minimum quantity of stock that should be maintained in the inventory
-uSets the stock to contain items that are unique

Format: add stock <StockType> <Stock Code> <Quantity> <Description> {<optional parameter>}

+

eg. add stock Resistor R500 1000 500ohm resistor -mq 100

+

3.3.2 Deleting Stocks: delete stock

+

This removes a stock from the inventory, including any references to loaned out stock.

+

Format: delete stock

+

3.3.3 Editing Stock: edit stock

+

This directly modifies the value of a property of a stock. You may modify as many properties as you wish in one command.

+

Keywords to modify each property:

+
    +
  • +

    stockcode

    +
  • +
  • +

    description

    +
  • +
  • +

    stocktype

    +
  • +
  • +

    quantity

    +
  • +
  • +

    minquantity

    +
  • +
+

Format: edit stock <Stock Code> {<Property> <New Value>}

+

eg. edit stock R500 quantity 1000 description stockcode Res500

+

3.3.4 Listing Stock: list stock

+

This lists out all Stocks that are present in the inventory.

+

Format: list stock

+

3.3.5 Listing Stock of a particular StockType: list <StockType>

+

This lists out all Stock under a particular Stock Type

+

Format: list <Stock Type>

+

eg. list Resistor

+
+

3.4 Managing your list of People

+

People have to be added to the system before they can take loans from the inventory. Each person is identified by their matric number, as the inventory primarily loans out stock to students.

+

3.4.1 Adding a Person: add person

+

This adds a new person to keep track that will loan stock.

+

Format: add person <Matric No.> <Name>

+

eg. add person A0123456
+Note: By nature, the matric number of each Person should be unique, meaning no two individuals are allowed to share the same matric number.

+

[coming in v2.0]
+Optional Parameters:

+ + + + + + + + + + + + + + + + + + +
FormatPurpose
-n < Name >Sets the name of the person being added
-c < Course >Sets the course of the person being added

Format: add person <Matric. No> {<flag> <optional parameter>}

+

eg. add person A0187654 -n Raghav -c CEG

+

3.4.2 Deleting a Person:delete person

+

This removes a person from being tracked. All outstanding loans are automatically returned.

+

Format: delete person <Matric. No>

+

eg. delete person A0123456

+

3.4.3 Editing a Person’s details: edit person

+

This directly modifies the value of a property of a person. You may modify as many properties as you wish in one command.

+

Properties:

+
    +
  • matric
  • +
  • name
  • +
+

Format: edit person <Matric No.> {<Property> <New Value>}

+

eg. edit person A0123456 name Alex

+

3.4.4 Listing all People: list person

+

This lists all the people in the system, along with any information recorded about them.

+

Format: list person

+
+

3.5 Managing your list of Loans

+

3.5.1 Adding a Loan: loan add

+

This adds a new Loan made by a Person. is possible to add multiple stocks at once.

+

Format: loan add <Matric No.> {<Stock Code> <Quantity>}

+

eg. loan add A0123456 R500 1000 X123 80

+

3.5.2 Returning specific Loans: loan return

+

This marks specific Loans of a Person as returned.

+

Format: loan return <Matric No.> {<Stock Code> <Quantity>}

+

3.5.3 Returning all Loans: loan returnall

+

This marks all Loans of a Person as returned.

+

Format: `loan returnall <Matric No

+

3.5.4 Listing all Persons and their Loans: list loan

+

This lists out all loans currently recorded, listed by the Person who made the loan.

+

Format: list loan

+
+

3.6 Loaning using Templates [coming in v1.4]

+

To speed up the loaning process, Eggventory allows you to create loan templates. Templates allow you to define a set of stocks in advance, and repeatedly loan out the same combination of stocks to different People.

+

3.6.1 Adding loan templates: add template

+

This creates a template that can be substituted for { } in loan commands.

+

Format:add template “<Template Name>” {<Stock Code> <Quantity>}

+

e.g. add template CG1112_Alex R500 5 A123 1

+

3.6.2 Deleting a Template: delete template

+

This deletes a saved loan template.

+

Format: delete template <Template Name>

+

eg. delete template CG1112_Alex

+

3.6.3 Making a Loan from a template: loan add

+

This adds a Loan to a Person from a Template.

+

Format: loan add <Matric. No> <Template Name>

+

eg. loan add A0187654 CG1112_Alex

+

Note: Additional Loans can still be added on to the same Person afterwards using the loan add command.
+3.6.4 Listing Loan Templates: `list template

+

This lists out all the templates created in the system.

+

Format: list template

+
+

3.7 Marking Stock as lost

+

[coming in v2.0]
+Marks a certain quantity of a stock as lost. Differs from deleting stock in the fact that the quantity of stock will still be saved in the inventory (eg. for administrative purposes). Lost stock will not be included in tallies of available stock.

+

3.7.1 Marking Stock as lost: lost

+

Format:lost <Stock Code> <Quantity>

+

eg. lost R500 10

+

3.7.2 Marking Loaned Stock as lost: [coming in v2.0]

+

This directly marks a quantity of a Person’s Loan as lost. The items are removed from the Loan list and counted as lost within the main inventory.

+

Format: [coming in v2.0]

+

3.8 Searching the inventory

+

It is possible to search the inventory for a Stock or StockType with the find command. It will display all Stocks or StockType that partially or fully matches the input query.

+

3.8.1 Finding a Stock: find stock

+

This finds all stocks that match the query.

+

Format: find stock <Query>

+

3.8.2 Finding a StockType: find stocktype

+

This finds all StockTypes that matches the query.

+

Format: find stocktype <Query>

+
+

3.9 Using Undo and Redo commands: [coming in v2.0]

+

3.9.1 Undoing a command: `undo

+

If you accidentally entered a command by accident, the effects of any command can be reversed with the undo command.

+

Format: undo

+

3.9.2 Reversing an undo command: redo

+

Undoing a command can be reversed using the redo command.

+

Format: redo

+
+

3.10 Setting autosave options: [coming in v2.0]

+

Eggventory automatically saves the current inventory to the disk every time data is added, removed, or edited. You can disable this feature with this command. Eggventory will then save only when the program exits.

+

Format: autosave on OR autosave off

+
+

3.11 Exiting the program: bye

+

Format: bye

+

4. FAQ

+

5. Command Summary

+ + + + + + + + + + + + + + + + + + +
Add CommandsDescription
Add Stockadd stock <Stock Type> <Stock Code> <Quantity> <Description>
Add Stock Type`
    +
  • +
+

add stocktype Add Template|

+
    +
  • +

    add template { }`

    +
  • +
  • +

    add person

    +
  • +

    List

    +
  • +
  • +

    list stock

    +
  • +
  • +

    list stocktypes

    +
  • +
  • +

    list stocktype

    +
  • +
  • +

    list loan

    +
  • +
  • +

    list template

    +
  • +
  • +

    list lost

    +
  • +
  • +

    Find

    +
  • +
  • +

    find stock

    +
  • +
  • +

    find stocktype

    +
  • +
  • +

    Loan

    +
  • +
  • +

    loan add

OR

+

loan add

    +
  • loan returned

OR

+

loan returned

    +
  • +

    Lost

    +
  • +
  • +

    lost

    +
  • +
  • +

    Undo

    +
  • +
  • +

    undo

    +
  • +
  • +

    Redo

    +
  • +
  • +

    redo

    +
  • +
  • +

    Exit

    +
  • +
  • +

    bye

    +
  • +
+

6. Glossary

+

Matric No.: Matriculation number of student to be added

+

Stock: A physical asset to be tracked by Eggventory

+

Stock Code: A unique string of characters to identify a stock

+

Stock Type: A category of stock

+ From dd6c48debe375b0d8efce1582eed6ef209d62930 Mon Sep 17 00:00:00 2001 From: Dana Poon Date: Thu, 31 Oct 2019 16:27:39 +0800 Subject: [PATCH 04/16] Add UG markdown --- docs/User Guide.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docs/User Guide.md b/docs/User Guide.md index 56092b5acd..5b55a475a0 100644 --- a/docs/User Guide.md +++ b/docs/User Guide.md @@ -1,9 +1,3 @@ ---- -extensions: - preset: gfm - ---- -

Eggventory User Guide

By: Team F09-03
Dated: 24 October 2019

From e620f8a06a813bd730ae03e4379dc3571b6d58a7 Mon Sep 17 00:00:00 2001 From: Deculsion Date: Fri, 1 Nov 2019 14:59:09 +0800 Subject: [PATCH 05/16] LoanList is now more OOP and optimised. --- src/main/java/eggventory/model/LoanList.java | 108 +++++++++---------- 1 file changed, 51 insertions(+), 57 deletions(-) diff --git a/src/main/java/eggventory/model/LoanList.java b/src/main/java/eggventory/model/LoanList.java index aa027fd12b..2768600d36 100644 --- a/src/main/java/eggventory/model/LoanList.java +++ b/src/main/java/eggventory/model/LoanList.java @@ -16,8 +16,9 @@ * Loans can be printed as a complete list of all loans, or only by the Person or Stock involved. */ public final class LoanList { - private static ArrayList loanPairs = new ArrayList(); - private static HashMap loanList = new HashMap(); + + private static ArrayList loansList = new ArrayList(); + private static HashMap stockLoaned = new HashMap(); /** * Overloaded version of addLoan which does not require Date parameters. @@ -27,11 +28,10 @@ public final class LoanList { * @param quantity the quantity loaned out. */ public static void addLoan(String stockCode, String matricNo, int quantity) { - //Add one set of information to the table, and one to the list. - LoanPair loanPair = new LoanPair(stockCode, matricNo); - loanPairs.add(loanPair); Loan loan = new Loan(stockCode, matricNo, quantity); - loanList.put(loanPair,loan); + + loansList.add(loan); + updateStockLoaned(stockCode, quantity); } /** @@ -45,10 +45,10 @@ public static void addLoan(String stockCode, String matricNo, int quantity) { public static void addLoan(String stockCode, String matricNo, int quantity, Calendar loanDate, Calendar returnDate) { //Add one set of information to the table, and one to the list. - LoanPair loanPair = new LoanPair(stockCode, matricNo); - loanPairs.add(loanPair); Loan loan = new Loan(stockCode, matricNo, quantity, loanDate, returnDate); - loanList.put(loanPair,loan); + + loansList.add(loan); + updateStockLoaned(stockCode, quantity); } /** @@ -57,27 +57,14 @@ public static void addLoan(String stockCode, String matricNo, int quantity, * @param matricNo the matric number of the Person. */ public static boolean deleteLoan(String stockCode, String matricNo) { - //Construct the pair. - LoanPair queryPair = new LoanPair(stockCode, matricNo); - - boolean removeSuccess = false; - - //Check if the pair matches any in our list. - //If so, use the pair from the list to remove. - for (LoanPair loanPair : loanPairs) { - if (loanPair.equals(queryPair)) { - removeSuccess = true; - queryPair = loanPair; //Reassign the instance. - break; - } - } + Loan loan = findLoan(stockCode, matricNo); - if (removeSuccess) { - loanList.remove(queryPair); - loanPairs.remove(queryPair); - } + if (loan == null) return false; + + updateStockLoaned(stockCode, loan.getQuantity() * -1); + loansList.remove(loan); - return removeSuccess; + return true; } /** @@ -90,52 +77,59 @@ public static boolean deleteLoan(String stockCode, String matricNo) { * @return the quantity. */ public static int getLoanQuantity(String stockCode, String matricNo) { - //Construct the pair. - LoanPair queryPair = new LoanPair(stockCode, matricNo); - - //Check if the pair matches any in our list. - //If so, use the one from the list to access the quantity. - for (LoanPair loanPair : loanPairs) { - if (loanPair.equals(queryPair)) { - return loanList.get(loanPair).getQuantity(); + Loan loan = findLoan(stockCode, matricNo); + if (loan == null) return -1; + return loan.getQuantity(); + } + + public static int getStockLoanedQuantity(String stockCode) { + return stockLoaned.get(stockCode); + } + + private static Loan findLoan(String stockCode, String matricNo) { + for (Loan loan : loansList) { + if (loan.getStockCode().equals(stockCode) && loan.getMatricNo().equals(matricNo)) { + return loan; } } - return -1; + return null; } - //TODO: Add getters for the loan and return dates also. + private static void updateStockLoaned(String stockCode, int quantity) { + if (stockLoaned.containsKey(stockCode)) { + quantity += stockLoaned.get(stockCode); + } + stockLoaned.put(stockCode, quantity); + } - /** - * Returns a list of all the Loans of a single Person. - * @param matricNo the matric number of the person, used to uniquely identify them. - * @return the list of all Loans involving that Person. - */ private static ArrayList getPersonLoans(String matricNo) { - ArrayList queriedList = new ArrayList(); - - for (LoanPair pair : loanPairs) { - if (pair.getMatricNo().equals(matricNo)) { - queriedList.add(loanList.get(pair)); //Adds that Loan item, retrieved using the pair as key. + ArrayList loans = new ArrayList(); + for (Loan loan : loansList) { + if (loan.getMatricNo().equals(matricNo)) { + loans.add(loan); } } - return queriedList; + + return loans; } + //TODO: Add getters for the loan and return dates also. /** * Means of obtaining all the Loans of a single type of Stock. * @param stockCode the unique identifier of the Stock. * @return the list of Loans involving that Stock. */ private static ArrayList getStockLoans(String stockCode) { - ArrayList queriedList = new ArrayList(); - - for (LoanPair pair : loanPairs) { - if (pair.getStockCode().equals(stockCode)) { - queriedList.add(loanList.get(pair)); //Adds that Loan item, retrieved using the pair as key. + ArrayList loans = new ArrayList(); + for (Loan loan : loansList) { + if (loan.getStockCode().equals(stockCode)) { + loans.add(loan); } } - return queriedList; + + return loans; + } /** @@ -145,8 +139,8 @@ private static ArrayList getStockLoans(String stockCode) { public static String printLoans() { String output = "Here are all the Loans: \n"; - for (LoanPair loanPair : loanPairs) { - output += loanList.get(loanPair).toString() + "\n"; + for (Loan loan : loansList) { + output += loan.toString() + "\n"; } return output; From 3fd25c7248dcff449f6a3b95f04622927c1f4869 Mon Sep 17 00:00:00 2001 From: Deculsion Date: Fri, 1 Nov 2019 15:09:21 +0800 Subject: [PATCH 06/16] Check whether sufficient stock before adding. --- .../logic/commands/add/AddLoanCommand.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java b/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java index 3cfd20c1f8..cb6302a21b 100644 --- a/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java +++ b/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java @@ -28,6 +28,14 @@ public AddLoanCommand(CommandType type, String stockCode, String matricNo, int q this.quantity = quantity; } + private boolean sufficientStock() { + if (quantity - LoanList.getStockLoanedQuantity(stockCode) < 0) { + return false; + } + + return true; + } + /** * Method to execute the AddLoanCommand. * @param list the stockList. @@ -36,11 +44,18 @@ public AddLoanCommand(CommandType type, String stockCode, String matricNo, int q * @return the print string for assertion in testing. */ public String execute(StockList list, Ui ui, Storage storage) { - LoanList.addLoan(stockCode, matricNo, quantity); - String output = (String.format("Nice, I have added this loan for you: \n" - + "Stock: %s | Person: %s | Quantity: %d", stockCode, matricNo, quantity)); + String output = ""; + if (sufficientStock()) { + LoanList.addLoan(stockCode, matricNo, quantity); + output = (String.format("Nice, I have added this loan for you: \n" + + "Stock: %s | Person: %s | Quantity: %d", stockCode, matricNo, quantity)); + + ui.print(output); + } + else { + output = ("OOPS there is insufficient stock to loan out!"); + } - ui.print(output); return output; } } From d87a24546a0961c37a20ebdb209a5f9b610008cc Mon Sep 17 00:00:00 2001 From: Deculsion Date: Fri, 1 Nov 2019 15:11:38 +0800 Subject: [PATCH 07/16] Checkstyle --- .../eggventory/logic/commands/add/AddLoanCommand.java | 3 +-- src/main/java/eggventory/model/LoanList.java | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java b/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java index cb6302a21b..b601be1f37 100644 --- a/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java +++ b/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java @@ -51,8 +51,7 @@ public String execute(StockList list, Ui ui, Storage storage) { + "Stock: %s | Person: %s | Quantity: %d", stockCode, matricNo, quantity)); ui.print(output); - } - else { + } else { output = ("OOPS there is insufficient stock to loan out!"); } diff --git a/src/main/java/eggventory/model/LoanList.java b/src/main/java/eggventory/model/LoanList.java index 2768600d36..eb97b25527 100644 --- a/src/main/java/eggventory/model/LoanList.java +++ b/src/main/java/eggventory/model/LoanList.java @@ -59,7 +59,9 @@ public static void addLoan(String stockCode, String matricNo, int quantity, public static boolean deleteLoan(String stockCode, String matricNo) { Loan loan = findLoan(stockCode, matricNo); - if (loan == null) return false; + if (loan == null) { + return false; + } updateStockLoaned(stockCode, loan.getQuantity() * -1); loansList.remove(loan); @@ -78,7 +80,9 @@ public static boolean deleteLoan(String stockCode, String matricNo) { */ public static int getLoanQuantity(String stockCode, String matricNo) { Loan loan = findLoan(stockCode, matricNo); - if (loan == null) return -1; + if (loan == null) { + return -1; + } return loan.getQuantity(); } From 770feb7f18229d73db20ac030d75c12c3fa4feff Mon Sep 17 00:00:00 2001 From: Deculsion Date: Fri, 1 Nov 2019 15:30:42 +0800 Subject: [PATCH 08/16] Implement backend to list all of one person's loan --- src/main/java/eggventory/model/LoanList.java | 17 +++++++++++++++++ src/main/java/eggventory/model/loans/Loan.java | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/main/java/eggventory/model/LoanList.java b/src/main/java/eggventory/model/LoanList.java index eb97b25527..3f906c6e90 100644 --- a/src/main/java/eggventory/model/LoanList.java +++ b/src/main/java/eggventory/model/LoanList.java @@ -2,6 +2,7 @@ import eggventory.model.loans.Loan; import eggventory.model.loans.LoanPair; +import eggventory.ui.TableStruct; import java.util.ArrayList; import java.util.Calendar; @@ -182,6 +183,22 @@ public static String printStockLoans(String stockCode) { return output; } + public static TableStruct getPersonLoansStruct(String matricNo) { + TableStruct dataTable = new TableStruct("Loans of " + matricNo); + dataTable.setTableColumns("Stock Code", "Quantity Loaned"); + + ArrayList loans = getPersonLoans(matricNo); + ArrayList> dataList = new ArrayList<>(); + + for (Loan loan : loans) { + dataList.add(loan.getStockDataAsArray()); + } + + dataTable.setTableData(dataList); + + return dataTable; + } + //@@author } diff --git a/src/main/java/eggventory/model/loans/Loan.java b/src/main/java/eggventory/model/loans/Loan.java index 6ae1883d16..66cdb74189 100644 --- a/src/main/java/eggventory/model/loans/Loan.java +++ b/src/main/java/eggventory/model/loans/Loan.java @@ -1,5 +1,6 @@ package eggventory.model.loans; +import java.util.ArrayList; import java.util.Calendar; //@@author cyanoei @@ -84,6 +85,15 @@ public String toString() { return getMatricNo() + " loaned " + getQuantity() + " of " + getStockCode() + "."; } + public ArrayList getStockDataAsArray() { + ArrayList data = new ArrayList<>(); + + data.add(stockCode); + data.add(String.valueOf(quantity)); + + return data; + } + //@@author From 7c5c6e30c94875247450a0da78c6742afcb3331b Mon Sep 17 00:00:00 2001 From: Deculsion Date: Fri, 1 Nov 2019 16:00:26 +0800 Subject: [PATCH 09/16] Add logic and parser for list specific person loans --- .../logic/commands/CommandDictionary.java | 1 + .../commands/list/ListPersonLoansCommand.java | 38 +++++++++++++++++++ .../eggventory/logic/parsers/ParseList.java | 11 ++++-- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 src/main/java/eggventory/logic/commands/list/ListPersonLoansCommand.java diff --git a/src/main/java/eggventory/logic/commands/CommandDictionary.java b/src/main/java/eggventory/logic/commands/CommandDictionary.java index 6bd3ebab3c..0d33982a53 100644 --- a/src/main/java/eggventory/logic/commands/CommandDictionary.java +++ b/src/main/java/eggventory/logic/commands/CommandDictionary.java @@ -39,6 +39,7 @@ public CommandDictionary() { commandDict.add(new Pair<>("list template", null)); commandDict.add(new Pair<>("list lost", null)); commandDict.add(new Pair<>("list person", null)); + commandDict.add(new Pair<>("list person", "")); // Find Commands commandDict.add(new Pair<>("find stock", "")); diff --git a/src/main/java/eggventory/logic/commands/list/ListPersonLoansCommand.java b/src/main/java/eggventory/logic/commands/list/ListPersonLoansCommand.java new file mode 100644 index 0000000000..a0f648d312 --- /dev/null +++ b/src/main/java/eggventory/logic/commands/list/ListPersonLoansCommand.java @@ -0,0 +1,38 @@ +package eggventory.logic.commands.list; + +import eggventory.commons.enums.CommandType; +import eggventory.commons.exceptions.BadInputException; +import eggventory.logic.commands.Command; +import eggventory.model.LoanList; +import eggventory.model.PersonList; +import eggventory.model.StockList; +import eggventory.storage.Storage; +import eggventory.ui.Ui; + +//@@author Deculsion +public class ListPersonLoansCommand extends Command{ + String matricNo; + + public ListPersonLoansCommand(CommandType type, String matricNo) { + super(type); + this.matricNo = matricNo; + } + + /** + * Executes the command. + * @param list The stock list. + * @param ui The ui. + * @param storage The Storage. + */ + @Override + public String execute(StockList list, Ui ui, Storage storage) throws BadInputException { + String output = ""; + + output += LoanList.printPersonLoans(matricNo); + + ui.drawTable(LoanList.getPersonLoansStruct(matricNo)); + ui.print(output); + + return output; + } +} diff --git a/src/main/java/eggventory/logic/parsers/ParseList.java b/src/main/java/eggventory/logic/parsers/ParseList.java index 372e9dd195..7b29e8ab4b 100644 --- a/src/main/java/eggventory/logic/parsers/ParseList.java +++ b/src/main/java/eggventory/logic/parsers/ParseList.java @@ -4,6 +4,7 @@ import eggventory.logic.commands.Command; import eggventory.logic.commands.CommandDictionary; import eggventory.logic.commands.list.ListPersonCommand; +import eggventory.logic.commands.list.ListPersonLoansCommand; import eggventory.logic.commands.list.ListStockCommand; import eggventory.logic.commands.list.ListStockTypeCommand; import eggventory.commons.enums.CommandType; @@ -30,12 +31,14 @@ private Command processListStockType(String input) throws BadInputException { private Command processListPerson(String input) throws BadInputException { String[] inputArr = input.split(" +"); - if (inputArr.length > 1) { + switch (inputArr.length) { + case 1: + return new ListPersonCommand(CommandType.LIST); + case 2: + return new ListPersonLoansCommand(CommandType.LIST, inputArr[1]); + default: throw new BadInputException(CommandDictionary.getCommandUsage("list person")); } - - return new ListPersonCommand(CommandType.LIST); - } /** From eb83660bbaa0b4835ce004ecdbff8390c8e9f2fb Mon Sep 17 00:00:00 2001 From: Deculsion Date: Fri, 1 Nov 2019 16:05:07 +0800 Subject: [PATCH 10/16] Checkstyle fixes. --- .../eggventory/logic/commands/list/ListPersonCommand.java | 1 + .../logic/commands/list/ListPersonLoansCommand.java | 2 +- src/main/java/eggventory/model/LoanList.java | 4 ++++ src/main/java/eggventory/model/loans/Loan.java | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/eggventory/logic/commands/list/ListPersonCommand.java b/src/main/java/eggventory/logic/commands/list/ListPersonCommand.java index 2431ccafd8..bdc0659034 100644 --- a/src/main/java/eggventory/logic/commands/list/ListPersonCommand.java +++ b/src/main/java/eggventory/logic/commands/list/ListPersonCommand.java @@ -9,6 +9,7 @@ //@@author Deculsion public class ListPersonCommand extends Command { + public ListPersonCommand(CommandType type) { super(type); } diff --git a/src/main/java/eggventory/logic/commands/list/ListPersonLoansCommand.java b/src/main/java/eggventory/logic/commands/list/ListPersonLoansCommand.java index a0f648d312..c556a2b8a5 100644 --- a/src/main/java/eggventory/logic/commands/list/ListPersonLoansCommand.java +++ b/src/main/java/eggventory/logic/commands/list/ListPersonLoansCommand.java @@ -10,7 +10,7 @@ import eggventory.ui.Ui; //@@author Deculsion -public class ListPersonLoansCommand extends Command{ +public class ListPersonLoansCommand extends Command { String matricNo; public ListPersonLoansCommand(CommandType type, String matricNo) { diff --git a/src/main/java/eggventory/model/LoanList.java b/src/main/java/eggventory/model/LoanList.java index 3f906c6e90..d9bc07cbce 100644 --- a/src/main/java/eggventory/model/LoanList.java +++ b/src/main/java/eggventory/model/LoanList.java @@ -183,6 +183,10 @@ public static String printStockLoans(String stockCode) { return output; } + /** + * Returns all of a person's loans as a TableStruct. + * @param matricNo Matriculation number of person to output. + */ public static TableStruct getPersonLoansStruct(String matricNo) { TableStruct dataTable = new TableStruct("Loans of " + matricNo); dataTable.setTableColumns("Stock Code", "Quantity Loaned"); diff --git a/src/main/java/eggventory/model/loans/Loan.java b/src/main/java/eggventory/model/loans/Loan.java index 66cdb74189..90a1f57786 100644 --- a/src/main/java/eggventory/model/loans/Loan.java +++ b/src/main/java/eggventory/model/loans/Loan.java @@ -85,6 +85,9 @@ public String toString() { return getMatricNo() + " loaned " + getQuantity() + " of " + getStockCode() + "."; } + /** + * Gets the data of this stock as an arraylist. + */ public ArrayList getStockDataAsArray() { ArrayList data = new ArrayList<>(); From 2c1e807ce5f359ed58ddb1459a8c748e1764d3df Mon Sep 17 00:00:00 2001 From: Deculsion Date: Tue, 5 Nov 2019 13:16:54 +0800 Subject: [PATCH 11/16] Fix basic adding of new loan --- data/saved_stocks.csv | 4 +--- src/main/java/eggventory/Eggventory.java | 4 +++- .../logic/commands/add/AddLoanCommand.java | 23 +++++++++++++------ src/main/java/eggventory/model/LoanList.java | 15 ++++++++---- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/data/saved_stocks.csv b/data/saved_stocks.csv index b5ea440efd..6ed6c287aa 100644 --- a/data/saved_stocks.csv +++ b/data/saved_stocks.csv @@ -1,6 +1,4 @@ Uncategorised,#TEST,100,TD,0 Uncategorised,#TEST2,100,TD2,0 - - - +Uncategorised,R100,1000,Resistors,0 diff --git a/src/main/java/eggventory/Eggventory.java b/src/main/java/eggventory/Eggventory.java index 0fba79043c..0d2420b059 100644 --- a/src/main/java/eggventory/Eggventory.java +++ b/src/main/java/eggventory/Eggventory.java @@ -3,6 +3,7 @@ import eggventory.logic.commands.Command; import eggventory.commons.enums.CommandType; import eggventory.logic.parsers.Parser; +import eggventory.model.LoanList; import eggventory.model.PersonList; import eggventory.model.StockList; import eggventory.storage.Storage; @@ -21,6 +22,7 @@ public class Eggventory { private static Parser parser; private static Ui ui; private static StockList stockList; + private static LoanList loanList; private static PersonList personList; //private static LoanList loanList; @@ -37,7 +39,7 @@ public static void main(String[] args) { storage = new Storage(stockFilePath, stockTypesFilePath); parser = new Parser(); stockList = storage.load(); - //loanList = new LoanList(); + loanList = new LoanList(); personList = new PersonList(); /* diff --git a/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java b/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java index b601be1f37..e0addd30b4 100644 --- a/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java +++ b/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java @@ -21,18 +21,25 @@ public class AddLoanCommand extends Command { * @param matricNo the matric number of the person making the loan. * @param quantity the quantity loaned. */ - public AddLoanCommand(CommandType type, String stockCode, String matricNo, int quantity) { + public AddLoanCommand(CommandType type, String matricNo, String stockCode, int quantity) { super(type); this.stockCode = stockCode; this.matricNo = matricNo; this.quantity = quantity; } + private boolean stockExists() { + if (LoanList.getStockLoanedQuantity(stockCode) == -1) { + return false; + } + + return true; + } + private boolean sufficientStock() { if (quantity - LoanList.getStockLoanedQuantity(stockCode) < 0) { return false; } - return true; } @@ -45,16 +52,18 @@ private boolean sufficientStock() { */ public String execute(StockList list, Ui ui, Storage storage) { String output = ""; - if (sufficientStock()) { + if (!stockExists()) { + output += "OOPS that stock does not exist!"; + } else if (!sufficientStock()) { + output = ("OOPS there is insufficient stock to loan out!"); + } else { LoanList.addLoan(stockCode, matricNo, quantity); output = (String.format("Nice, I have added this loan for you: \n" + "Stock: %s | Person: %s | Quantity: %d", stockCode, matricNo, quantity)); - - ui.print(output); - } else { - output = ("OOPS there is insufficient stock to loan out!"); } + ui.print(output); + return output; } } diff --git a/src/main/java/eggventory/model/LoanList.java b/src/main/java/eggventory/model/LoanList.java index d9bc07cbce..fcdc12f90a 100644 --- a/src/main/java/eggventory/model/LoanList.java +++ b/src/main/java/eggventory/model/LoanList.java @@ -71,13 +71,10 @@ public static boolean deleteLoan(String stockCode, String matricNo) { } /** - * Returns the Loan quantity of a queried Loan. - * The map requires the exact same instance of the key in order to access the quantity. - * Therefore constructing the key (pair of matricNo/stockCode) cannot directly access the value (the Loan). - * Rather, we have to compare the pairs using .equals and then use the original instance to access the Loan. + * Returns the quantity of a certain Stock that a Person has loaned out. * @param stockCode the stockCode of the Stock involved. * @param matricNo the matric number of the Person involved. - * @return the quantity. + * @return the quantity loaned out by a person. */ public static int getLoanQuantity(String stockCode, String matricNo) { Loan loan = findLoan(stockCode, matricNo); @@ -87,7 +84,15 @@ public static int getLoanQuantity(String stockCode, String matricNo) { return loan.getQuantity(); } + /** + * Returns the total quantity of a certain Stock has been loaned out. + * @param stockCode stockCode of the Stock to check + * @return The quantity loaned out + */ public static int getStockLoanedQuantity(String stockCode) { + if (stockLoaned.get(stockCode) == null) { + return -1; + } return stockLoaned.get(stockCode); } From ca78761ba56f6a7b5739a17f61a740acd32fd47a Mon Sep 17 00:00:00 2001 From: Deculsion Date: Tue, 5 Nov 2019 13:23:34 +0800 Subject: [PATCH 12/16] Add Loan works full now --- .../eggventory/logic/commands/add/AddLoanCommand.java | 2 +- .../logic/commands/add/AddStockCommand.java | 2 ++ .../logic/commands/delete/DeleteLoanCommand.java | 2 +- src/main/java/eggventory/model/LoanList.java | 11 ++++++++++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java b/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java index e0addd30b4..7b92cd6272 100644 --- a/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java +++ b/src/main/java/eggventory/logic/commands/add/AddLoanCommand.java @@ -37,7 +37,7 @@ private boolean stockExists() { } private boolean sufficientStock() { - if (quantity - LoanList.getStockLoanedQuantity(stockCode) < 0) { + if (LoanList.getStockLoanedQuantity(stockCode) - quantity < 0) { return false; } return true; diff --git a/src/main/java/eggventory/logic/commands/add/AddStockCommand.java b/src/main/java/eggventory/logic/commands/add/AddStockCommand.java index 3cf6a1c085..100a9899ee 100644 --- a/src/main/java/eggventory/logic/commands/add/AddStockCommand.java +++ b/src/main/java/eggventory/logic/commands/add/AddStockCommand.java @@ -1,5 +1,6 @@ package eggventory.logic.commands.add; +import eggventory.model.LoanList; import eggventory.model.StockList; import eggventory.logic.commands.Command; import eggventory.commons.exceptions.BadInputException; @@ -69,5 +70,6 @@ public String execute(StockList list, Ui ui, Storage storage) throws BadInputExc */ public void execute(StockList list) { list.addStock(stockType, stockCode, quantity, description); + LoanList.addStock(stockCode, quantity); } } diff --git a/src/main/java/eggventory/logic/commands/delete/DeleteLoanCommand.java b/src/main/java/eggventory/logic/commands/delete/DeleteLoanCommand.java index c7c4ac3b1f..d670b4b323 100644 --- a/src/main/java/eggventory/logic/commands/delete/DeleteLoanCommand.java +++ b/src/main/java/eggventory/logic/commands/delete/DeleteLoanCommand.java @@ -25,7 +25,7 @@ public DeleteLoanCommand(CommandType type, String stockCode, String matricNo) { super(type); this.stockCode = stockCode; this.matricNo = matricNo; - this.quantity = LoanList.getLoanQuantity(stockCode, matricNo); + this.quantity = LoanList.getPersonLoanQuantity(stockCode, matricNo); } @Override diff --git a/src/main/java/eggventory/model/LoanList.java b/src/main/java/eggventory/model/LoanList.java index fcdc12f90a..1e25702939 100644 --- a/src/main/java/eggventory/model/LoanList.java +++ b/src/main/java/eggventory/model/LoanList.java @@ -70,13 +70,22 @@ public static boolean deleteLoan(String stockCode, String matricNo) { return true; } + /** + * Adds a new stock to track in LoanList. + * @param stockCode The code of the stock + * @param quantity The starting quantity of the stock + */ + public static void addStock(String stockCode, int quantity) { + updateStockLoaned(stockCode, quantity); + } + /** * Returns the quantity of a certain Stock that a Person has loaned out. * @param stockCode the stockCode of the Stock involved. * @param matricNo the matric number of the Person involved. * @return the quantity loaned out by a person. */ - public static int getLoanQuantity(String stockCode, String matricNo) { + public static int getPersonLoanQuantity(String stockCode, String matricNo) { Loan loan = findLoan(stockCode, matricNo); if (loan == null) { return -1; From 7f10d2a11e8ed9f277eea5440cd284086f5defc7 Mon Sep 17 00:00:00 2001 From: Deculsion Date: Tue, 5 Nov 2019 13:39:01 +0800 Subject: [PATCH 13/16] Add Loan for single person works now --- .../eggventory/logic/parsers/ParseList.java | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/main/java/eggventory/logic/parsers/ParseList.java b/src/main/java/eggventory/logic/parsers/ParseList.java index 7b29e8ab4b..da809e1a5a 100644 --- a/src/main/java/eggventory/logic/parsers/ParseList.java +++ b/src/main/java/eggventory/logic/parsers/ParseList.java @@ -3,10 +3,7 @@ import eggventory.commons.exceptions.InsufficientInfoException; import eggventory.logic.commands.Command; import eggventory.logic.commands.CommandDictionary; -import eggventory.logic.commands.list.ListPersonCommand; -import eggventory.logic.commands.list.ListPersonLoansCommand; -import eggventory.logic.commands.list.ListStockCommand; -import eggventory.logic.commands.list.ListStockTypeCommand; +import eggventory.logic.commands.list.*; import eggventory.commons.enums.CommandType; import eggventory.commons.exceptions.BadInputException; @@ -30,15 +27,29 @@ private Command processListStockType(String input) throws BadInputException { } private Command processListPerson(String input) throws BadInputException { - String[] inputArr = input.split(" +"); - switch (inputArr.length) { - case 1: - return new ListPersonCommand(CommandType.LIST); - case 2: - return new ListPersonLoansCommand(CommandType.LIST, inputArr[1]); - default: + String[] inputArr = input.split(" "); + + if (inputArr.length > 1) { throw new BadInputException(CommandDictionary.getCommandUsage("list person")); } + + return new ListPersonCommand(CommandType.LIST); + } + + private Command processListLoan(String input) throws BadInputException { + String[] inputArr = input.split(" +"); + + switch(inputArr.length) { + case 1: + return new ListLoanCommand(CommandType.LIST); + case 2: + return new ListPersonLoansCommand(CommandType.LIST, inputArr[1]); + + default: + throw new BadInputException(CommandDictionary.getCommandUsage("list loan")); + + } + } /** @@ -71,11 +82,16 @@ public Command parse(String inputString) throws BadInputException, InsufficientI listCommand = processListPerson(inputArr[0]); break; + case "loan": + listCommand = processListLoan(inputString); + break; + default: throw new BadInputException(CommandDictionary.getCommandUsage("list")); } return listCommand; } + } //@@author From 0f062bf36c2fd6a93746e1ab0297dd5ef4a111f5 Mon Sep 17 00:00:00 2001 From: Deculsion Date: Tue, 5 Nov 2019 13:40:44 +0800 Subject: [PATCH 14/16] Add Loan for single person works now --- .../eggventory/logic/parsers/ParseList.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/eggventory/logic/parsers/ParseList.java b/src/main/java/eggventory/logic/parsers/ParseList.java index da809e1a5a..f29aaed9dd 100644 --- a/src/main/java/eggventory/logic/parsers/ParseList.java +++ b/src/main/java/eggventory/logic/parsers/ParseList.java @@ -3,7 +3,11 @@ import eggventory.commons.exceptions.InsufficientInfoException; import eggventory.logic.commands.Command; import eggventory.logic.commands.CommandDictionary; -import eggventory.logic.commands.list.*; +import eggventory.logic.commands.list.ListStockCommand; +import eggventory.logic.commands.list.ListStockTypeCommand; +import eggventory.logic.commands.list.ListLoanCommand; +import eggventory.logic.commands.list.ListPersonLoansCommand; +import eggventory.logic.commands.list.ListPersonCommand; import eggventory.commons.enums.CommandType; import eggventory.commons.exceptions.BadInputException; @@ -39,15 +43,14 @@ private Command processListPerson(String input) throws BadInputException { private Command processListLoan(String input) throws BadInputException { String[] inputArr = input.split(" +"); - switch(inputArr.length) { - case 1: - return new ListLoanCommand(CommandType.LIST); - case 2: - return new ListPersonLoansCommand(CommandType.LIST, inputArr[1]); - - default: - throw new BadInputException(CommandDictionary.getCommandUsage("list loan")); + switch (inputArr.length) { + case 1: + return new ListLoanCommand(CommandType.LIST); + case 2: + return new ListPersonLoansCommand(CommandType.LIST, inputArr[1]); + default: + throw new BadInputException(CommandDictionary.getCommandUsage("list loan")); } } From a3de754e187ca7a6cc6adcf3b8baf88e2073ef9d Mon Sep 17 00:00:00 2001 From: Deculsion Date: Tue, 5 Nov 2019 13:46:15 +0800 Subject: [PATCH 15/16] temp fix for listloan --- src/main/java/eggventory/logic/parsers/ParseList.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/eggventory/logic/parsers/ParseList.java b/src/main/java/eggventory/logic/parsers/ParseList.java index f29aaed9dd..50049c2ec5 100644 --- a/src/main/java/eggventory/logic/parsers/ParseList.java +++ b/src/main/java/eggventory/logic/parsers/ParseList.java @@ -5,7 +5,6 @@ import eggventory.logic.commands.CommandDictionary; import eggventory.logic.commands.list.ListStockCommand; import eggventory.logic.commands.list.ListStockTypeCommand; -import eggventory.logic.commands.list.ListLoanCommand; import eggventory.logic.commands.list.ListPersonLoansCommand; import eggventory.logic.commands.list.ListPersonCommand; import eggventory.commons.enums.CommandType; @@ -45,7 +44,8 @@ private Command processListLoan(String input) throws BadInputException { switch (inputArr.length) { case 1: - return new ListLoanCommand(CommandType.LIST); + throw new BadInputException(CommandDictionary.getCommandUsage("list loan")); + //return new ListLoanCommand(CommandType.LIST); case 2: return new ListPersonLoansCommand(CommandType.LIST, inputArr[1]); From e9f9be4c07d3d14e828f7160803b58c3a41bfab2 Mon Sep 17 00:00:00 2001 From: Dana Poon Date: Tue, 5 Nov 2019 15:12:41 +0800 Subject: [PATCH 16/16] Delete saved_stocks.csv --- data/saved_stocks.csv | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 data/saved_stocks.csv diff --git a/data/saved_stocks.csv b/data/saved_stocks.csv deleted file mode 100644 index 6ed6c287aa..0000000000 --- a/data/saved_stocks.csv +++ /dev/null @@ -1,4 +0,0 @@ -Uncategorised,#TEST,100,TD,0 -Uncategorised,#TEST2,100,TD2,0 -Uncategorised,R100,1000,Resistors,0 -