Commit c9c3f374 authored by Loris Croce's avatar Loris Croce
Browse files

product list getters

parent 9ee26c62
Pipeline #38377 passed with stages
in 4 minutes and 18 seconds
......@@ -46,7 +46,7 @@ public class Simulator {
this.dynamicsList = parameters.getDynamics();
this.initIgnoredFields();
for (Dynamics dynamics : dynamicsList) {
dynamics.setTimeStamp(timestamp);
dynamics.setTimeStamp(timestamp);
}
this.global = createGlobal();
}
......@@ -151,6 +151,77 @@ public class Simulator {
}
}
/**
* Get all current products in the simulator
*
* @return ArrayList<Product> of products
*/
public List<Product> getProducts() {
Set<Product> products = new HashSet<Product>();
for (Farmer farmer : farmers) {
for (Patch patch : farmer.getFarm().getPatches()) {
products.add(patch.getProduction().getProduct());
}
}
for (GeoArea geoArea : geoAreas) {
if (geoArea.getFlows() != null) {
for (Flow flow : geoArea.getFlows()) {
for (Product output : flow.getOutputs()) {
products.add(output);
}
}
}
for (Patch patch : geoArea.getPatches()) {
products.add(patch.getProduction().getProduct());
}
if (farmers != null) {
for (Farmer farmer : farmers) {
products.addAll(farmer.getFarm().getLivestock().getRatio().getProduced().keySet());
}
}
}
return new ArrayList<>(products);
}
/**
* Get all current crops in the simulator
*
* @return ArrayList<Product> of products
*/
public List<Product> getCrops() {
Set<Product> products = new HashSet<Product>();
for (Farmer farmer : farmers) {
for (Patch patch : farmer.getFarm().getPatches()) {
products.add(patch.getProduction().getProduct());
}
}
return new ArrayList<>(products);
}
/**
* Get all current transformed products in the simulator
*
* @return ArrayList<Product> of products
*/
public List<Product> getTransformedProducts() {
Set<Product> products = new HashSet<Product>();
for (GeoArea geoArea : geoAreas) {
if (geoArea.getFlows() != null) {
for (Flow flow : geoArea.getFlows()) {
for (Product output : flow.getOutputs()) {
products.add(output);
}
}
}
if (farmers != null) {
for (Farmer farmer : farmers) {
products.addAll(farmer.getFarm().getLivestock().getRatio().getProduced().keySet());
}
}
}
return new ArrayList<>(products);
}
public List<Farmer> getFarmers() {
return farmers;
}
......@@ -158,7 +229,7 @@ public class Simulator {
public List<GeoArea> geoAreas() {
return geoAreas;
}
public Flow getGlobal() {
return global;
}
......@@ -198,7 +269,6 @@ public class Simulator {
return context;
}
public void patchesCBOR() throws IOException, CborException {
CborBuilder cborBuilder = new CborBuilder();
ArrayBuilder arrayBuilder;
......
......@@ -201,7 +201,15 @@ public class SimulatorTest {
}
}
@Test
@Test
public void getListProducts() throws FileNotFoundException {
Simulator simulator = Simulator.loadSimulator(new FileInputStream(directory + "simulator.xml"));
simulator.getProducts();
simulator.getTransformedProducts();
simulator.getCrops();
}
@Test
public void createTransMatrix() throws IOException {
// for test minimal
XStream xStream = new XStream();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment