]> source.dussan.org Git - poi.git/commitdiff
#59170 - Remove deprecated classes (POI 3.15) - remove BuiltinFormats.getBuiltinFormats()
authorAndreas Beeker <kiwiwings@apache.org>
Tue, 7 Jun 2016 23:13:57 +0000 (23:13 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Tue, 7 Jun 2016 23:13:57 +0000 (23:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1747325 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/usermodel/BuiltinFormats.java

index 54bae723cbf42429eabb257813b5e1fe6cf795b0..708f2f66a4390efb5fe9e9cfa311be306adfd526 100644 (file)
 ==================================================================== */
 package org.apache.poi.ss.usermodel;
 
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
 /**
  * Utility to identify built-in formats.  The following is a list of the formats as
  * returned by this class.<p/>
@@ -65,12 +60,6 @@ import java.util.Map;
  *       0x31, "@" - This is text format.<br/>
  *       0x31  "text" - Alias for "@"<br/>
  * <p/>
- *
- * @author Yegor Kozlov
- *
- * Modified 6/17/09 by Stanislav Shor - positive formats don't need starting '('
- * Modified 10/31/13 by Eric Peters - * is a repeating/padding character directive, examples needed a space after the asterix (e.i. Accounting format)
- *
  */
 public final class BuiltinFormats {
        /**
@@ -78,95 +67,62 @@ public final class BuiltinFormats {
         */
        public static final int FIRST_USER_DEFINED_FORMAT_INDEX = 164;
 
-       private final static String[] _formats;
-
-/*
-0 General General 18 Time h:mm AM/PM
-1 Decimal 0 19 Time h:mm:ss AM/PM
-2 Decimal 0.00 20 Time h:mm
-3 Decimal #,##0 21 Time h:mm:ss
-4 Decimal #,##0.00 2232 Date/Time M/D/YY h:mm
-531 Currency "$"#,##0_);("$"#,##0) 37 Account. _(#,##0_);(#,##0)
-631 Currency "$"#,##0_);[Red]("$"#,##0) 38 Account. _(#,##0_);[Red](#,##0)
-731 Currency "$"#,##0.00_);("$"#,##0.00) 39 Account. _(#,##0.00_);(#,##0.00)
-831 Currency "$"#,##0.00_);[Red]("$"#,##0.00) 40 Account. _(#,##0.00_);[Red](#,##0.00)
-9 Percent 0% 4131 Currency _("$"* #,##0_);_("$"* (#,##0);_("$"* "-"_);_(@_)
-10 Percent 0.00% 4231 33 Currency _(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)
-11 Scientific 0.00E+00 4331 Currency _("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)
-12 Fraction # ?/? 4431 33 Currency _(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)
-13 Fraction # ??/?? 45 Time mm:ss
-1432 Date M/D/YY 46 Time [h]:mm:ss
-15 Date D-MMM-YY 47 Time mm:ss.0
-16 Date D-MMM 48 Scientific ##0.0E+0
-17 Date MMM-YY 49 Text @
-* */
-       static {
-               List<String> m = new ArrayList<String>();
-               putFormat(m, 0, "General");
-               putFormat(m, 1, "0");
-               putFormat(m, 2, "0.00");
-               putFormat(m, 3, "#,##0");
-               putFormat(m, 4, "#,##0.00");
-               putFormat(m, 5, "\"$\"#,##0_);(\"$\"#,##0)");
-               putFormat(m, 6, "\"$\"#,##0_);[Red](\"$\"#,##0)");
-               putFormat(m, 7, "\"$\"#,##0.00_);(\"$\"#,##0.00)");
-               putFormat(m, 8, "\"$\"#,##0.00_);[Red](\"$\"#,##0.00)");
-               putFormat(m, 9, "0%");
-               putFormat(m, 0xa, "0.00%");
-               putFormat(m, 0xb, "0.00E+00");
-               putFormat(m, 0xc, "# ?/?");
-               putFormat(m, 0xd, "# ??/??");
-               putFormat(m, 0xe, "m/d/yy");
-               putFormat(m, 0xf, "d-mmm-yy");
-               putFormat(m, 0x10, "d-mmm");
-               putFormat(m, 0x11, "mmm-yy");
-               putFormat(m, 0x12, "h:mm AM/PM");
-               putFormat(m, 0x13, "h:mm:ss AM/PM");
-               putFormat(m, 0x14, "h:mm");
-               putFormat(m, 0x15, "h:mm:ss");
-               putFormat(m, 0x16, "m/d/yy h:mm");
-
-               // 0x17 - 0x24 reserved for international and undocumented
-               for (int i=0x17; i<=0x24; i++) {
-                       // TODO - one junit relies on these values which seems incorrect
-                       putFormat(m, i, "reserved-0x" + Integer.toHexString(i));
-               }
-
-               putFormat(m, 0x25, "#,##0_);(#,##0)");
-               putFormat(m, 0x26, "#,##0_);[Red](#,##0)");
-               putFormat(m, 0x27, "#,##0.00_);(#,##0.00)");
-               putFormat(m, 0x28, "#,##0.00_);[Red](#,##0.00)");
-               putFormat(m, 0x29, "_(\"$\"* #,##0_);_(\"$\"* (#,##0);_(\"$\"* \"-\"_);_(@_)");
-               putFormat(m, 0x2a, "_(* #,##0_);_(* (#,##0);_(* \"-\"_);_(@_)");
-               putFormat(m, 0x2b, "_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)");
-               putFormat(m, 0x2c, "_(\"$\"* #,##0.00_);_(\"$\"* (#,##0.00);_(\"$\"* \"-\"??_);_(@_)");
-               putFormat(m, 0x2d, "mm:ss");
-               putFormat(m, 0x2e, "[h]:mm:ss");
-               putFormat(m, 0x2f, "mm:ss.0");
-               putFormat(m, 0x30, "##0.0E+0");
-               putFormat(m, 0x31, "@");
-               String[] ss = new String[m.size()];
-               m.toArray(ss);
-               _formats = ss;
-       }
-       private static void putFormat(List<String> m, int index, String value) {
-               if (m.size() != index) {
-                       throw new IllegalStateException("index " + index  + " is wrong");
-               }
-               m.add(value);
-       }
-
+       private final static String[] _formats = {
+        "General",
+        "0",
+        "0.00",
+        "#,##0",
+        "#,##0.00",
+        "\"$\"#,##0_);(\"$\"#,##0)",
+        "\"$\"#,##0_);[Red](\"$\"#,##0)",
+        "\"$\"#,##,00_);(\"$\"#,##0.00)",
+        "\"$\"#,##0.00_);[Red](\"$\"#,##0.00)",
+        "0%",
+        "0.00%",
+        "0.00E+00",
+        "# ?/?",
+        "# ??/??",
+        "m/d/yy",
+        "d-mmm-yy",
+        "d-mmm",
+        "mmm-yy",
+        "h:mm AM/PM",
+        "h:mm:ss AM/PM",
+        "h:mm",
+        "h:mm:ss",
+        "m/d/yy h:mm",
 
-       /**
-        * @deprecated (May 2009) use {@link #getAll()}
-        */
-       public static Map<Integer, String> getBuiltinFormats() {
-               Map<Integer, String> result = new LinkedHashMap<Integer, String>();
-               for (int i=0; i<_formats.length; i++) {
-                       result.put(Integer.valueOf(i), _formats[i]);
-               }
-               return result;
-       }
+        // 0x17 - 0x24 reserved for international and undocumented
+        // TODO - one junit relies on these values which seems incorrect
+        "reserved-0x17",
+        "reserved-0x18",
+        "reserved-0x19",
+        "reserved-0x1A",
+        "reserved-0x1B",
+        "reserved-0x1C",
+        "reserved-0x1D",
+        "reserved-0x1E",
+        "reserved-0x1F",
+        "reserved-0x20",
+        "reserved-0x21",
+        "reserved-0x22",
+        "reserved-0x23",
+        "reserved-0x24",
+        
+        "#,##0_);(#,##0)",
+        "#,##0_);[Red](#,##0)",
+        "#,##0.00_);(#,##0.00)",
+        "#,##0.00_);[Red](#,##0.00)",
+        "_(\"$\"* #,##0_);_(\"$\"* (#,##0);_(\"$\"* \"-\"_);_(@_)",
+        "_(* #,##0_);_(* (#,##0);_(* \"-\"_);_(@_)",
+        "_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)",
+        "_(\"$\"* #,##0.00_);_(\"$\"* (#,##0.00);_(\"$\"* \"-\"??_);_(@_)",
+        "mm:ss",
+        "[h]:mm:ss",
+        "mm:ss.0",
+        "##0.0E+0",
+        "@"
+       };
 
        /**
         * @return array of built-in data formats
@@ -189,26 +145,23 @@ public final class BuiltinFormats {
        }
 
        /**
-        * Get the format index that matches the given format string
-        * <p/>
+        * Get the format index that matches the given format string.<br/>
         * Automatically converts "text" to excel's format string to represent text.
-        * </p>
+        * 
         * @param pFmt string matching a built-in format
         * @return index of format or -1 if undefined.
         */
        public static int getBuiltinFormat(String pFmt) {
-               String fmt;
-               if (pFmt.equalsIgnoreCase("TEXT")) {
-                       fmt = "@";
-               } else {
-                       fmt = pFmt;
-               }
+               String fmt = "TEXT".equalsIgnoreCase(pFmt) ? "@" : pFmt;
 
-               for(int i =0; i< _formats.length; i++) {
-                       if(fmt.equals(_formats[i])) {
-                               return i;
-                       }
+               int i = -1;
+               for (String f : _formats) {
+                   i++;
+                   if (f.equals(fmt)) {
+                       return i; 
+                   }
                }
+               
                return -1;
        }
 }