I am trying to hash my object:
protected XMLGregorianCalendar startTime;
value of getStartTime() is 2018-06-21T12:04:10.000Z
The hashCode method at the bottom from XMLGregorianCalendar does not handle milliseconds, so I will never get a unique hashCode even when I use a startTime with different value for milliseconds like 2018-06-21T12:04:10.111Z
Both 2018-06-21T12:04:10.000Z and 2018-06-21T12:04:10.111Z result in the same hashCode unless I change the seconds, minutes, hour, etc etc. I need it to also take into account the milliseconds.
Is there a different hashCode() method that will handle this? How can I accomplish this?
public int hashCode() {
// Following two dates compare to EQUALS since in different timezones.
// 2000-01-15T12:00:00-05:00 == 2000-01-15T13:00:00-04:00
//
// Must ensure both instances generate same hashcode by normalizing
// this to UTC timezone.
int timezone = getTimezone();
if (timezone == DatatypeConstants.FIELD_UNDEFINED) {
timezone = 0;
}
XMLGregorianCalendar gc = this;
if (timezone != 0) {
gc = this.normalize();
}
return gc.getYear()
+ gc.getMonth()
+ gc.getDay()
+ gc.getHour()
+ gc.getMinute()
+ gc.getSecond(); //Where's milliseconds???
}