diff --git a/src/ItemsByCapacity.java b/src/ItemsByCapacity.java index faf7f85..ea4654d 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..451d33d 100644 --- a/src/ItemsByPrice.java +++ b/src/ItemsByPrice.java @@ -1,21 +1,47 @@ -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; - } -} \ No newline at end of file + 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; + } +} +// +//import java.util.ArrayList; +//import java.util.List; +//import java.util.Map; +// +//public class ItemsByPrice { +// 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.getSiteAValue()) { +// 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..1bc24a7 100644 --- a/src/SSDStore.java +++ b/src/SSDStore.java @@ -1,40 +1,67 @@ -import java.util.*; +import java.util.List; +import java.util.Map; public class SSDStore { - private Capacity capacity; - private SiteA siteA; - private ItemsByCapacity itemsByCapacity; - private Price price; - private ItemsByPrice itemsByPrice; - public SSDStore() { - 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(); - } - public int getPrice() { - return price.getValue(); - } - public void setPrice(int cur_price) { - this.price.setPrice(cur_price); - } - public List> getItemsByPrice() { - return itemsByPrice.getValue(); - } + private Capacity capacity; + private SiteA siteA; // ���̎Q�Ƃ͕s�v�ɂȂ�”\�������� + private SiteB siteB; + private SiteWrapper siteWrapper; + private ItemsByCapacity itemsByCapacity; + private Price price; + private ItemsByPrice itemsByPrice; + + public SSDStore() { + this.capacity = new Capacity(); + this.siteA = new SiteA(); + 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); + } + + public int getCapacity() { + return capacity.getValue(); + } + + public void setCapacity(int cur_capacity) { + this.capacity.setCapacity(cur_capacity); + } + + // SiteA �̒��ړI�ȎQ�Ƃ͕s�v�ɂȂ����̂ŁA���̃��\�b�h�͍폜���邩�A�ύX���邩���������� + public List> getSiteA() { + 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) { + this.siteA.addProductToSiteA(capacity, price); + } + + public void addProductToSiteB(int capacity, int price) { + this.siteB.addProductToSiteB(capacity, price); + } + + public List> getItemsByCapacity() { + return itemsByCapacity.getValue(); + } + + public int getPrice() { + return price.getValue(); + } + + public void setPrice(int cur_price) { + this.price.setPrice(cur_price); + } + + public List> getItemsByPrice() { + return itemsByPrice.getValue(); + } } \ No newline at end of file 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 new file mode 100644 index 0000000..ee683cb --- /dev/null +++ b/src/SiteWrapper.java @@ -0,0 +1,48 @@ +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +//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; +// } +// +//} + +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; + } + + 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