아래 클래스는 Tree 객체를 그리드의 지리적 공간에 배치하는 컨텍스트 빌더입니다.게터 기능은 어디에 두어야합니까?
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;
}
}
내가 다른 클래스의 목록에 액세스 할 게터를 사용할 수 있다고 생각 : 나는 나무의 배열리스트가 다양한 적합성 값과 ID를 가진 개체를 만들었습니다. 이게 뭔가 ...
public ArrayList<Tree> getList() {
return trees;
}
하지만 내 질문은 위의 코드를 어디에 넣어야합니까? 나는 그것을 놓을 때마다, 특히 "돌아 오는 나무들"과 함께 오류가 발생합니다.
추가 정보 : getter를 사용하여 목록에서 maxTree 값을 가져올 수 있습니까?
일반적으로'getters'는 ** class ** (지역 변수가 아님) 변수에 사용됩니다. –