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..f39dac7 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..9eb4f8e 100644 --- a/src/SSDStore.java +++ b/src/SSDStore.java @@ -1,17 +1,21 @@ -import java.util.*; +import java.util.List; +import java.util.Map; public class SSDStore { private Capacity capacity; private SiteA siteA; + private SiteWrapper siteWrapper; 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.siteWrapper = new SiteWrapper(); + this.siteWrapper.addSite(new SiteA()); + this.itemsByCapacity = new ItemsByCapacity(capacity, siteWrapper); this.price = new Price(); - this.itemsByPrice = new ItemsByPrice(price, siteA); + this.itemsByPrice = new ItemsByPrice(price, siteWrapper); } public int getCapacity() { return capacity.getValue(); diff --git a/src/SiteWrapper.java b/src/SiteWrapper.java new file mode 100644 index 0000000..2b6cbda --- /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 List sites = new ArrayList<>(); + + public void addSite(SiteA site) { + sites.add(site); + } + + public List> getSiteValue() { + List> combinedList = new ArrayList<>(); + for (SiteA site : sites) { + combinedList.addAll(site.getValue()); + } + return combinedList; + } +} \ No newline at end of file