2016-09-03 26 views
1

我是java和新手的新手。我试图创建一个类型gridcell(值层单元格)的网格单元格(网格单元格)列表,但我不断收到错误“类型GridCell不是通用的;它不能用参数参数化”GridCell类型不是通用的;它不能用参数<GridCell>参数化。虽然创建一个列表

我该如何修复这个?

package tester; 

import java.util.List; 

import repast.simphony.context.Context; 
import repast.simphony.engine.environment.RunEnvironment; 
import repast.simphony.engine.schedule.ScheduledMethod; 
import repast.simphony.parameter.Parameters; 
//import repast.simphony.query.space.grid.GridCell; 
import repast.simphony.query.space.grid.GridCellNgh; 
import repast.simphony.space.grid.Grid; 
import repast.simphony.space.grid.GridPoint; 
import repast.simphony.valueLayer.AbstractGridFunction; 
import repast.simphony.valueLayer.BufferedGridValueLayer; 
import repast.simphony.valueLayer.BufferedGridValueLayer.Buffer; 
import repast.simphony.valueLayer.GridCell; 
import repast.simphony.valueLayer.MaxGridFunction; 
import repast.simphony.valueLayer.MinGridFunction; 

      private void Move() { 
       // TODO Auto-generated method stub 

       BufferedGridValueLayer heat = (BufferedGridValueLayer) context.getValueLayer("Heat Layer"); 
       Grid <Object> grid = (Grid <Object>) context.getProjection("Insulation Grid"); 

       //Get the Grid Location of this insulation unit. 
       GridPoint pt = grid.getLocation(this); 

       //Use the GridCellNgh to retrieve the list of of Gridcells (grid) contianing Gridcells (valueLayergrid). 
       GridCellNgh <GridCell> nghCreator = new GridCellNgh <GridCell> (grid, pt, GridCell.class, 1, 1); 


       List <GridCell <GridCell>> gridCells = nghCreator.getNeighborhood(true); 
      } 
+0

这个例子是否需要所有的导入,是否可以修剪? –

+0

@JamesK我只复制了一部分代码。还有其他代码需要导入才能工作。 – Tannay

+0

请参阅http://stackoverflow.com/help/mcve –

回答

1

由于Repast API中有两个GridCell类,所以存在一些混淆。

GridCellNgh.getNeighborhood(true)返回类型repast.simphony.query.space.grid.GridCell<T>这是位于特定网格位置的代理的容器。 GridCellNgh类用于根据代理类的类型检索这些类型的网格单元,并且不适用于ValueLayer repast.simphony.valueLayer.GridCell对象。

GridCellNgh可以用来获取从中通过GridCell.getPoint()你可以得到相关GridCell格点的名单,但是这是假定所有周围的网格位置都充满了传递到GridCellNgh构造代理类,这是唯一可行的时网格完全充满代理。

我建议您只是简单地使用GridPoint pt = grid.getLocation(this)来获得中心点,然后根据中心x,y在构成摩尔邻域的每个x +/- 1,y +/- 1上访问值层。

相关问题