を誤動作私はTreeMap
を持っている:のJavaのTreeMap
final Map<UserSetting, ItemsIntersectionAndComplement> _usersSimilar = new TreeMap<UserSetting, ItemsIntersectionAndComplement>(new Comparator<UserSetting>() {
@Override
public int compare(UserSetting lhs, UserSetting rhs) {
int prec = (lhs.id()).compareTo(rhs.id());
return lhs.totalMatch > rhs.totalMatch ? -1 : (lhs.totalMatch < rhs.totalMatch) ? 1 : prec;
}
});
とキーが存在天気をチェックし、それが偽の応答するが、特定のn番目の位置に私は、その項目を参照してください。どのように可能ですか?そして、以前の反復項目では、項目が追加されました。
if (!_usersSimilar.containsKey(rating2.userSetting())) { // <-- CHECKING HERE EXISTENCE
ItemsIntersectionAndComplement iiac = new ItemsIntersectionAndComplement();
iiac.intersection.add(rating2.item());
rating2.userSetting().totalMatch = 1;
_usersSimilar.put(rating2.userSetting(), iiac);
} else {
//.. SOME CODE, BUT CALL DOES NOT REACH IT
}
public class UserSetting extends _UserSetting {
public UserSetting() {
}
int totalMatch;
}
なぜ-1?合理的な質問。 –
存在を確認している場所にコメントを入れます –
マップ内の変更可能なキーはお勧めできません。 [This](http://stackoverflow.com/questions/7842049/are-mutable-hashmap-keys-a-dangerous-practice)は 'HashMap'についてですが、' TreeMap'についても同様の議論ができます。同様のケースでは、通常、 'Map'は間違ったデータ構造であり、本当に必要なのはソートされた' List'です。 – biziclop