This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit 963c337d772ec4e27a4501a9dda1ffd860c59d7e
Author: Gary Gregory <[email protected]>
AuthorDate: Mon Sep 21 10:40:05 2026 -0400

    Add equality and hash code support to ImmutableTimeZone
    
    Compare wrapped time zones with other ImmutableTimeZone and TimeZone
    instances. Add tests for matching and different zones.
---
 .../commons/lang3/time/ImmutableTimeZone.java      | 23 ++++++++++++++++++++++
 .../commons/lang3/time/ImmutableTimeZoneTest.java  | 23 ++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/src/main/java/org/apache/commons/lang3/time/ImmutableTimeZone.java 
b/src/main/java/org/apache/commons/lang3/time/ImmutableTimeZone.java
index 0d09c869a..e5593f54f 100644
--- a/src/main/java/org/apache/commons/lang3/time/ImmutableTimeZone.java
+++ b/src/main/java/org/apache/commons/lang3/time/ImmutableTimeZone.java
@@ -41,6 +41,21 @@ public Object clone() {
         return this;
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof TimeZone)) {
+            return false;
+        }
+        final TimeZone other = (TimeZone) obj;
+        return timeZone.equals(other instanceof ImmutableTimeZone ? 
((ImmutableTimeZone) other).timeZone : other);
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -89,6 +104,14 @@ public int getRawOffset() {
         return timeZone.getRawOffset();
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        return timeZone.hashCode();
+    }
+
     /**
      * {@inheritDoc}
      */
diff --git 
a/src/test/java/org/apache/commons/lang3/time/ImmutableTimeZoneTest.java 
b/src/test/java/org/apache/commons/lang3/time/ImmutableTimeZoneTest.java
index 2df5a8371..933733ca0 100644
--- a/src/test/java/org/apache/commons/lang3/time/ImmutableTimeZoneTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/ImmutableTimeZoneTest.java
@@ -18,6 +18,8 @@
 package org.apache.commons.lang3.time;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -59,6 +61,20 @@ void testConstructorNullThrowsNullPointerException() {
         assertThrows(NullPointerException.class, () -> new 
ImmutableTimeZone(null));
     }
 
+    @Test
+    void testEquals() {
+        final ImmutableTimeZone anotherUtc = new ImmutableTimeZone((TimeZone) 
UTC.clone());
+        assertEquals(utcImmutable, utcImmutable);
+        assertEquals(utcImmutable, anotherUtc);
+        assertEquals(anotherUtc, utcImmutable);
+        assertNotEquals(utcImmutable, newYorkImmutable);
+        assertEquals(utcImmutable, UTC);
+        assertEquals(utcImmutable, UTC.clone());
+        assertNotEquals(utcImmutable, NEW_YORK);
+        assertFalse(utcImmutable.equals(null));
+        assertFalse(utcImmutable.equals("UTC"));
+    }
+
     @Test
     void testGetDisplayNameDelegatesToWrappedTimeZone() {
         assertEquals(UTC.getDisplayName(false, TimeZone.LONG, Locale.US), 
utcImmutable.getDisplayName(false, TimeZone.LONG, Locale.US));
@@ -97,6 +113,13 @@ void testGetRawOffsetDelegatesToWrappedTimeZone() {
         assertEquals(NEW_YORK.getRawOffset(), newYorkImmutable.getRawOffset());
     }
 
+    @Test
+    void testHashCode() {
+        final ImmutableTimeZone anotherUtc = new ImmutableTimeZone((TimeZone) 
UTC.clone());
+        assertEquals(UTC.hashCode(), utcImmutable.hashCode());
+        assertEquals(utcImmutable.hashCode(), anotherUtc.hashCode());
+    }
+
     @Test
     void testHasSameRulesDelegatesToWrappedTimeZone() {
         assertTrue(utcImmutable.hasSameRules(UTC));

Reply via email to