java更新Map键值
好的,我有这段代码:
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;
谢谢, :)
Ok I have this code:
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;
It checks for range of date in submap. then checks if values of those dates (which are keys btw) can accomodate terminals (that is reservation number), then if yes it would subtract that from capacity currently in map. I am unsure how to update the capacity in the map for all dates between startx and endx with value
capacity -= terminals;
Thanks,
:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用更新后的值将键/值重新插入到地图中。
You have to reinsert the key / value into the map with the updated value.