]> granicus.if.org Git - icu/commitdiff
ICU-8745 docs & comments from code review
authorMarkus Scherer <markus.icu@gmail.com>
Tue, 16 Aug 2011 23:04:09 +0000 (23:04 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Tue, 16 Aug 2011 23:04:09 +0000 (23:04 +0000)
X-SVN-Rev: 30533

icu4j/demos/src/com/ibm/icu/dev/demo/messagepattern/MessagePatternUtilDemo.java
icu4j/main/classes/core/src/com/ibm/icu/text/MessagePatternUtil.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/MessagePatternUtilTest.java

index 47d41b49cfc1824c3b4b00dc70463a5e922b4527..2de520c423fe6ef4faaf627a27dfa5aa3677615d 100644 (file)
@@ -11,6 +11,7 @@ package com.ibm.icu.dev.demo.messagepattern;
 
 import com.ibm.icu.text.MessagePattern;
 import com.ibm.icu.text.MessagePatternUtil;
+import com.ibm.icu.text.MessagePatternUtil.VariantNode;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -73,7 +74,8 @@ public class MessagePatternUtilDemo {
             double value;
             switch (argType) {
             case CHOICE:
-                System.out.println(indent + variant.getSelectorValue() + " " + variant.getSelector() + ":");
+                System.out.println(indent + variant.getSelectorValue() + " " +
+                                   variant.getSelector() + ":");
                 break;
             case PLURAL:
                 value = variant.getSelectorValue();
@@ -189,7 +191,8 @@ public class MessagePatternUtilDemo {
         if (!keywordVariants.isEmpty()) {
             System.out.println(manySpaces.substring(0, depth * 2) +
                                "_keyword = PluralRules.select(" + pluralNumber + ")");
-            genCodeForKeywordVariants(keywordVariants, depth++, firstResult, "_keyword", pluralNumber);
+            genCodeForKeywordVariants(keywordVariants, depth++, firstResult,
+                                      "_keyword", pluralNumber);
         }
         genCode(otherVariant.getMessage(), depth, firstResult, pluralNumber);
         if (origDepth < depth) {
@@ -216,7 +219,7 @@ public class MessagePatternUtilDemo {
         }
     }
 
-    private static final void genCodeForNumericVariants(List<MessagePatternUtil.VariantNode> variants,
+    private static final void genCodeForNumericVariants(List<VariantNode> variants,
                                                         int depth,
                                                         boolean firstResult,
                                                         String varName,
@@ -234,7 +237,7 @@ public class MessagePatternUtilDemo {
         System.out.println(indent + "} else {");
     }
 
-    private static final void genCodeForKeywordVariants(List<MessagePatternUtil.VariantNode> variants,
+    private static final void genCodeForKeywordVariants(List<VariantNode> variants,
                                                         int depth,
                                                         boolean firstResult,
                                                         String varName,
@@ -334,9 +337,10 @@ public class MessagePatternUtilDemo {
         msg="_'__{gender, select, female{Her n'ame is {person_name}.}"+
                                  "other{His n'ame is {person_name}.}}__'_";
         print(msg);
-        print("{num,plural,offset:1 =0{no one} =1{one, that is one and # others} " +
-                                   "one{one and # (probably 1) others} few{one and # others} " +
-                                   "other{lots & lots}}");
+        print("{num,plural,offset:1 " +
+                "=0{no one} =1{one, that is one and # others} " +
+                "one{one and # (probably 1) others} few{one and # others} " +
+                "other{lots & lots}}");
         print(
             "{p1_gender,select," +
               "female{" +
index 880f8264ae0118e150b06c209d2419c28406991a..03180cc466598df7b6391237da87c00bf40c0dcd 100644 (file)
@@ -20,6 +20,9 @@ import java.util.List;
  * Intended for use in tools when convenience is more important than
  * minimizing runtime and object creations.
  *
+ * <p>This class only has static methods.
+ * Each of the nested classes is immutable and thread-safe.
+ *
  * <p>This class and its nested classes are not intended for public subclassing.
  * @draft ICU 49
  * @provisional This API might change or be removed in a future release.
@@ -62,6 +65,7 @@ public final class MessagePatternUtil {
     /**
      * Common base class for all elements in a tree of nodes
      * returned by {@link MessagePatternUtil#buildMessageNode(MessagePattern)}.
+     * This class and all subclasses are immutable and thread-safe.
      * @draft ICU 49
      * @provisional This API might change or be removed in a future release.
      */
@@ -165,6 +169,10 @@ public final class MessagePatternUtil {
          */
         @Override
         public String toString() {
+            // Note: There is no specific subclass for REPLACE_NUMBER
+            // because it would not provide any additional API.
+            // Therefore we have a little bit of REPLACE_NUMBER-specific code
+            // here in the contents-node base class.
             return "{REPLACE_NUMBER}";
         }
 
index 148f24dce1d1ca0835ebcae088255865c62ffb4f..b798b60d58c9bcdde73d93c1e80625e13316eed3 100644 (file)
@@ -15,11 +15,11 @@ import java.util.List;
 
 import com.ibm.icu.text.MessagePattern;
 import com.ibm.icu.text.MessagePatternUtil;
-import com.ibm.icu.text.MessagePatternUtil.MessageNode;
-import com.ibm.icu.text.MessagePatternUtil.MessageContentsNode;
-import com.ibm.icu.text.MessagePatternUtil.TextNode;
 import com.ibm.icu.text.MessagePatternUtil.ArgNode;
 import com.ibm.icu.text.MessagePatternUtil.ComplexArgStyleNode;
+import com.ibm.icu.text.MessagePatternUtil.MessageContentsNode;
+import com.ibm.icu.text.MessagePatternUtil.MessageNode;
+import com.ibm.icu.text.MessagePatternUtil.TextNode;
 import com.ibm.icu.text.MessagePatternUtil.VariantNode;
 
 /**
@@ -379,6 +379,19 @@ public final class MessagePatternUtilTest extends com.ibm.icu.dev.test.TestFmwk
                 finishComplexArg().
             expectTextThatContains("_z");
         expect.checkMatches(msg);
+        // Plural with explicit offset:0.
+        msg = MessagePatternUtil.buildMessageNode(
+                "a_{0,plural,offset:0 other{num=#!}}_z");
+        expect = new ExpectMessageNode().
+            expectTextThatContains("a_").
+            expectPluralArg(0).
+                expectOffset(0).
+                expectVariant("other").
+                    expectTextThatContains("num=").expectReplaceNumber().
+                    expectTextThatContains("!").finishVariant().
+                finishComplexArg().
+            expectTextThatContains("_z");
+        expect.checkMatches(msg);
     }
 
     public void TestChoiceArg() {