diff --git a/src/ItemsByCapacity.java b/src/ItemsByCapacity.java index 7f9ccaf..1bde0ac 100644 --- a/src/ItemsByCapacity.java +++ b/src/ItemsByCapacity.java @@ -10,7 +10,7 @@ public List> getValue() { List> temp_l1 = new ArrayList<>(); { - for (Map item: this.siteWrapper.getSiteAValue()) { + for (Map item: this.siteWrapper.getSiteValue()) { if ((Integer) item.get("capacity") >= this.capacity.getValue()) { temp_l1.add(item); } diff --git a/src/ItemsByPrice.java b/src/ItemsByPrice.java index fe4b17f..de59ea6 100644 --- a/src/ItemsByPrice.java +++ b/src/ItemsByPrice.java @@ -10,7 +10,7 @@ public List> getValue() { List> temp_l1 = new ArrayList<>(); { - for (Map item: this.siteWrapper.getSiteAValue()) { + for (Map item: this.siteWrapper.getSiteValue()) { if ((Integer) item.get("price") <= this.price.getValue()) { temp_l1.add(item); } diff --git a/src/SSDStore.java b/src/SSDStore.java index 36f3ba0..2836b8c 100644 --- a/src/SSDStore.java +++ b/src/SSDStore.java @@ -4,6 +4,7 @@ private Price price; private Capacity capacity; private SiteA siteA; + private SiteB siteB; private SiteWrapper siteWrapper; private ItemsByCapacity itemsByCapacity; private ItemsByPrice itemsByPrice; @@ -11,7 +12,8 @@ this.price = new Price(); this.capacity = new Capacity(); this.siteA = new SiteA(); - this.siteWrapper = new SiteWrapper(siteA); + this.siteB = new SiteB(); + this.siteWrapper = new SiteWrapper(siteA, siteB); this.itemsByCapacity = new ItemsByCapacity(capacity, siteWrapper); this.itemsByPrice = new ItemsByPrice(price, siteWrapper); } @@ -24,6 +26,9 @@ public List> getSiteA() { return siteA.getValue(); } + public List> getSiteB() { + return siteB.getValue(); + } public List> getItemsByCapacity() { return itemsByCapacity.getValue(); } @@ -39,4 +44,7 @@ public void addProductToSiteA(int capacity, int price) { this.siteA.addProductToSiteA(capacity, price); } + public void addProductToSiteB(int capacity, int price) { + this.siteB.addProductToSiteB(capacity, price); + } } \ No newline at end of file diff --git a/src/SiteB.java b/src/SiteB.java new file mode 100644 index 0000000..1650c73 --- /dev/null +++ b/src/SiteB.java @@ -0,0 +1,14 @@ +import java.util.*; + +public class SiteB { + private List> value = new ArrayList<>(); + public List> getValue() { + return new ArrayList<>(this.value); + } + public void addProductToSiteB(int capacity, int price) { + Map temp_nil = new HashMap(); + temp_nil.put("price",price); + temp_nil.put("capacity",capacity); + this.value.add(0, temp_nil); + } +} \ No newline at end of file diff --git a/src/SiteWrapper.java b/src/SiteWrapper.java index c25318f..a630d21 100644 --- a/src/SiteWrapper.java +++ b/src/SiteWrapper.java @@ -2,10 +2,14 @@ public class SiteWrapper { private SiteA siteA; - public SiteWrapper(SiteA siteA) { + private SiteB siteB; + public SiteWrapper(SiteA siteA, SiteB siteB) { this.siteA = siteA; + this.siteB = siteB; } - public List> getSiteAValue() { - return this.siteA.getValue(); + public List> getSiteValue() { + List> productList = this.siteA.getValue(); + productList.addAll(this.siteB.getValue()); + return productList; } } \ No newline at end of file diff --git a/src/TestMultiSSDStoreUpdate.java b/src/TestMultiSSDStoreUpdate.java new file mode 100644 index 0000000..239c91b --- /dev/null +++ b/src/TestMultiSSDStoreUpdate.java @@ -0,0 +1,73 @@ + + +import static org.junit.Assert.*; + +import java.util.List; +import java.util.Map; + +import org.junit.Test; + +public class TestMultiSSDStoreUpdate { + + @Test + public void test() { + SSDStore store = new SSDStore(); + store.addProductToSiteA(500, 7000); + store.addProductToSiteB(1500, 12000); + + store.setPrice(7000); + List> itemsByPrice = store.getItemsByPrice(); + assertEquals(itemsByPrice.size(), 1); + for (Map item: itemsByPrice) { + assertTrue((Integer) item.get("price") <= 7000); + } + store.setPrice(12000); + itemsByPrice = store.getItemsByPrice(); + assertEquals(itemsByPrice.size(), 2); + for (Map item: itemsByPrice) { + assertTrue((Integer) item.get("price") <= 12000); + } + + store.setCapacity(500); + List> itemsByCapacity = store.getItemsByCapacity(); + assertEquals(itemsByCapacity.size(), 2); + for (Map item: itemsByCapacity) { + assertTrue((Integer) item.get("capacity") >= 500); + } + store.setCapacity(1500); + itemsByCapacity = store.getItemsByCapacity(); + assertEquals(itemsByCapacity.size(), 1); + for (Map item: itemsByCapacity) { + assertTrue((Integer) item.get("capacity") >= 1500); + } + + store.addProductToSiteB(1000, 10000); + + store.setPrice(7000); + itemsByPrice = store.getItemsByPrice(); + assertEquals(itemsByPrice.size(), 1); + for (Map item: itemsByPrice) { + assertTrue((Integer) item.get("price") <= 7000); + } + store.setPrice(12000); + itemsByPrice = store.getItemsByPrice(); + assertEquals(itemsByPrice.size(), 3); + for (Map item: itemsByPrice) { + assertTrue((Integer) item.get("price") <= 12000); + } + + store.setCapacity(500); + itemsByCapacity = store.getItemsByCapacity(); + assertEquals(itemsByCapacity.size(), 3); + for (Map item: itemsByCapacity) { + assertTrue((Integer) item.get("capacity") >= 500); + } + store.setCapacity(1500); + itemsByCapacity = store.getItemsByCapacity(); + assertEquals(itemsByCapacity.size(), 1); + for (Map item: itemsByCapacity) { + assertTrue((Integer) item.get("capacity") >= 1500); + } + } + +}