]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - jars/icu4j-4_2_1-src/src/com/ibm/icu/impl/DateNumberFormat.java
go
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / impl / DateNumberFormat.java
old mode 100755 (executable)
new mode 100644 (file)
index 22343af..913a04c
-//##header\r
-/*\r
-*******************************************************************************\r
-*   Copyright (C) 2007-2009, International Business Machines\r
-*   Corporation and others.  All Rights Reserved.\r
-*******************************************************************************\r
-*/\r
-package com.ibm.icu.impl;\r
-\r
-import java.io.IOException;\r
-import java.io.ObjectInputStream;\r
-import java.math.BigInteger;\r
-import java.text.FieldPosition;\r
-import java.text.ParsePosition;\r
-\r
-import com.ibm.icu.lang.UCharacter;\r
-import com.ibm.icu.math.BigDecimal;\r
-import com.ibm.icu.text.NumberFormat;\r
-import com.ibm.icu.util.ULocale;\r
-import com.ibm.icu.util.UResourceBundle;\r
-\r
-/*\r
- * NumberFormat implementation dedicated/optimized for DateFormat,\r
- * used by SimpleDateFormat implementation.\r
- */\r
-public final class DateNumberFormat extends NumberFormat {\r
-\r
-    private static final long serialVersionUID = -6315692826916346953L;\r
-\r
-    private char zeroDigit;\r
-    private char minusSign;\r
-    private boolean positiveOnly = false;\r
-\r
-    private transient char[] decimalBuf = new char[20]; // 20 digits is good enough to store Long.MAX_VALUE\r
-\r
-    private static SimpleCache CACHE = new SimpleCache();\r
-\r
-    private int maxIntDigits;\r
-    private int minIntDigits;\r
\r
-    public DateNumberFormat(ULocale loc, char zeroDigitIn) {\r
-        initialize(loc,zeroDigitIn);\r
-    }\r
-\r
-/*    public DateNumberFormat(char zeroDigit, char minusSign) {\r
-        this.zeroDigit = zeroDigit;\r
-        this.minusSign = minusSign;\r
-    }\r
-*/\r
-\r
-    private void initialize(ULocale loc,char zeroDigitIn) {\r
-        char[] elems = (char[])CACHE.get(loc);\r
-        if (elems == null) {\r
-            // Missed cache\r
-            ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, loc);\r
-            String[] numberElements = rb.getStringArray("NumberElements");\r
-            elems = new char[2];\r
-            elems[0] = zeroDigitIn;\r
-            elems[1] = numberElements[6].charAt(0);\r
-            CACHE.put(loc, elems);\r
-        }\r
-        zeroDigit = elems[0];\r
-        minusSign = elems[1];\r
-    }\r
-\r
-    public void setMaximumIntegerDigits(int newValue) {\r
-        maxIntDigits = newValue;\r
-    }\r
-\r
-    public int getMaximumIntegerDigits() {\r
-        return maxIntDigits;\r
-    }\r
-\r
-    public void setMinimumIntegerDigits(int newValue) {\r
-        minIntDigits = newValue;\r
-    }\r
-\r
-    public int getMinimumIntegerDigits() {\r
-        return minIntDigits;\r
-    }\r
-\r
-    /* For supporting SimpleDateFormat.parseInt */\r
-    public void setParsePositiveOnly(boolean isPositiveOnly) {\r
-        positiveOnly = isPositiveOnly;\r
-    }\r
-\r
-    public char getZeroDigit() {\r
-        return zeroDigit;\r
-    }\r
-\r
-    public void setZeroDigit(char zero) {\r
-        zeroDigit = zero;\r
-    }\r
-\r
-    public StringBuffer format(double number, StringBuffer toAppendTo,\r
-            FieldPosition pos) {\r
-        throw new UnsupportedOperationException("StringBuffer format(double, StringBuffer, FieldPostion) is not implemented");\r
-    }\r
-\r
-    public StringBuffer format(long numberL, StringBuffer toAppendTo,\r
-            FieldPosition pos) {\r
-\r
-        if (numberL < 0) {\r
-            // negative\r
-            toAppendTo.append(minusSign);\r
-        }\r
-\r
-        // Note: NumberFormat used by DateFormat only uses int numbers.\r
-        // Remainder operation on 32bit platform using long is significantly slower\r
-        // than int.  So, this method casts long number into int.\r
-        int number = (int)numberL;\r
-\r
-        int limit = decimalBuf.length < maxIntDigits ? decimalBuf.length : maxIntDigits;\r
-        int index = limit - 1;\r
-        while (true) {\r
-            decimalBuf[index] = (char)((number % 10) + zeroDigit);\r
-            number /= 10;\r
-            if (index == 0 || number == 0) {\r
-                break;\r
-            }\r
-            index--;\r
-        }\r
-        int padding = minIntDigits - (limit - index);\r
-        for (; padding > 0; padding--) {\r
-            decimalBuf[--index] = zeroDigit;\r
-        }\r
-        int length = limit - index;\r
-        toAppendTo.append(decimalBuf, index, length);\r
-        pos.setBeginIndex(0);\r
-        if (pos.getField() == NumberFormat.INTEGER_FIELD) {\r
-            pos.setEndIndex(length);\r
-        } else {\r
-            pos.setEndIndex(0);\r
-        }\r
-        return toAppendTo;\r
-    }\r
-    \r
-    public StringBuffer format(BigInteger number, StringBuffer toAppendTo,\r
-            FieldPosition pos) {\r
-        throw new UnsupportedOperationException("StringBuffer format(BigInteger, StringBuffer, FieldPostion) is not implemented");\r
-    }\r
-\r
-//#if defined(FOUNDATION10)\r
-//#else\r
-    public StringBuffer format(java.math.BigDecimal number, StringBuffer toAppendTo,\r
-            FieldPosition pos) {\r
-        throw new UnsupportedOperationException("StringBuffer format(BigDecimal, StringBuffer, FieldPostion) is not implemented");\r
-    }\r
-//#endif\r
-\r
-    public StringBuffer format(BigDecimal number,\r
-            StringBuffer toAppendTo, FieldPosition pos) {\r
-        throw new UnsupportedOperationException("StringBuffer format(BigDecimal, StringBuffer, FieldPostion) is not implemented");\r
-    }\r
-\r
-    /*\r
-     * Note: This method only parse integer numbers which can be represented by long\r
-     */\r
-    public Number parse(String text, ParsePosition parsePosition) {\r
-        long num = 0;\r
-        boolean sawNumber = false;\r
-        boolean negative = false;\r
-        int base = parsePosition.getIndex();\r
-        int offset = 0;\r
-        for (; base + offset < text.length(); offset++) {\r
-            char ch = text.charAt(base + offset);\r
-            if (offset == 0 && ch == minusSign) {\r
-                if (positiveOnly) {\r
-                    break;\r
-                }\r
-                negative = true;\r
-            } else {\r
-                int digit = ch - zeroDigit;\r
-                if (digit < 0 || 9 < digit) {\r
-                    digit = UCharacter.digit(ch);\r
-                }\r
-                if (0 <= digit && digit <= 9) {\r
-                    sawNumber = true;\r
-                    num = num * 10 + digit;\r
-                } else {\r
-                    break;\r
-                }\r
-            }\r
-        }\r
-        Number result = null;\r
-        if (sawNumber) {\r
-            num = negative ? num * (-1) : num;\r
-            result = new Long(num);\r
-            parsePosition.setIndex(base + offset);\r
-        }\r
-        return result;\r
-    }\r
-\r
-    public boolean equals(Object obj) {\r
-        if (obj == null || !super.equals(obj) || !(obj instanceof DateNumberFormat)) {\r
-            return false;\r
-        }\r
-        DateNumberFormat other = (DateNumberFormat)obj;\r
-        return (this.maxIntDigits == other.maxIntDigits\r
-                && this.minIntDigits == other.minIntDigits\r
-                && this.zeroDigit == other.zeroDigit\r
-                && this.minusSign == other.minusSign\r
-                && this.positiveOnly == other.positiveOnly);\r
-    }\r
-\r
-    private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {\r
-        stream.defaultReadObject();\r
-        // re-allocate the work buffer\r
-        decimalBuf = new char[20];\r
-    }\r
-}\r
-\r
-//eof\r
+//##header J2SE15
+/*
+*******************************************************************************
+*   Copyright (C) 2007-2009, International Business Machines
+*   Corporation and others.  All Rights Reserved.
+*******************************************************************************
+*/
+package com.ibm.icu.impl;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.math.BigInteger;
+import java.text.FieldPosition;
+import java.text.ParsePosition;
+
+import com.ibm.icu.lang.UCharacter;
+import com.ibm.icu.math.BigDecimal;
+import com.ibm.icu.text.NumberFormat;
+import com.ibm.icu.util.ULocale;
+import com.ibm.icu.util.UResourceBundle;
+
+/*
+ * NumberFormat implementation dedicated/optimized for DateFormat,
+ * used by SimpleDateFormat implementation.
+ */
+public final class DateNumberFormat extends NumberFormat {
+
+    private static final long serialVersionUID = -6315692826916346953L;
+
+    private char zeroDigit;
+    private char minusSign;
+    private boolean positiveOnly = false;
+
+    private transient char[] decimalBuf = new char[20]; // 20 digits is good enough to store Long.MAX_VALUE
+
+    private static SimpleCache CACHE = new SimpleCache();
+
+    private int maxIntDigits;
+    private int minIntDigits;
+    public DateNumberFormat(ULocale loc, char zeroDigitIn) {
+        initialize(loc,zeroDigitIn);
+    }
+
+/*    public DateNumberFormat(char zeroDigit, char minusSign) {
+        this.zeroDigit = zeroDigit;
+        this.minusSign = minusSign;
+    }
+*/
+
+    private void initialize(ULocale loc,char zeroDigitIn) {
+        char[] elems = (char[])CACHE.get(loc);
+        if (elems == null) {
+            // Missed cache
+            ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, loc);
+            String[] numberElements = rb.getStringArray("NumberElements");
+            elems = new char[2];
+            elems[0] = zeroDigitIn;
+            elems[1] = numberElements[6].charAt(0);
+            CACHE.put(loc, elems);
+        }
+        zeroDigit = elems[0];
+        minusSign = elems[1];
+    }
+
+    public void setMaximumIntegerDigits(int newValue) {
+        maxIntDigits = newValue;
+    }
+
+    public int getMaximumIntegerDigits() {
+        return maxIntDigits;
+    }
+
+    public void setMinimumIntegerDigits(int newValue) {
+        minIntDigits = newValue;
+    }
+
+    public int getMinimumIntegerDigits() {
+        return minIntDigits;
+    }
+
+    /* For supporting SimpleDateFormat.parseInt */
+    public void setParsePositiveOnly(boolean isPositiveOnly) {
+        positiveOnly = isPositiveOnly;
+    }
+
+    public char getZeroDigit() {
+        return zeroDigit;
+    }
+
+    public void setZeroDigit(char zero) {
+        zeroDigit = zero;
+    }
+
+    public StringBuffer format(double number, StringBuffer toAppendTo,
+            FieldPosition pos) {
+        throw new UnsupportedOperationException("StringBuffer format(double, StringBuffer, FieldPostion) is not implemented");
+    }
+
+    public StringBuffer format(long numberL, StringBuffer toAppendTo,
+            FieldPosition pos) {
+
+        if (numberL < 0) {
+            // negative
+            toAppendTo.append(minusSign);
+        }
+
+        // Note: NumberFormat used by DateFormat only uses int numbers.
+        // Remainder operation on 32bit platform using long is significantly slower
+        // than int.  So, this method casts long number into int.
+        int number = (int)numberL;
+
+        int limit = decimalBuf.length < maxIntDigits ? decimalBuf.length : maxIntDigits;
+        int index = limit - 1;
+        while (true) {
+            decimalBuf[index] = (char)((number % 10) + zeroDigit);
+            number /= 10;
+            if (index == 0 || number == 0) {
+                break;
+            }
+            index--;
+        }
+        int padding = minIntDigits - (limit - index);
+        for (; padding > 0; padding--) {
+            decimalBuf[--index] = zeroDigit;
+        }
+        int length = limit - index;
+        toAppendTo.append(decimalBuf, index, length);
+        pos.setBeginIndex(0);
+        if (pos.getField() == NumberFormat.INTEGER_FIELD) {
+            pos.setEndIndex(length);
+        } else {
+            pos.setEndIndex(0);
+        }
+        return toAppendTo;
+    }
+    
+    public StringBuffer format(BigInteger number, StringBuffer toAppendTo,
+            FieldPosition pos) {
+        throw new UnsupportedOperationException("StringBuffer format(BigInteger, StringBuffer, FieldPostion) is not implemented");
+    }
+
+//#if defined(FOUNDATION10)
+//#else
+    public StringBuffer format(java.math.BigDecimal number, StringBuffer toAppendTo,
+            FieldPosition pos) {
+        throw new UnsupportedOperationException("StringBuffer format(BigDecimal, StringBuffer, FieldPostion) is not implemented");
+    }
+//#endif
+
+    public StringBuffer format(BigDecimal number,
+            StringBuffer toAppendTo, FieldPosition pos) {
+        throw new UnsupportedOperationException("StringBuffer format(BigDecimal, StringBuffer, FieldPostion) is not implemented");
+    }
+
+    /*
+     * Note: This method only parse integer numbers which can be represented by long
+     */
+    public Number parse(String text, ParsePosition parsePosition) {
+        long num = 0;
+        boolean sawNumber = false;
+        boolean negative = false;
+        int base = parsePosition.getIndex();
+        int offset = 0;
+        for (; base + offset < text.length(); offset++) {
+            char ch = text.charAt(base + offset);
+            if (offset == 0 && ch == minusSign) {
+                if (positiveOnly) {
+                    break;
+                }
+                negative = true;
+            } else {
+                int digit = ch - zeroDigit;
+                if (digit < 0 || 9 < digit) {
+                    digit = UCharacter.digit(ch);
+                }
+                if (0 <= digit && digit <= 9) {
+                    sawNumber = true;
+                    num = num * 10 + digit;
+                } else {
+                    break;
+                }
+            }
+        }
+        Number result = null;
+        if (sawNumber) {
+            num = negative ? num * (-1) : num;
+            result = new Long(num);
+            parsePosition.setIndex(base + offset);
+        }
+        return result;
+    }
+
+    public boolean equals(Object obj) {
+        if (obj == null || !super.equals(obj) || !(obj instanceof DateNumberFormat)) {
+            return false;
+        }
+        DateNumberFormat other = (DateNumberFormat)obj;
+        return (this.maxIntDigits == other.maxIntDigits
+                && this.minIntDigits == other.minIntDigits
+                && this.zeroDigit == other.zeroDigit
+                && this.minusSign == other.minusSign
+                && this.positiveOnly == other.positiveOnly);
+    }
+
+    private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
+        stream.defaultReadObject();
+        // re-allocate the work buffer
+        decimalBuf = new char[20];
+    }
+}
+
+//eof