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