]> source.dussan.org Git - poi.git/commitdiff
Minor code improvements, fixed comments
authorJosh Micich <josh@apache.org>
Wed, 3 Dec 2008 23:39:11 +0000 (23:39 +0000)
committerJosh Micich <josh@apache.org>
Wed, 3 Dec 2008 23:39:11 +0000 (23:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@723146 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/formula/Formula.java

index eaf73cd637a5e710660686cef9fe0763ed941b1c..f2cef2cb42879425d611d40bfc3f99eeea31f49c 100644 (file)
@@ -1,3 +1,20 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
 package org.apache.poi.ss.formula;\r
 \r
 import java.util.Arrays;\r
@@ -14,9 +31,16 @@ import org.apache.poi.util.LittleEndianByteArrayInputStream;
 import org.apache.poi.util.LittleEndianInput;\r
 import org.apache.poi.util.LittleEndianOutput;\r
 \r
+/**\r
+ * Encapsulates an encoded formula token array. \r
+ * \r
+ * @author Josh Micich\r
+ */\r
 public class Formula {\r
 \r
-       private static final byte[] EMPTY_BYTE_ARRAY = { };\r
+       private static final Formula EMPTY = new Formula(new byte[0], 0);\r
+\r
+       /** immutable */\r
        private final byte[] _byteEncoding;\r
        private final int _encodedTokenLen;\r
        \r
@@ -24,17 +48,17 @@ public class Formula {
                _byteEncoding = byteEncoding;\r
                _encodedTokenLen = encodedTokenLen;\r
                if (false) { // set to true to eagerly check Ptg decoding \r
-               LittleEndianByteArrayInputStream in = new LittleEndianByteArrayInputStream(byteEncoding);\r
-               Ptg.readTokens(encodedTokenLen, in);\r
-               int nUnusedBytes = _byteEncoding.length - in.getReadIndex();\r
-               if (nUnusedBytes > 0) {\r
-                       // TODO - this seems to occur when IntersectionPtg is present\r
-                       // This example file "IntersectionPtg.xls"\r
-                       // used by test: TestIntersectionPtg.testReading()\r
-                       // has 10 bytes unused at the end of the formula\r
-                       // 10 extra bytes are just 0x01 and 0x00\r
-                       System.out.println(nUnusedBytes + " unused bytes at end of formula");\r
-               }\r
+                       LittleEndianByteArrayInputStream in = new LittleEndianByteArrayInputStream(byteEncoding);\r
+                       Ptg.readTokens(encodedTokenLen, in);\r
+                       int nUnusedBytes = _byteEncoding.length - in.getReadIndex();\r
+                       if (nUnusedBytes > 0) {\r
+                               // TODO - this seems to occur when IntersectionPtg is present\r
+                               // This example file "IntersectionPtg.xls"\r
+                               // used by test: TestIntersectionPtg.testReading()\r
+                               // has 10 bytes unused at the end of the formula\r
+                               // 10 extra bytes are just 0x01 and 0x00\r
+                               System.out.println(nUnusedBytes + " unused bytes at end of formula");\r
+                       }\r
                }\r
        }\r
        /**\r
@@ -112,8 +136,8 @@ public class Formula {
         * @return Never <code>null</code> (Possibly empty if the supplied <tt>ptgs</tt> is <code>null</code>)\r
         */\r
        public static Formula create(Ptg[] ptgs) {\r
-               if (ptgs == null) {\r
-                       return new Formula(EMPTY_BYTE_ARRAY, 0);\r
+               if (ptgs == null || ptgs.length < 1) {\r
+                       return EMPTY;\r
                }\r
                int totalSize = Ptg.getEncodedSize(ptgs);\r
                byte[] encodedData = new byte[totalSize];\r
@@ -136,7 +160,7 @@ public class Formula {
        }\r
        \r
        public Formula copy() {\r
-               // OK to return this for the moment because currently immutable\r
+               // OK to return this because immutable\r
                return this;\r
        }\r
        \r