diff --git a/src/ItemsByCapacity.java b/src/ItemsByCapacity.java index faf7f85..dcc971f 100644 --- a/src/ItemsByCapacity.java +++ b/src/ItemsByCapacity.java @@ -1,21 +1,23 @@ -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; public class ItemsByCapacity { - private Capacity capacity; - private SiteA siteA; - public ItemsByCapacity(Capacity capacity, SiteA siteA) { - this.capacity = capacity; - this.siteA = siteA; - } - public List> getValue() { - List> temp_l1 = new ArrayList<>(); - { - for (Map item: this.siteA.getValue()) { - if ((Integer) item.get("capacity") >= this.capacity.getValue()) { - temp_l1.add(item); - } - } - } - return temp_l1; - } + private Capacity capacity; + private SiteWrapper siteWrapper; + + public ItemsByCapacity(Capacity capacity, SiteWrapper siteWrapper) { + this.capacity = capacity; + this.siteWrapper = siteWrapper; + } + + public List> getValue() { + List> temp_l1 = new ArrayList<>(); + for (Map item: this.siteWrapper.getSiteValue()) { + if ((Integer) item.get("capacity") >= this.capacity.getValue()) { + temp_l1.add(item); + } + } + return temp_l1; + } } \ No newline at end of file diff --git a/src/ItemsByPrice.java b/src/ItemsByPrice.java index cf04438..d2e5f27 100644 --- a/src/ItemsByPrice.java +++ b/src/ItemsByPrice.java @@ -1,21 +1,23 @@ -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; public class ItemsByPrice { - private Price price; - private SiteA siteA; - public ItemsByPrice(Price price, SiteA siteA) { - this.price = price; - this.siteA = siteA; - } - public List> getValue() { - List> temp_l1 = new ArrayList<>(); - { - for (Map item: this.siteA.getValue()) { - if ((Integer) item.get("price") <= this.price.getValue()) { - temp_l1.add(item); - } - } - } - return temp_l1; - } + private Price price; + private SiteWrapper siteWrapper; + + public ItemsByPrice(Price price, SiteWrapper siteWrapper) { + this.price = price; + this.siteWrapper = siteWrapper; + } + + public List> getValue() { + List> temp_l1 = new ArrayList<>(); + for (Map item: this.siteWrapper.getSiteValue()) { + if ((Integer) item.get("price") <= this.price.getValue()) { + temp_l1.add(item); + } + } + return temp_l1; + } } \ No newline at end of file diff --git a/src/SSDStore.java b/src/SSDStore.java index 692304d..fae3f4d 100644 --- a/src/SSDStore.java +++ b/src/SSDStore.java @@ -1,40 +1,53 @@ -import java.util.*; +import java.util.List; +import java.util.Map; 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.siteWrapper = new SiteWrapper(siteA); + 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> getItemsByCapacity() { + return itemsByCapacity.getValue(); } public List> getItemsByPrice() { return itemsByPrice.getValue(); } -} \ No newline at end of file + 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 List> getSiteB() { + return siteB.getValue(); + } + + public void addProductToSiteB(int capacity, int price) { + this.siteB.addProductToSiteB(capacity, price); + } +} diff --git a/src/SiteA.java b/src/SiteA.java index 60d7574..aa285d9 100644 --- a/src/SiteA.java +++ b/src/SiteA.java @@ -1,4 +1,7 @@ -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class SiteA { private List> value = new ArrayList<>(); diff --git a/src/SiteB.java b/src/SiteB.java new file mode 100644 index 0000000..e762653 --- /dev/null +++ b/src/SiteB.java @@ -0,0 +1,19 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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..d5c7177 --- /dev/null +++ b/src/SiteWrapper.java @@ -0,0 +1,19 @@ +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +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 = new ArrayList<>(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..5580b34 --- /dev/null +++ b/src/TestMultiSSDStoreUpdate.java @@ -0,0 +1,76 @@ +import static org.junit.Assert.*; + +import java.util.List; +import java.util.Map; + +import org.junit.Test; + +public class TestMultiSSDStoreUpdate { + + @Test + public void test() { + // ���i��1�‚��ƒT�C�gA�ƃT�C�gB�ɓo�^���� + SSDStore store = new SSDStore(); + store.addProductToSiteA(500, 7000); + store.addProductToSiteB(1500, 12000); + + // ���i���w�肵�Č������� + 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); + } + + // �e�ʂ��w�肵�Č������� + 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); + } + + // ���i��1�ƒT�C�gB�ɒlj����� + store.addProductToSiteB(1000, 10000); + + // ���i���w�肵�Č������� + 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); + } + + // �e�ʂ��w�肵�Č������� + 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); + } + } +} \ No newline at end of file