Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Agriterix
simulator
Commits
c9c3f374
Commit
c9c3f374
authored
Jul 27, 2021
by
Loris Croce
Browse files
product list getters
parent
9ee26c62
Pipeline
#38377
passed with stages
in 4 minutes and 18 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/fr/inrae/agriterix/simulator/Simulator.java
View file @
c9c3f374
...
...
@@ -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
;
...
...
src/test/java/fr/inrae/agriterix/simulator/SimulatorTest.java
View file @
c9c3f374
...
...
@@ -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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment