【发布时间】:2014-07-01 13:25:47
【问题描述】:
如何从插入到地图列表中的列表中检索值? 我有我的主要课程
public class Path {
private Map<Integer, List<Arc>> mapNode;
private final Arc arc;
public Path() {
this.arc = new Arc();
double coll[][] = {{1, 13}, {2, 21}, {21, 2}, {7, 21}, {21, 5}};
mapNode = new HashMap();
for (int i = 0; i < coll.length; i++) {
if (!mapNode.containsKey((int) coll[i][0])) {
mapNode.put((int) coll[i][0], new ArrayList());
}
Arc arc = new Arc();
arc.setOrigin((int) coll[i][0]);
arc.setDestination((int) coll[i][1]);
mapNode.get(arc.getOrigin()).add(arc);
mapNode.get(arc.getOrigin()).get(arc.getDestination()).getOccupancy().setInit(0);
}
}
}
在我的地图中,我有一个 Arc 列表。它包含出发地、目的地以及占用列表:
public class Arc {
private int origin;
private int destination;
private Occupancy occupancy;
private List <Occupancy> time_occupancy;
public Arc(){
}
public Arc(int origin, int destination){
this.origin = origin;
this.destination = destination;
}
public Occupancy getOccupancy() {
return occupancy;
}
public void setOccupancy(Occupancy occupancy) {
this.occupancy = occupancy;
}
public List<Occupancy> getTime_occupancy() {
return time_occupancy;
}
public void setTime_occupancy(List<Occupancy> time_occupancy) {
this.time_occupancy = time_occupancy;
}
public int getOrigin() {
return origin;
}
public void setOrigin(int origin) {
this.origin = origin;
}
public int getDestination() {
return destination;
}
public void setDestination(int destination) {
this.destination = destination;
}
}
Occupancy是弧线不可用的时间,它有两个变量:init和end。
class Occupancy {
double init;
double end;
public Occupancy(double init, double end){
this.init = init;
this.end = end;
}
public double getInit() {
return init;
}
public void setInit(double init) {
this.init = init;
}
public double getEnd() {
return end;
}
public void setEnd(double end) {
this.end = end;
}
}
我不能在我的入住清单中存储价值。我试过了:
mapNode.get(arc.getOrigin()).get(arc.getDestination()).getOccupancy().setInit(0);
但它不起作用。我可以在我的弧列表中获取和设置值,但我不能使用我的占用列表。
【问题讨论】:
-
例如:我有我的圆弧列表,我想存储origin=1和destination=13的arc占用时间。我想 setInit=0 和 setEnd=4。然后 setInit=5 和 setEnd=9...使用 "mapNode.get(arc.getOrigin()).get(arc.getDestination()).getOccupancy().setInit(0);"它说:java.lang.NullPointerException