diff --git a/src/Main/Cart.java b/src/Main/Cart.java index 11811cf..13ad26a 100644 --- a/src/Main/Cart.java +++ b/src/Main/Cart.java @@ -18,7 +18,7 @@ package Main; /** * - * @author Studente + * @author Daniil Gentili */ public class Cart extends Container { public Cart(String input) { diff --git a/src/Main/Client.java b/src/Main/Client.java index 4636ae5..e3f3c89 100644 --- a/src/Main/Client.java +++ b/src/Main/Client.java @@ -19,8 +19,6 @@ package Main; import Payloads.RequestPayload; import Payloads.ResponsePayload; import Payloads.ServerException; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; @@ -30,9 +28,9 @@ import java.net.Socket; /** * - * @author root + * @author Daniil Gentili */ -public class Client implements ActionListener { +public class Client { private BufferedWriter out; private BufferedReader in; @@ -70,7 +68,6 @@ public class Client implements ActionListener { } public void commit() throws IOException, ServerException { - RequestPayload request = new RequestPayload("POST", "/", cart.getPayload()); request.shouldKeepAlive(true); request.write(out); @@ -80,21 +77,7 @@ public class Client implements ActionListener { if (response.getResponseCode() != 200) { throw new ServerException(response); } - warehouse = new Warehouse(response.getPayload()); - cart = new Cart(); - } - - @Override - public void actionPerformed(ActionEvent e) { - System.out.println(e.paramString()); -/* if (e.getText().equals("Buy")) { - try { - this.addToCart(Integer.parseInt(e.getActionCommand())); - } catch (ClientException ex) { - Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex); - } - } else { - } - */ + this.warehouse.rebuild(response.getPayload()); + this.cart.rebuild(); } } diff --git a/src/Main/ClientException.java b/src/Main/ClientException.java index 74a430c..de194c4 100644 --- a/src/Main/ClientException.java +++ b/src/Main/ClientException.java @@ -18,7 +18,7 @@ package Main; /** * - * @author root + * @author Daniil Gentili */ public class ClientException extends Exception { diff --git a/src/Main/Container.java b/src/Main/Container.java index 07b14ac..2c6cd95 100644 --- a/src/Main/Container.java +++ b/src/Main/Container.java @@ -20,7 +20,7 @@ import java.util.Hashtable; /** * - * @author root + * @author Daniil Gentili */ public abstract class Container { @@ -32,6 +32,17 @@ public abstract class Container Constructors */ public Container(String response) { + rebuild(response); + } + public Container() { + rebuild(); + } + + public void rebuild() { + this.products.clear(); + } + public void rebuild(String response) { + this.products.clear(); String[] split; for (String line: response.split("\n")) { split = line.split(";"); @@ -48,11 +59,6 @@ public abstract class Container ); } } - public Container() { - - } - - /** * Get the string payload of the container * @return The string payload diff --git a/src/Main/Product.java b/src/Main/Product.java index e51e9c4..981eede 100644 --- a/src/Main/Product.java +++ b/src/Main/Product.java @@ -18,7 +18,7 @@ package Main; /** * - * @author Studente + * @author Daniil Gentili */ public class Product { private Double price; diff --git a/src/Main/ProductCollection.java b/src/Main/ProductCollection.java index ddecaef..0f1df09 100644 --- a/src/Main/ProductCollection.java +++ b/src/Main/ProductCollection.java @@ -19,7 +19,7 @@ package Main; /** * - * @author root + * @author Daniil Gentili */ public class ProductCollection { private final Product product; diff --git a/src/Main/Warehouse.java b/src/Main/Warehouse.java index 3af098d..0e0b596 100644 --- a/src/Main/Warehouse.java +++ b/src/Main/Warehouse.java @@ -18,7 +18,7 @@ package Main; /** * - * @author root + * @author Daniil Gentili */ public class Warehouse extends Container { public Warehouse(String input) {