From: Debabrata Sengupta Date: Thu, 23 Aug 2012 20:59:35 +0000 (+0000) Subject: ICU-9476 fixed bug with numeric collation X-Git-Tag: milestone-59-0-1~3644 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=525d85dd59d18097ec102af0a45aeacf61dc649e;p=icu ICU-9476 fixed bug with numeric collation X-SVN-Rev: 32223 --- diff --git a/icu4j/main/classes/collate/src/com/ibm/icu/text/CollationElementIterator.java b/icu4j/main/classes/collate/src/com/ibm/icu/text/CollationElementIterator.java index 5d207e6534b..c6006b629ed 100644 --- a/icu4j/main/classes/collate/src/com/ibm/icu/text/CollationElementIterator.java +++ b/icu4j/main/classes/collate/src/com/ibm/icu/text/CollationElementIterator.java @@ -1,6 +1,6 @@ /** ******************************************************************************* -* Copyright (C) 1996-2011, International Business Machines Corporation and * +* Copyright (C) 1996-2012, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* * @@ -1928,6 +1928,11 @@ public final class CollationElementIterator // We drop the collation value into the buffer so if // we need to do a "front patch" we don't have to // check to see if we're hitting the last element. + + if (trailingZeroIndex != 0) { + trailingZeroIndex = 0; + } + collateVal = digVal * 10; m_utilStringBuffer_.setCharAt((digIndx >>> 1) + 2, (char)((collateVal << 1) + 6)); @@ -1973,7 +1978,8 @@ public final class CollationElementIterator } int endIndex = trailingZeroIndex != 0 ? trailingZeroIndex - : (digIndx >>> 1) + 2; + : (digIndx >>> 1) + 2; + if (digIndx % 2 != 0){ // We missed a value. Since digIndx isn't even, stuck too many // values into the buffer (this is what we get for padding the diff --git a/icu4j/main/tests/collate/src/com/ibm/icu/dev/test/collator/CollationMiscTest.java b/icu4j/main/tests/collate/src/com/ibm/icu/dev/test/collator/CollationMiscTest.java index a89731df171..69394faf2c2 100644 --- a/icu4j/main/tests/collate/src/com/ibm/icu/dev/test/collator/CollationMiscTest.java +++ b/icu4j/main/tests/collate/src/com/ibm/icu/dev/test/collator/CollationMiscTest.java @@ -1936,6 +1936,12 @@ public class CollationMiscTest extends TestFmwk { "\u0663\u0662", "\u0663\u0663" }; + + //Additional tests to cover bug reported in #9476 + String lastDigitDifferent[]={"2004","2005", + "110005", "110006", + "11005", "11006", + "100000000005","100000000006"}; // Open our collator. RuleBasedCollator coll @@ -1963,6 +1969,13 @@ public class CollationMiscTest extends TestFmwk { preZeroTestStrings[j],0); } } + + //Testing that the behavior reported in #9476 is fixed + //We expect comparisons between adjacent pairs will result in -1 + for (int i=0; i < lastDigitDifferent.length -1; i=i+2 ) { + CollationTest.doTest(this, coll, lastDigitDifferent[i], lastDigitDifferent[i+1], -1); + } + //cover setNumericCollationDefault, getNumericCollation assertTrue("The Numeric Collation setting is on", coll.getNumericCollation());