diff --git a/src/SSDStore.java b/src/SSDStore.java index e1409d6..1bc24a7 100644 --- a/src/SSDStore.java +++ b/src/SSDStore.java @@ -4,6 +4,7 @@ public class SSDStore { private Capacity capacity; private SiteA siteA; // ���̎Q�Ƃ͕s�v�ɂȂ�”\�������� + private SiteB siteB; private SiteWrapper siteWrapper; private ItemsByCapacity itemsByCapacity; private Price price; @@ -12,8 +13,10 @@ public SSDStore() { this.capacity = new Capacity(); this.siteA = new SiteA(); - this.siteWrapper = new SiteWrapper(); - this.siteWrapper.addSite(this.siteA); // SiteA �I�u�W�F�N�g��lj� + this.siteB = new SiteB(); + //this.siteWrapper = new SiteWrapper(); + this.siteWrapper = new SiteWrapper(siteA, siteB); + //this.siteWrapper.addSite(this.siteA); // SiteA �I�u�W�F�N�g��lj� this.itemsByCapacity = new ItemsByCapacity(capacity, siteWrapper); this.price = new Price(); this.itemsByPrice = new ItemsByPrice(price, siteWrapper); @@ -32,11 +35,18 @@ return siteA.getValue(); } +// public void addProductToSiteA(int capacity, int price) { +// List siteAList = this.siteWrapper.getSites(); +// if (!siteAList.isEmpty()) { +// siteAList.get(0).addProductToSiteA(capacity, price); // �ŏ��� SiteA �I�u�W�F�N�g�ɐ��i��lj� +// } +// } public void addProductToSiteA(int capacity, int price) { - List siteAList = this.siteWrapper.getSites(); - if (!siteAList.isEmpty()) { - siteAList.get(0).addProductToSiteA(capacity, price); // �ŏ��� SiteA �I�u�W�F�N�g�ɐ��i��lj� - } + this.siteA.addProductToSiteA(capacity, price); + } + + public void addProductToSiteB(int capacity, int price) { + this.siteB.addProductToSiteB(capacity, price); } public List> getItemsByCapacity() { diff --git a/src/SiteB.java b/src/SiteB.java new file mode 100644 index 0000000..3837a7c --- /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 product = new HashMap<>(); + product.put("price", price); + product.put("capacity", capacity); + this.value.add(product); + } +} \ No newline at end of file diff --git a/src/SiteWrapper.java b/src/SiteWrapper.java index 027d0e8..ee683cb 100644 --- a/src/SiteWrapper.java +++ b/src/SiteWrapper.java @@ -2,24 +2,47 @@ import java.util.List; import java.util.Map; -public class SiteWrapper { - private List sites = new ArrayList<>(); - - public void addSite(SiteA site) { - sites.add(site); - } +//public class SiteWrapper { +// private List sites = new ArrayList<>(); +// +// public void addSite(SiteA site) { +// sites.add(site); +// } +// +// // ���݂� SiteA �I�u�W�F�N�g�̃��X�g��Ԃ����\�b�h +// public List getSites() { +// return this.sites; +// } +// +// public List> getSiteValue() { +// List> combinedList = new ArrayList<>(); +// for (SiteA site : sites) { +// combinedList.addAll(site.getValue()); +// } +// return combinedList; +// } +// +//} - // ���݂� SiteA �I�u�W�F�N�g�̃��X�g��Ԃ����\�b�h +public class SiteWrapper { + private SiteA siteA; + private SiteB siteB; + private List sites = new ArrayList<>(); + + public SiteWrapper(SiteA siteA, SiteB siteB) { + this.siteA = siteA; + this.siteB = siteB; + } + + + // ���݂� SiteA �I�u�W�F�N�g�̃��X�g��Ԃ����\�b�h public List getSites() { - return this.sites; + return this.sites; } public List> getSiteValue() { - List> combinedList = new ArrayList<>(); - for (SiteA site : sites) { - combinedList.addAll(site.getValue()); - } - return combinedList; + 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