The class below is a context builder which places Tree objects in geographic space on a grid. I have created an array list of trees objects with various suitability values and ids:
public class TreeBuilder implements ContextBuilder<Object> {
@Override
public Context build(Context<Object> context) {
context.setId("taylor");
ContinuousSpaceFactory spaceFactory =
ContinuousSpaceFactoryFinder.createContinuousSpaceFactory(null);
ContinuousSpace<Object> space =
spaceFactory.createContinuousSpace("space", context,
new RandomCartesianAdder<Object>(),
new repast.simphony.space.continuous.WrapAroundBorders(),
50, 50);
GridFactory gridFactory = GridFactoryFinder.createGridFactory(null);
Grid<Object> grid = gridFactory.createGrid("grid", context,
new GridBuilderParameters<Object>(new WrapAroundBorders(),
new SimpleGridAdder<Object>(),
true, 50, 50));
ArrayList<Tree> trees = new ArrayList<Tree>();
int treeCount = 100;
for (int i = 1; i < treeCount; i++) {
double suitability = Math.random();
int id = i;
Tree tree = new Tree(space, grid, suitability, id);
context.add(tree);
trees.add(tree);
tree.measureSuit();
}
Tree maxTree = Collections.max(trees, new SuitComp());
System.out.println(maxTree);
for (Object obj : context) {
NdPoint pt = space.getLocation(obj);
grid.moveTo(obj, (int)pt.getX(), (int)pt.getY());
}
return context;
}
}
I believe I can use a getter to access the list in other classes. Something like this...
public ArrayList<Tree> getList() {
return trees;
}
But my question is: Where do I put the code above? I get an error whenever I place it, specifically with "return trees;".
In addition: Can I also use a getter to get the maxTree value from the list?