Allow very large maximumIntegerDigits.

This allows up to 2 billion to be used as the maximum integer digits,
while keeping the default value at the current 309. This change brings
ICU4J in line with ICU4C limits, which is necessary for correct
implementation of java.text.DecimalFormat on ICU4J.

Bug: 27855939

(cherry picked from commit 86b7d2d760b249da7417f90f09796f3227491aba)

Change-Id: Ic054c0d34e008f7b2ea6a29e6b3d891ecc53d65b
diff --git a/android_icu4j/src/main/java/android/icu/text/DecimalFormat.java b/android_icu4j/src/main/java/android/icu/text/DecimalFormat.java
index 1cebe44..6dc95d1 100644
--- a/android_icu4j/src/main/java/android/icu/text/DecimalFormat.java
+++ b/android_icu4j/src/main/java/android/icu/text/DecimalFormat.java
@@ -5152,13 +5152,14 @@
 
     /**
      * Sets the maximum number of digits allowed in the integer portion of a number. This
-     * override limits the integer digit count to 309.
+     * override limits the integer digit count to 2,000,000,000 to match ICU4C.
      *
      * @see NumberFormat#setMaximumIntegerDigits
      */
     @Override
     public void setMaximumIntegerDigits(int newValue) {
-        super.setMaximumIntegerDigits(Math.min(newValue, DOUBLE_INTEGER_DIGITS));
+        // Android changed: Allow 2 billion integer digits.
+        super.setMaximumIntegerDigits(Math.min(newValue, MAX_INTEGER_DIGITS));
     }
 
     /**
@@ -5447,11 +5448,12 @@
         // InvalidObjectException("Digit count out of range"); }
 
 
-        // Truncate the maximumIntegerDigits to DOUBLE_INTEGER_DIGITS and
+        // Android changed: Allow 2 billion integer digits.
+        // Truncate the maximumIntegerDigits to MAX_INTEGER_DIGITS and
         // maximumFractionDigits to DOUBLE_FRACTION_DIGITS
 
-        if (getMaximumIntegerDigits() > DOUBLE_INTEGER_DIGITS) {
-            setMaximumIntegerDigits(DOUBLE_INTEGER_DIGITS);
+        if (getMaximumIntegerDigits() > MAX_INTEGER_DIGITS) {
+            setMaximumIntegerDigits(MAX_INTEGER_DIGITS);
         }
         if (getMaximumFractionDigits() > DOUBLE_FRACTION_DIGITS) {
             _setMaximumFractionDigits(DOUBLE_FRACTION_DIGITS);
@@ -5904,6 +5906,11 @@
      * Upper limit on integer and fraction digits for a Java double [Richard/GCL]
      */
     static final int DOUBLE_INTEGER_DIGITS = 309;
+    // Android changed: Allow 2 billion integer digits.
+    // This change is necessary to stay feature-compatible in java.text.DecimalFormat which
+    // used to be implemented using ICU4C (which has a 2 billion integer digits limit) and
+    // is now implemented based on this class.
+    static final int MAX_INTEGER_DIGITS = 2000000000;
     static final int DOUBLE_FRACTION_DIGITS = 340;
 
     /**
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java
index 982bd35..d50ab20 100644
--- a/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java
+++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java
@@ -5223,14 +5223,15 @@
 
     /**
      * Sets the maximum number of digits allowed in the integer portion of a number. This
-     * override limits the integer digit count to 309.
+     * override limits the integer digit count to 2,000,000,000 to match ICU4C.
      *
      * @see NumberFormat#setMaximumIntegerDigits
      * @stable ICU 2.0
      */
     @Override
     public void setMaximumIntegerDigits(int newValue) {
-        super.setMaximumIntegerDigits(Math.min(newValue, DOUBLE_INTEGER_DIGITS));
+        // Android changed: Allow 2 billion integer digits.
+        super.setMaximumIntegerDigits(Math.min(newValue, MAX_INTEGER_DIGITS));
     }
 
     /**
@@ -5534,11 +5535,12 @@
         // InvalidObjectException("Digit count out of range"); }
 
 
-        // Truncate the maximumIntegerDigits to DOUBLE_INTEGER_DIGITS and
+        // Android changed: Allow 2 billion integer digits.
+        // Truncate the maximumIntegerDigits to MAX_INTEGER_DIGITS and
         // maximumFractionDigits to DOUBLE_FRACTION_DIGITS
 
-        if (getMaximumIntegerDigits() > DOUBLE_INTEGER_DIGITS) {
-            setMaximumIntegerDigits(DOUBLE_INTEGER_DIGITS);
+        if (getMaximumIntegerDigits() > MAX_INTEGER_DIGITS) {
+            setMaximumIntegerDigits(MAX_INTEGER_DIGITS);
         }
         if (getMaximumFractionDigits() > DOUBLE_FRACTION_DIGITS) {
             _setMaximumFractionDigits(DOUBLE_FRACTION_DIGITS);
@@ -6009,6 +6011,11 @@
      * Upper limit on integer and fraction digits for a Java double [Richard/GCL]
      */
     static final int DOUBLE_INTEGER_DIGITS = 309;
+    // Android changed: Allow 2 billion integer digits.
+    // This change is necessary to stay feature-compatible in java.text.DecimalFormat which
+    // used to be implemented using ICU4C (which has a 2 billion integer digits limit) and
+    // is now implemented based on this class.
+    static final int MAX_INTEGER_DIGITS = 2000000000;
     static final int DOUBLE_FRACTION_DIGITS = 340;
 
     /**