< prev index next >
src/java.xml/share/classes/javax/xml/datatype/XMLGregorianCalendar.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -26,10 +26,11 @@
package javax.xml.datatype;
import javax.xml.namespace.QName;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.util.Arrays;
import java.util.TimeZone;
import java.util.GregorianCalendar;
/**
* <p>Representation for W3C XML Schema 1.0 date/time datatypes.
@@ -686,14 +687,16 @@
* returns {@link DatatypeConstants#EQUAL},
* otherwise {@code false}.
*/
@Override
public boolean equals(Object obj) {
-
if (obj == null || !(obj instanceof XMLGregorianCalendar)) {
return false;
}
+ if (obj == this) {
+ return true;
+ }
return compare((XMLGregorianCalendar) obj) == DatatypeConstants.EQUAL;
}
/**
* Returns a hash code consistent with the definition of the equals method.
@@ -714,16 +717,14 @@
}
XMLGregorianCalendar gc = this;
if (timezone != 0) {
gc = this.normalize();
}
- return gc.getYear()
- + gc.getMonth()
- + gc.getDay()
- + gc.getHour()
- + gc.getMinute()
- + gc.getSecond();
+
+ int[] elements = {gc.getYear(), gc.getMonth(), gc.getDay(), gc.getHour(),
+ gc.getMinute(), gc.getSecond(), gc.getMillisecond()};
+ return Arrays.hashCode(elements);
}
/**
* Return the lexical representation of {@code this} instance.
* The format is specified in
< prev index next >