java - TreeMap of GregorianCalendars -


i have created treemap of <gregoriancalendar, integer> store dates in gps leap seconds introduced:

leapsecondsdict = new treemap<gregoriancalendar, integer>(); gregoriancalendar calendar =     new gregoriancalendar(timezone.gettimezone("utc"));  calendar.set(1981, gregoriancalendar.june, 30, 23, 59, 59); leapsecondsdict.put(calendar, 1); calendar.set(1982, gregoriancalendar.june, 30, 23, 59, 59); leapsecondsdict.put(calendar, 2); calendar.set(1983, gregoriancalendar.june, 30, 23, 59, 59); leapsecondsdict.put(calendar, 3); 

the problem each time call put, treemap contains last inserted element, , size stays 1.

why happening? guess when using calendar key, key class instance id , not value, when inserting second element treemap updating existing entry same key, if key same class different value.

is assumption right, or there other reason? there farcier way of achieving other creating new calendar each entry?

the set method not create new calendar, still same different value. therefore, when add map updates value same key, referencing same object. need create new instance each of keys.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -