aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2008-12-03 23:39:11 +0000
committerJosh Micich <josh@apache.org>2008-12-03 23:39:11 +0000
commitdb07c3ed7eff2e638a5cbb0ab4a79ff4e2be889e (patch)
tree18fa7e75136859e3b486dbb073b5d81913ee310a /src/java/org
parentbcfff4072f90bb923f5d475be17a9aa783373edf (diff)
downloadpoi-db07c3ed7eff2e638a5cbb0ab4a79ff4e2be889e.tar.gz
poi-db07c3ed7eff2e638a5cbb0ab4a79ff4e2be889e.zip
Minor code improvements, fixed comments
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@723146 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
-rw-r--r--src/java/org/apache/poi/ss/formula/Formula.java54
1 files changed, 39 insertions, 15 deletions
diff --git a/src/java/org/apache/poi/ss/formula/Formula.java b/src/java/org/apache/poi/ss/formula/Formula.java
index eaf73cd637..f2cef2cb42 100644
--- a/src/java/org/apache/poi/ss/formula/Formula.java
+++ b/src/java/org/apache/poi/ss/formula/Formula.java
@@ -1,3 +1,20 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.ss.formula;
import java.util.Arrays;
@@ -14,9 +31,16 @@ import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
+/**
+ * Encapsulates an encoded formula token array.
+ *
+ * @author Josh Micich
+ */
public class Formula {
- private static final byte[] EMPTY_BYTE_ARRAY = { };
+ private static final Formula EMPTY = new Formula(new byte[0], 0);
+
+ /** immutable */
private final byte[] _byteEncoding;
private final int _encodedTokenLen;
@@ -24,17 +48,17 @@ public class Formula {
_byteEncoding = byteEncoding;
_encodedTokenLen = encodedTokenLen;
if (false) { // set to true to eagerly check Ptg decoding
- LittleEndianByteArrayInputStream in = new LittleEndianByteArrayInputStream(byteEncoding);
- Ptg.readTokens(encodedTokenLen, in);
- int nUnusedBytes = _byteEncoding.length - in.getReadIndex();
- if (nUnusedBytes > 0) {
- // TODO - this seems to occur when IntersectionPtg is present
- // This example file "IntersectionPtg.xls"
- // used by test: TestIntersectionPtg.testReading()
- // has 10 bytes unused at the end of the formula
- // 10 extra bytes are just 0x01 and 0x00
- System.out.println(nUnusedBytes + " unused bytes at end of formula");
- }
+ LittleEndianByteArrayInputStream in = new LittleEndianByteArrayInputStream(byteEncoding);
+ Ptg.readTokens(encodedTokenLen, in);
+ int nUnusedBytes = _byteEncoding.length - in.getReadIndex();
+ if (nUnusedBytes > 0) {
+ // TODO - this seems to occur when IntersectionPtg is present
+ // This example file "IntersectionPtg.xls"
+ // used by test: TestIntersectionPtg.testReading()
+ // has 10 bytes unused at the end of the formula
+ // 10 extra bytes are just 0x01 and 0x00
+ System.out.println(nUnusedBytes + " unused bytes at end of formula");
+ }
}
}
/**
@@ -112,8 +136,8 @@ public class Formula {
* @return Never <code>null</code> (Possibly empty if the supplied <tt>ptgs</tt> is <code>null</code>)
*/
public static Formula create(Ptg[] ptgs) {
- if (ptgs == null) {
- return new Formula(EMPTY_BYTE_ARRAY, 0);
+ if (ptgs == null || ptgs.length < 1) {
+ return EMPTY;
}
int totalSize = Ptg.getEncodedSize(ptgs);
byte[] encodedData = new byte[totalSize];
@@ -136,7 +160,7 @@ public class Formula {
}
public Formula copy() {
- // OK to return this for the moment because currently immutable
+ // OK to return this because immutable
return this;
}