diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/resources/Arrival.java b/src/main/java/resources/Arrival.java
index 8db95fc..a34e6fb 100644
--- a/src/main/java/resources/Arrival.java
+++ b/src/main/java/resources/Arrival.java
@@ -1,20 +1,25 @@
package resources;
+import values.Item;
+
import java.util.*;
public class Arrival {
private Available available;
private Stock stock;
- private Map.Entry value;
+ private Item value;
+
public Arrival(Available available, Stock stock) {
this.available = available;
this.stock = stock;
}
- public void arrive(int num, String item) {
- this.value = new AbstractMap.SimpleEntry<>(item, num);
+
+ public void arrive(int num, String name) {
+ this.value = new Item(name, num);
Map stock = this.stock.getValue();
- this.available.updateArrival(value, stock);
+ this.available.updateArrival(new Item(value), stock);
}
- public Map.Entry getValue() {
- return new AbstractMap.SimpleEntry<>(value);
+
+ public Item getValue() {
+ return new Item(value);
}
}
\ No newline at end of file
diff --git a/src/main/java/resources/Available.java b/src/main/java/resources/Available.java
index 37e60ec..f840629 100644
--- a/src/main/java/resources/Available.java
+++ b/src/main/java/resources/Available.java
@@ -1,27 +1,32 @@
package resources;
+import values.Item;
+
import java.util.*;
public class Available {
private Shortage shortage;
- private Deriver deriver;
- private Map.Entry value;
- public void updateArrival(Map.Entry arrival, Map stock) {
+ private Handling handling;
+ private Item value;
+
+ public Available(Shortage shortage, Handling handling) {
+ this.shortage = shortage;
+ this.handling = handling;
+ }
+
+ public void updateArrival(Item arrival, Map stock) {
Map shortage = this.shortage.getValue();
int temp_get3;
- if (stock.get(arrival.getKey()) != null) {
- temp_get3 = stock.get(arrival.getKey());
+ if (stock.get(arrival.getName()) != null) {
+ temp_get3 = stock.get(arrival.getName());
} else {
temp_get3 = 0;
}
- value = new AbstractMap.SimpleEntry<>(arrival.getKey(), (arrival.getValue()+temp_get3));
- this.shortage.updateAvailable(value);
- this.deriver.updateAvailable(value, shortage);
+ value = new Item(arrival.getName(), (arrival.getNum() + temp_get3));
+ this.shortage.updateAvailable(new Item(value));
+ this.handling.updateAvailable(new Item(value), shortage);
}
- public Available(Shortage shortage, Deriver deriver) {
- this.shortage = shortage;
- this.deriver = deriver;
- }
- public Map.Entry getValue() {
- return new AbstractMap.SimpleEntry<>(value);
+
+ public Item getValue() {
+ return new Item(value);
}
}
\ No newline at end of file
diff --git a/src/main/java/resources/Deriver.java b/src/main/java/resources/Deriver.java
deleted file mode 100644
index b4ed5ec..0000000
--- a/src/main/java/resources/Deriver.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package resources;
-import java.util.*;
-
-public class Deriver {
- private Map.Entry available;
- private Map.Entry request;
- private Stock stock;
- private Map.Entry> value;
- public void updateAvailable(Map.Entry available, Map shortage) {
- this.available = available;
- Map.Entry> temp_if2;
- int temp_get4;
- if (shortage.get(available.getKey()) != null) {
- temp_get4 = shortage.get(available.getKey());
- } else {
- temp_get4 = 0;
- }
- if ((available.getValue()>=temp_get4)) {
- int temp_get5;
- if (shortage.get(available.getKey()) != null) {
- temp_get5 = shortage.get(available.getKey());
- } else {
- temp_get5 = 0;
- }
- int temp_get6;
- if (shortage.get(available.getKey()) != null) {
- temp_get6 = shortage.get(available.getKey());
- } else {
- temp_get6 = 0;
- }
- temp_if2 = new AbstractMap.SimpleEntry<>(available.getKey(), new AbstractMap.SimpleEntry<>(temp_get5, (available.getValue()-temp_get6)));
- } else {
- temp_if2 = new AbstractMap.SimpleEntry<>(available.getKey(), new AbstractMap.SimpleEntry<>(0, available.getValue()));
- }
- value = temp_if2;
- this.stock.updateDeriver(value);
- }
- public void updateRequest(Map.Entry request, Map stock) {
- this.request = request;
- Map.Entry> temp_if3;
- int temp_get7;
- if (stock.get(request.getKey()) != null) {
- temp_get7 = stock.get(request.getKey());
- } else {
- temp_get7 = 0;
- }
- if ((temp_get7>=request.getValue())) {
- int temp_get8;
- if (stock.get(request.getKey()) != null) {
- temp_get8 = stock.get(request.getKey());
- } else {
- temp_get8 = 0;
- }
- temp_if3 = new AbstractMap.SimpleEntry<>(request.getKey(), new AbstractMap.SimpleEntry<>(request.getValue(), (temp_get8-request.getValue())));
- } else {
- int temp_get9;
- if (stock.get(request.getKey()) != null) {
- temp_get9 = stock.get(request.getKey());
- } else {
- temp_get9 = 0;
- }
- temp_if3 = new AbstractMap.SimpleEntry<>(request.getKey(), new AbstractMap.SimpleEntry<>(0, temp_get9));
- }
- value = temp_if3;
- this.stock.updateDeriver(value);
- }
- public Deriver(Stock stock) {
- this.stock = stock;
- }
- public Map.Entry> getValue() {
- return new AbstractMap.SimpleEntry<>(value);
- }
-}
\ No newline at end of file
diff --git a/src/main/java/resources/Handling.java b/src/main/java/resources/Handling.java
new file mode 100644
index 0000000..b6740c7
--- /dev/null
+++ b/src/main/java/resources/Handling.java
@@ -0,0 +1,80 @@
+package resources;
+import values.Item;
+import values.ItemHandling;
+
+import java.util.*;
+
+public class Handling {
+ private Item available;
+ private Item request;
+ private Stock stock;
+ private ItemHandling value;
+
+ public Handling(Stock stock) {
+ this.stock = stock;
+ }
+
+ public void updateAvailable(Item available, Map shortage) {
+ this.available = available;
+ ItemHandling temp_if2;
+ int temp_get4;
+ if (shortage.get(available.getName()) != null) {
+ temp_get4 = shortage.get(available.getName());
+ } else {
+ temp_get4 = 0;
+ }
+ if ((available.getNum() >= temp_get4)) {
+ int temp_get5;
+ if (shortage.get(available.getName()) != null) {
+ temp_get5 = shortage.get(available.getName());
+ } else {
+ temp_get5 = 0;
+ }
+ int temp_get6;
+ if (shortage.get(available.getName()) != null) {
+ temp_get6 = shortage.get(available.getName());
+ } else {
+ temp_get6 = 0;
+ }
+ temp_if2 = new ItemHandling(available.getName(), temp_get5, available.getNum() - temp_get6);
+ } else {
+ temp_if2 = new ItemHandling(available.getName(), 0, available.getNum());
+ }
+ value = temp_if2;
+ this.stock.updateHandling(new ItemHandling(value));
+ }
+
+ public void updateRequest(Item request, Map stock) {
+ this.request = request;
+ ItemHandling temp_if3;
+ int temp_get7;
+ if (stock.get(request.getName()) != null) {
+ temp_get7 = stock.get(request.getName());
+ } else {
+ temp_get7 = 0;
+ }
+ if ((temp_get7>=request.getNum())) {
+ int temp_get8;
+ if (stock.get(request.getName()) != null) {
+ temp_get8 = stock.get(request.getName());
+ } else {
+ temp_get8 = 0;
+ }
+ temp_if3 = new ItemHandling(request.getName(), request.getNum(), temp_get8 - request.getNum());
+ } else {
+ int temp_get9;
+ if (stock.get(request.getName()) != null) {
+ temp_get9 = stock.get(request.getName());
+ } else {
+ temp_get9 = 0;
+ }
+ temp_if3 = new ItemHandling(request.getName(), 0, temp_get9);
+ }
+ value = temp_if3;
+ this.stock.updateHandling(new ItemHandling(value));
+ }
+
+ public ItemHandling getValue() {
+ return new ItemHandling(value);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/resources/Request.java b/src/main/java/resources/Request.java
index b5bd53e..b8857ae 100644
--- a/src/main/java/resources/Request.java
+++ b/src/main/java/resources/Request.java
@@ -1,23 +1,28 @@
package resources;
+import values.Item;
+
import java.util.*;
public class Request {
private Shortage shortage;
- private Deriver deriver;
+ private Handling handling;
private Stock stock;
- private Map.Entry value;
- public Request(Shortage shortage, Deriver deriver, Stock stock) {
+ private Item value;
+
+ public Request(Shortage shortage, Handling handling, Stock stock) {
this.shortage = shortage;
- this.deriver = deriver;
+ this.handling = handling;
this.stock = stock;
}
- public void req(int num, String item) {
- this.value = new AbstractMap.SimpleEntry<>(item, num);
+
+ public void req(int num, String name) {
+ this.value = new Item(name, num);
Map stock = this.stock.getValue();
- this.shortage.updateRequest(value, stock);
- this.deriver.updateRequest(value, stock);
+ this.shortage.updateRequest(new Item(value), stock);
+ this.handling.updateRequest(new Item(value), stock);
}
- public Map.Entry getValue() {
- return new AbstractMap.SimpleEntry<>(value);
+
+ public Item getValue() {
+ return new Item(value);
}
}
\ No newline at end of file
diff --git a/src/main/java/resources/Shipping.java b/src/main/java/resources/Shipping.java
index 97e6dd2..fe26674 100644
--- a/src/main/java/resources/Shipping.java
+++ b/src/main/java/resources/Shipping.java
@@ -1,12 +1,16 @@
package resources;
+import values.Item;
+
import java.util.*;
public class Shipping {
- private Deriver deriver;
- public Shipping(Deriver deriver) {
- this.deriver = deriver;
+ private Handling handling;
+
+ public Shipping(Handling handling) {
+ this.handling = handling;
}
- public Map.Entry getValue() {
- return new AbstractMap.SimpleEntry<>(this.deriver.getValue().getKey(), this.deriver.getValue().getValue().getKey());
+
+ public Item getValue() {
+ return new Item(this.handling.getValue().getName(), this.handling.getValue().getShippingNum());
}
}
\ No newline at end of file
diff --git a/src/main/java/resources/Shortage.java b/src/main/java/resources/Shortage.java
index 3df25e8..5875f3a 100644
--- a/src/main/java/resources/Shortage.java
+++ b/src/main/java/resources/Shortage.java
@@ -1,50 +1,55 @@
package resources;
+import values.Item;
+
import java.util.*;
public class Shortage {
- private Map.Entry request;
- private Map.Entry available;
+ private Item request;
+ private Item available;
private Map value = new HashMap();
- public void updateRequest(Map.Entry request, Map stock) {
+
+ public void updateRequest(Item request, Map stock) {
this.request = request;
Map temp_if0;
int temp_get0;
- if (stock.get(request.getKey()) != null) {
- temp_get0 = stock.get(request.getKey());
+ if (stock.get(request.getName()) != null) {
+ temp_get0 = stock.get(request.getName());
} else {
temp_get0 = 0;
}
- if ((temp_get0>=request.getValue())) {
+ if ((temp_get0>=request.getNum())) {
temp_if0 = this.value;
} else {
int temp_get1;
- if (this.value.get(request.getKey()) != null) {
- temp_get1 = this.value.get(request.getKey());
- } else {
- temp_get1 = 0;
- }
- this.value.put(request.getKey(),(temp_get1+request.getValue()));
+ if (this.value.get(request.getName()) != null) {
+ temp_get1 = this.value.get(request.getName());
+ } else {
+ temp_get1 = 0;
+ }
+ this.value.put(request.getName(),(temp_get1 + request.getNum()));
temp_if0 = this.value;
}
value = temp_if0;
}
- public void updateAvailable(Map.Entry available) {
+
+ public void updateAvailable(Item available) {
this.available = available;
Map temp_if1;
int temp_get2;
- if (this.value.get(available.getKey()) != null) {
- temp_get2 = this.value.get(available.getKey());
+ if (this.value.get(available.getName()) != null) {
+ temp_get2 = this.value.get(available.getName());
} else {
temp_get2 = 0;
}
- if ((available.getValue()>=temp_get2)) {
- this.value.put(available.getKey(),0);
+ if ((available.getNum() >= temp_get2)) {
+ this.value.put(available.getName(), 0);
temp_if1 = this.value;
} else {
temp_if1 = this.value;
}
value = temp_if1;
}
+
public Map getValue() {
return new HashMap<>(value);
}
diff --git a/src/main/java/resources/Stock.java b/src/main/java/resources/Stock.java
index cb5976d..79b17fc 100644
--- a/src/main/java/resources/Stock.java
+++ b/src/main/java/resources/Stock.java
@@ -1,11 +1,15 @@
package resources;
+import values.ItemHandling;
+
import java.util.*;
public class Stock {
private Map value = new HashMap();
- public void updateDeriver(Map.Entry> deriver) {
- this.value.put(deriver.getKey(),deriver.getValue().getValue());
+
+ public void updateHandling(ItemHandling itemHandling) {
+ this.value.put(itemHandling.getName(), itemHandling.getStockNum());
}
+
public Map getValue() {
return new HashMap<>(value);
}
diff --git a/src/main/java/resources/StockManagement.java b/src/main/java/resources/StockManagement.java
index 7de5ab0..621e3ad 100644
--- a/src/main/java/resources/StockManagement.java
+++ b/src/main/java/resources/StockManagement.java
@@ -1,47 +1,60 @@
package resources;
+import values.Item;
+import values.ItemHandling;
+
import java.util.*;
public class StockManagement {
private Stock stock;
- private Deriver deriver;
+ private Handling handling;
private Shortage shortage;
private Available available;
private Arrival arrival;
private Shipping shipping;
private Request request;
+
public StockManagement() {
stock = new Stock();
- deriver = new Deriver(stock);
+ handling = new Handling(stock);
shortage = new Shortage();
- available = new Available(shortage,deriver);
+ available = new Available(shortage, handling);
arrival = new Arrival(available,stock);
- shipping = new Shipping(deriver);
- request = new Request(shortage,deriver,stock);
+ shipping = new Shipping(handling);
+ request = new Request(shortage, handling,stock);
}
+
public void arrive(int num, String item) {
this.arrival.arrive(num, item);
}
+
public void req(int num, String item) {
this.request.req(num, item);
}
- public Map.Entry getRequest() {
+
+ public Item getRequest() {
return request.getValue();
}
- public Map.Entry getShipping() {
+
+ public Item getShipping() {
return shipping.getValue();
}
- public Map.Entry getArrival() {
+
+ public Item getArrival() {
return arrival.getValue();
}
+
public Map getShortage() {
return shortage.getValue();
}
- public Map.Entry getAvailable() {
+
+ public Item getAvailable() {
return available.getValue();
}
- public Map.Entry> getDeriver() {
- return deriver.getValue();
+
+ public ItemHandling getHandling() {
+ return handling.getValue();
}
+
public Map getStock() {
return stock.getValue();
}
diff --git a/src/main/java/values/Item.java b/src/main/java/values/Item.java
new file mode 100644
index 0000000..d39e89e
--- /dev/null
+++ b/src/main/java/values/Item.java
@@ -0,0 +1,24 @@
+package values;
+
+public class Item {
+ private String name;
+ private int num;
+
+ public Item(String name, int num) {
+ this.name = name;
+ this.num = num;
+ }
+
+ public Item(Item other) {
+ this.name = other.name;
+ this.num = other.num;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getNum() {
+ return num;
+ }
+}
diff --git a/src/main/java/values/ItemHandling.java b/src/main/java/values/ItemHandling.java
new file mode 100644
index 0000000..c68e604
--- /dev/null
+++ b/src/main/java/values/ItemHandling.java
@@ -0,0 +1,31 @@
+package values;
+
+public class ItemHandling {
+ private String name;
+ private int shippingNum;
+ private int stockNum;
+
+ public ItemHandling(String name, int shippingNum, int stockNum) {
+ this.name = name;
+ this.shippingNum = shippingNum;
+ this.stockNum = stockNum;
+ }
+
+ public ItemHandling(ItemHandling other) {
+ this.name = other.name;
+ this.shippingNum = other.shippingNum;
+ this.stockNum = other.stockNum;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getShippingNum() {
+ return shippingNum;
+ }
+
+ public int getStockNum() {
+ return stockNum;
+ }
+}
diff --git a/src/main/java/views/MainFrame.java b/src/main/java/views/MainFrame.java
index 1db2d3f..5a0d484 100644
--- a/src/main/java/views/MainFrame.java
+++ b/src/main/java/views/MainFrame.java
@@ -19,6 +19,7 @@
import javax.swing.border.TitledBorder;
import resources.StockManagement;
+import values.Item;
public class MainFrame extends JFrame {
private StockManagement stockManager;
@@ -84,10 +85,10 @@
arrivePanel.clearValues();
stockPanel.update(stockManager.getStock());
shortagePanel.update(stockManager.getShortage());
- Map.Entry shipping = stockManager.getShipping();
- if (shipping.getKey() != null && shipping.getValue() > 0) {
- shippingNameLbl.setText(shipping.getKey());
- shippingNumLbl.setText("" + shipping.getValue());
+ Item shipping = stockManager.getShipping();
+ if (shipping.getName() != null && shipping.getNum() > 0) {
+ shippingNameLbl.setText(shipping.getName());
+ shippingNumLbl.setText("" + shipping.getNum());
} else {
shippingNameLbl.setText("");
shippingNumLbl.setText("");
@@ -124,10 +125,10 @@
requestPanel.clearValues();
stockPanel.update(stockManager.getStock());
shortagePanel.update(stockManager.getShortage());
- Map.Entry shipping = stockManager.getShipping();
- if (shipping.getKey() != null && shipping.getValue() > 0) {
- shippingNameLbl.setText(shipping.getKey());
- shippingNumLbl.setText("" + shipping.getValue());
+ Item shipping = stockManager.getShipping();
+ if (shipping.getName() != null && shipping.getNum() > 0) {
+ shippingNameLbl.setText(shipping.getName());
+ shippingNumLbl.setText("" + shipping.getNum());
} else {
shippingNameLbl.setText("");
shippingNumLbl.setText("");
diff --git a/src/test/java/TestMain.java b/src/test/java/TestMain.java
index d9851a9..ae91a2e 100644
--- a/src/test/java/TestMain.java
+++ b/src/test/java/TestMain.java
@@ -1,10 +1,15 @@
import java.util.Map;
-
+
+import org.junit.Test;
import resources.StockManagement;
-
+import values.Item;
+
+import static org.junit.Assert.assertEquals;
+
public class TestMain {
-
- public static void main(String[] args) {
+
+ @Test
+ public void test() {
StockManagement stockMan = new StockManagement();
stockMan.arrive(10, "A");
System.out.println("Arrive A: 10");
@@ -13,15 +18,19 @@
Map stock1 = stockMan.getStock();
Map shortage1 = stockMan.getShortage();
- Map.Entry shipping1 = stockMan.getShipping();
+ Item shipping1 = stockMan.getShipping();
System.out.println("stock:");
System.out.println("A: " + stock1.get("A"));
System.out.println("B: " + stock1.get("B"));
+ assertEquals((int)stock1.get("A"), 10);
+ assertEquals((int)stock1.get("B"), 20);
System.out.println("shotage:");
System.out.println("A: " + shortage1.get("A"));
System.out.println("B: " + shortage1.get("B"));
+ assertEquals((int)shortage1.get("A"), 0);
+ assertEquals((int)shortage1.get("B"), 0);
System.out.println("shipping:");
- if (shipping1 != null) System.out.println(shipping1.getKey() +": " + shipping1.getValue());
+ if (shipping1 != null) System.out.println(shipping1.getName() +": " + shipping1.getNum());
stockMan.req(5, "A");
@@ -29,45 +38,65 @@
Map stock2 = stockMan.getStock();
Map shortage2 = stockMan.getShortage();
- Map.Entry shipping2 = stockMan.getShipping();
+ Item shipping2 = stockMan.getShipping();
System.out.println("stock:");
System.out.println("A: " + stock2.get("A"));
System.out.println("B: " + stock2.get("B"));
+ assertEquals((int)stock2.get("A"), 5);
+ assertEquals((int)stock2.get("B"), 20);
System.out.println("shotage:");
System.out.println("A: " + shortage2.get("A"));
System.out.println("B: " + shortage2.get("B"));
+ assertEquals((int)shortage2.get("A"), 0);
+ assertEquals((int)shortage2.get("B"), 0);
System.out.println("shipping:");
- if (shipping2 != null) System.out.println(shipping2.getKey() +": " + shipping2.getValue());
+ if (shipping2 != null) {
+ System.out.println(shipping2.getName() +": " + shipping2.getNum());
+ assertEquals(shipping2.getName(), "A");
+ assertEquals(shipping2.getNum(), 5);
+ }
stockMan.req(10, "A");
System.out.println("Request A: 10");
Map stock3 = stockMan.getStock();
Map shortage3 = stockMan.getShortage();
- Map.Entry shipping3 = stockMan.getShipping();
+ Item shipping3 = stockMan.getShipping();
System.out.println("stock:");
System.out.println("A: " + stock3.get("A"));
System.out.println("B: " + stock3.get("B"));
+ assertEquals((int)stock3.get("A"), 5);
+ assertEquals((int)stock3.get("B"), 20);
System.out.println("shotage:");
System.out.println("A: " + shortage3.get("A"));
System.out.println("B: " + shortage3.get("B"));
+ assertEquals((int)shortage3.get("A"), 10);
+ assertEquals((int)shortage3.get("B"), 0);
System.out.println("shipping:");
- if (shipping3 != null) System.out.println(shipping3.getKey() +": " + shipping3.getValue());
+ if (shipping3 != null) System.out.println(shipping3.getName() +": " + shipping3.getNum());
stockMan.arrive(10, "A");
System.out.println("Arrive A: 10");
Map stock4 = stockMan.getStock();
Map shortage4 = stockMan.getShortage();
- Map.Entry shipping4 = stockMan.getShipping();
+ Item shipping4 = stockMan.getShipping();
System.out.println("stock:");
System.out.println("A: " + stock4.get("A"));
System.out.println("B: " + stock4.get("B"));
+ assertEquals((int)stock4.get("A"), 5);
+ assertEquals((int)stock4.get("B"), 20);
System.out.println("shotage:");
System.out.println("A: " + shortage4.get("A"));
System.out.println("B: " + shortage4.get("B"));
+ assertEquals((int)shortage4.get("A"), 0);
+ assertEquals((int)shortage4.get("B"), 0);
System.out.println("shipping:");
- if (shipping4 != null) System.out.println(shipping4.getKey() +": " + shipping4.getValue());
+ if (shipping4 != null) {
+ System.out.println(shipping4.getName() +": " + shipping4.getNum());
+ assertEquals(shipping4.getName(), "A");
+ assertEquals(shipping4.getNum(), 10);
+ }
}
}