3
好吧,我有这样的代码:更新地图键的值的java
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;
它检查日期子图的范围内。然后检查这些日期的值(这是关键btw)是否可以容纳终端(即预留号码),如果是,则会从当前在地图上的容量中减去该值。我不能确定如何与值更新运行startx和endx之间的所有日期在地图容量
capacity -= terminals;
谢谢, :)
如何在这种情况下访问密钥?因为我的所有密钥都是DateTime类型...任何提示? –
不要遍历这些值,而是循环遍历子映射的键。 (从关键到价值很容易。) – aioobe
@sys_debug'tree2.subMap(startx,endx).keySet()'? – Thomas