I have a 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;
}
});
And when checking wether key exist, it respond false, but at a specific nth position I see that item. How is it possible? And in previous iteration item was added.
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;
}
The key you are searching for in the Map and the key you put in the Map have different state, since you are updating
rating2.userSetting().totalMatchinside your if clause.Therefore it's quite possible the key you are searching for doesn't exist in the Map but the key you are adding exists in the Map.