다음과 같은 코드가 있습니다 :containsKey가 키를 찾지 못한 이유는 무엇입니까?
payoffs2exchanges.put(point, exchange);
if (!payoffs2exchanges.containsKey(point)) {
game.log.fine("yes");
} else {
game.log.fine("no");
}
"no"를 출력합니다. 즉, 키 - 값 쌍을 맵에 추가 한 다음 바로 그 키가 존재하는지 확인하고 존재하지 않는다는 것을 확인합니다. 왜?
여전히 키에 문제가 있습니다. 다음 코드는 키를 추가 할 때마다 새 키를 추가한다고 말합니다. 그리고 나는 그렇지 않다는 것을 안다.
Integer[] point = new Integer[2];
point[0] = proposerBestScore;
point[1] = responderBestScore;
game.log.fine("In the getCloudOfPayoffs: found payoffs:" + point[0] + "," + point[1] + ". Exchange: " + exchange[0]+","+exchange[1]+","+exchange[2]+","+exchange[3]+","+exchange[4]);
// With the following block we ensure that every options (pair of payoffs) is represented by exchange with minimal number of moves.
if (!payoffs2exchanges.containsKey(point)) {
payoffs2exchanges.put(point, exchange);
game.log.fine("In the getCloudOfPayoffs: this option is new. We add it to the map.");
} else {
game.log.fine("In the getCloudOfPayoffs: this option is old.");
Integer[] exchangeFromMap = payoffs2exchanges.get(point);
Integer newSum = 0;
Integer oldSum = 0;
for (int i=0;i<Design.nColors;i++) {
newSum = newSum + Math.abs(exchange[i]);
oldSum = oldSum + Math.abs(exchangeFromMap[i]);
}
if (newSum<oldSum) {
game.log.fine("In the getCloudOfPayoffs: the new exchange is better than the old one.");
payoffs2exchanges.put(point, exchange);
}
}
'point' 클래스는 무엇입니까? 사용자 정의 클래스? 어떤 클래스가'payoffs2exchanges'입니까? –
업데이트를 해결하는 답변이 추가되었습니다. – aioobe
@aioobe, 질문에 대한 이러한 조작에 대해 사과드립니다. 나는 그것을 돌려 놓았다. 그래서 대답은 유용합니다. – Roman