diff --git a/src/ItemsByCapacity.java b/src/ItemsByCapacity.java index faf7f85..1bde0ac 100644 --- a/src/ItemsByCapacity.java +++ b/src/ItemsByCapacity.java @@ -2,15 +2,15 @@ public class ItemsByCapacity { private Capacity capacity; - private SiteA siteA; - public ItemsByCapacity(Capacity capacity, SiteA siteA) { + private SiteWrapper siteWrapper; + public ItemsByCapacity(Capacity capacity, SiteWrapper siteWrapper) { this.capacity = capacity; - this.siteA = siteA; + this.siteWrapper = siteWrapper; } public List> getValue() { List> temp_l1 = new ArrayList<>(); { - for (Map item: this.siteA.getValue()) { + 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 cf04438..de59ea6 100644 --- a/src/ItemsByPrice.java +++ b/src/ItemsByPrice.java @@ -2,15 +2,15 @@ public class ItemsByPrice { private Price price; - private SiteA siteA; - public ItemsByPrice(Price price, SiteA siteA) { + private SiteWrapper siteWrapper; + public ItemsByPrice(Price price, SiteWrapper siteWrapper) { this.price = price; - this.siteA = siteA; + this.siteWrapper = siteWrapper; } public List> getValue() { List> temp_l1 = new ArrayList<>(); { - for (Map item: this.siteA.getValue()) { + 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 692304d..2836b8c 100644 --- a/src/SSDStore.java +++ b/src/SSDStore.java @@ -1,40 +1,50 @@ import java.util.*; public class SSDStore { + private Price price; private Capacity capacity; private SiteA siteA; + private SiteB siteB; + private SiteWrapper siteWrapper; private ItemsByCapacity itemsByCapacity; - private Price price; private ItemsByPrice itemsByPrice; public SSDStore() { + this.price = new Price(); this.capacity = new Capacity(); this.siteA = new SiteA(); - this.itemsByCapacity = new ItemsByCapacity(capacity, siteA); - this.price = new Price(); - this.itemsByPrice = new ItemsByPrice(price, siteA); - } - public int getCapacity() { - return capacity.getValue(); - } - public void setCapacity(int cur_capacity) { - this.capacity.setCapacity(cur_capacity); - } - public List> getSiteA() { - return siteA.getValue(); - } - public void addProductToSiteA(int capacity, int price) { - this.siteA.addProductToSiteA(capacity, price); - } - public List> getItemsByCapacity() { - return itemsByCapacity.getValue(); + this.siteB = new SiteB(); + this.siteWrapper = new SiteWrapper(siteA, siteB); + this.itemsByCapacity = new ItemsByCapacity(capacity, siteWrapper); + this.itemsByPrice = new ItemsByPrice(price, siteWrapper); } public int getPrice() { return price.getValue(); } - public void setPrice(int cur_price) { - this.price.setPrice(cur_price); + public int getCapacity() { + return capacity.getValue(); + } + public List> getSiteA() { + return siteA.getValue(); + } + public List> getSiteB() { + return siteB.getValue(); + } + public List> getItemsByCapacity() { + return itemsByCapacity.getValue(); } public List> getItemsByPrice() { return itemsByPrice.getValue(); } + public void setCapacity(int cur_capacity) { + this.capacity.setCapacity(cur_capacity); + } + public void setPrice(int cur_price) { + this.price.setPrice(cur_price); + } + 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 new file mode 100644 index 0000000..a630d21 --- /dev/null +++ b/src/SiteWrapper.java @@ -0,0 +1,15 @@ +import java.util.*; + +public class SiteWrapper { + private SiteA siteA; + private SiteB siteB; + public SiteWrapper(SiteA siteA, SiteB siteB) { + this.siteA = siteA; + this.siteB = siteB; + } + 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); + } + } + +}