6

好的,我有这个代码:

TreeMap<DateTime, Integer> tree2 = getDatesTreeMap();
DateTime startx = new DateTime(startDate.getTime());
DateTime endx = new DateTime(endDate.getTime());
boolean possible = false;
int testValue = 0;
//produces submap
Map<DateTime, Integer> nav = tree2.subMap(startx, endx);

for (Integer capacity : tree2.subMap(startx, endx).values()) {
    //Provides an insight into capacity accomodation possibility
    //testValue++;
    terminals = 20;
    if(capacity >= terminals)
        possible = true;
    else if(capacity < terminals)
        possible = false;

}

if(possible == true)
{
    for (Integer capacity : tree2.subMap(startx, endx).values()) {
    {
        capacity -= terminals;
        //not sure what to do
    }
}
}else{

}

return possible;

它检查子图中的日期范围。然后检查这些日期的值(顺便说一句)是否可以容纳终端(即预订号),如果是,它将从地图中当前的容量中减去。我不确定如何使用值更新 startx 和 endx 之间所有日期的地图容量

capacity -= terminals;

谢谢, :)

4

1 回答 1

10

您必须使用更新的值将键/值重新插入到地图中。

tree2.put(key, tree2.get(key) - terminals);
于 2011-11-18T10:36:58.500 回答