]> granicus.if.org Git - icu/commitdiff
ICU-20133 Undeprecate Transliterator.Position#hashCode (#119)
authorgvictor <35373048+gvictor@users.noreply.github.com>
Tue, 18 Sep 2018 15:54:41 +0000 (16:54 +0100)
committerShane Carr <shane@unicode.org>
Thu, 27 Sep 2018 21:27:40 +0000 (14:27 -0700)
Create a preper hash code with Objects.hash instead of returning 42

icu4j/main/classes/translit/src/com/ibm/icu/text/Transliterator.java
icu4j/main/tests/translit/src/com/ibm/icu/dev/test/translit/TransliteratorTest.java

index da25f9b9e118e1c7a60f623bc1ed24fa1227d8b0..3d7a7e75316f5a6d897866f990aac79955becd98 100644 (file)
@@ -17,6 +17,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.MissingResourceException;
+import java.util.Objects;
 
 import com.ibm.icu.impl.ICUData;
 import com.ibm.icu.impl.ICUResourceBundle;
@@ -372,16 +373,11 @@ public abstract class Transliterator implements StringTransform  {
         }
 
         /**
-         * Mock implementation of hashCode(). This implementation always returns a constant
-         * value. When Java assertion is enabled, this method triggers an assertion failure.
-         * @internal
-         * @deprecated This API is ICU internal only.
+         * @draft ICU 63
          */
         @Override
-        @Deprecated
         public int hashCode() {
-            assert false : "hashCode not designed";
-            return 42;
+            return Objects.hash(contextStart, contextLimit, start, limit);
         }
 
         /**
index db20f6ea409595a6a6298869535431e8820ee334..86ee5e24698a9023340b1ee716a22dbfecfa24c9 100644 (file)
@@ -3949,4 +3949,18 @@ the ::BEGIN/::END stuff)
             "exception for a rule of '\\'");
         }
     }
+
+    /**
+     * Tests equals and hashCode implementation of Transliterator.Position
+     */
+    @Test
+    public void TestPositionEquals() {
+        Transliterator.Position position1 = new Transliterator.Position(1, 0, 0, 0);
+        Transliterator.Position position2 = new Transliterator.Position(0, 0, 0, 0);
+        assertNotEquals("2 different positions are not equal", position1, position2);
+        assertNotEquals("2 different positions have different hash codes", position1.hashCode(), position2.hashCode());
+        Transliterator.Position position3 = new Transliterator.Position(1, 0, 0, 0);
+        assertEquals("2 positions are equal", position1, position3);
+        assertEquals("2 positions have the same hash codes", position1.hashCode(), position3.hashCode());
+    }
 }