]> source.dussan.org Git - poi.git/commitdiff
Performance and memory improvements:
authorJason Height <jheight@apache.org>
Fri, 2 Sep 2005 03:48:31 +0000 (03:48 +0000)
committerJason Height <jheight@apache.org>
Fri, 2 Sep 2005 03:48:31 +0000 (03:48 +0000)
1) using BitFieldFactory
2) HSSFCell doesnt hold onto stale UnicodeString values (gets latest from SST)
3) Default for Encoding in HSSFCell is "do nothing". This will mean duplicate copies of the UnicodeString will not be required, just to change the encoding. The default "string" encoding will be used.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353778 13f79535-47bb-0310-9956-ffa450edef68

39 files changed:
src/java/org/apache/poi/hssf/model/Sheet.java
src/java/org/apache/poi/hssf/model/Workbook.java
src/java/org/apache/poi/hssf/record/AreaFormatRecord.java
src/java/org/apache/poi/hssf/record/AreaRecord.java
src/java/org/apache/poi/hssf/record/AxisOptionsRecord.java
src/java/org/apache/poi/hssf/record/BarRecord.java
src/java/org/apache/poi/hssf/record/CategorySeriesAxisRecord.java
src/java/org/apache/poi/hssf/record/ChartFormatRecord.java
src/java/org/apache/poi/hssf/record/ColumnInfoRecord.java
src/java/org/apache/poi/hssf/record/CommonObjectDataSubRecord.java
src/java/org/apache/poi/hssf/record/DatRecord.java
src/java/org/apache/poi/hssf/record/DataFormatRecord.java
src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java
src/java/org/apache/poi/hssf/record/FontRecord.java
src/java/org/apache/poi/hssf/record/FrameRecord.java
src/java/org/apache/poi/hssf/record/LegendRecord.java
src/java/org/apache/poi/hssf/record/LineFormatRecord.java
src/java/org/apache/poi/hssf/record/LinkedDataRecord.java
src/java/org/apache/poi/hssf/record/PrintSetupRecord.java
src/java/org/apache/poi/hssf/record/RowRecord.java
src/java/org/apache/poi/hssf/record/SeriesLabelsRecord.java
src/java/org/apache/poi/hssf/record/SheetPropertiesRecord.java
src/java/org/apache/poi/hssf/record/StyleRecord.java
src/java/org/apache/poi/hssf/record/TextObjectBaseRecord.java
src/java/org/apache/poi/hssf/record/TextObjectRecord.java
src/java/org/apache/poi/hssf/record/TextRecord.java
src/java/org/apache/poi/hssf/record/TickRecord.java
src/java/org/apache/poi/hssf/record/ValueRangeRecord.java
src/java/org/apache/poi/hssf/record/WSBoolRecord.java
src/java/org/apache/poi/hssf/record/WindowOneRecord.java
src/java/org/apache/poi/hssf/record/WindowTwoRecord.java
src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java
src/java/org/apache/poi/hssf/record/formula/AreaPtg.java
src/java/org/apache/poi/hssf/record/formula/AttrPtg.java
src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java
src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java
src/java/org/apache/poi/hssf/record/formula/StringPtg.java
src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java

index 22297271658ef3d1fd43827f55ed19cb757e7d01..34f0e9d8879b95b5bd1c18adce9b03c2eaa4f1bb 100644 (file)
@@ -1033,6 +1033,12 @@ public class Sheet implements Model
         setLoc(dimsloc);
         if (log.check( POILogger.DEBUG ))
             log.log(POILogger.DEBUG, "replaceValueRecord ");
+        //The ValueRecordsAggregate use a tree map underneath.
+        //The tree Map uses the CellValueRecordInterface as both the
+        //key and the value, if we dont do a remove, then
+        //the previous instance of the key is retained, effectively using 
+        //double the memory
+        cells.removeCell(newval);
         cells.insertCell(newval);
 
         /*
index 4bc93eb96a7b8bb85a258844d095b29ea749c925..ad2b9e27abe9c834055c1b934f0174d3f41d35a3 100644 (file)
@@ -216,6 +216,7 @@ public class Workbook implements Model
                     if (log.check( POILogger.DEBUG ))
                         log.log(DEBUG, "found palette record at " + k);
                     retval.records.setPalettepos( k );
+                    break;
                 case WindowOneRecord.sid:
                     if (log.check( POILogger.DEBUG ))
                         log.log(DEBUG, "found WindowOneRecord at " + k);
index cdcfeab940950b444ffbbe6601b35b329f310a43..4067dd2e45b7466e7d933a06f2ad95f044c92efe 100644 (file)
@@ -37,8 +37,8 @@ public class AreaFormatRecord
     private  int        field_2_backgroundColor;
     private  short      field_3_pattern;
     private  short      field_4_formatFlags;
-    private  BitField   automatic                                   = new BitField(0x1);
-    private  BitField   invert                                      = new BitField(0x2);
+    private  BitField   automatic                                   = BitFieldFactory.getInstance(0x1);
+    private  BitField   invert                                      = BitFieldFactory.getInstance(0x2);
     private  short      field_5_forecolorIndex;
     private  short      field_6_backcolorIndex;
 
index 9278293bba70e20cf6b8ce32bc94dbd2dcfb5fad..8282ce2dec86ea84fca51dbb3754602f83ba632a 100644 (file)
@@ -34,9 +34,9 @@ public class AreaRecord
 {
     public final static short      sid                             = 0x101A;
     private  short      field_1_formatFlags;
-    private  BitField   stacked                                     = new BitField(0x1);
-    private  BitField   displayAsPercentage                         = new BitField(0x2);
-    private  BitField   shadow                                      = new BitField(0x4);
+    private  BitField   stacked                                     = BitFieldFactory.getInstance(0x1);
+    private  BitField   displayAsPercentage                         = BitFieldFactory.getInstance(0x2);
+    private  BitField   shadow                                      = BitFieldFactory.getInstance(0x4);
 
 
     public AreaRecord()
index e1b4a772557bfd5a5df882880a928a5e3283dac7..03eede06b717578db582c8a6e90d3b93a0a1402b 100644 (file)
@@ -42,14 +42,14 @@ public class AxisOptionsRecord
     private  short      field_7_baseUnit;
     private  short      field_8_crossingPoint;
     private  short      field_9_options;
-    private  BitField   defaultMinimum                              = new BitField(0x1);
-    private  BitField   defaultMaximum                              = new BitField(0x2);
-    private  BitField   defaultMajor                                = new BitField(0x4);
-    private  BitField   defaultMinorUnit                            = new BitField(0x8);
-    private  BitField   isDate                                      = new BitField(0x10);
-    private  BitField   defaultBase                                 = new BitField(0x20);
-    private  BitField   defaultCross                                = new BitField(0x40);
-    private  BitField   defaultDateSettings                         = new BitField(0x80);
+    private  BitField   defaultMinimum                              = BitFieldFactory.getInstance(0x1);
+    private  BitField   defaultMaximum                              = BitFieldFactory.getInstance(0x2);
+    private  BitField   defaultMajor                                = BitFieldFactory.getInstance(0x4);
+    private  BitField   defaultMinorUnit                            = BitFieldFactory.getInstance(0x8);
+    private  BitField   isDate                                      = BitFieldFactory.getInstance(0x10);
+    private  BitField   defaultBase                                 = BitFieldFactory.getInstance(0x20);
+    private  BitField   defaultCross                                = BitFieldFactory.getInstance(0x40);
+    private  BitField   defaultDateSettings                         = BitFieldFactory.getInstance(0x80);
 
 
     public AxisOptionsRecord()
index 77038ca00976c0ddd3b1afd54171aca1de28f2ba..5411581cb5dc391e487813fc3e9fb10e126ffb8e 100644 (file)
@@ -36,10 +36,10 @@ public class BarRecord
     private  short      field_1_barSpace;
     private  short      field_2_categorySpace;
     private  short      field_3_formatFlags;
-    private  BitField   horizontal                                  = new BitField(0x1);
-    private  BitField   stacked                                     = new BitField(0x2);
-    private  BitField   displayAsPercentage                         = new BitField(0x4);
-    private  BitField   shadow                                      = new BitField(0x8);
+    private  BitField   horizontal                                  = BitFieldFactory.getInstance(0x1);
+    private  BitField   stacked                                     = BitFieldFactory.getInstance(0x2);
+    private  BitField   displayAsPercentage                         = BitFieldFactory.getInstance(0x4);
+    private  BitField   shadow                                      = BitFieldFactory.getInstance(0x8);
 
 
     public BarRecord()
index 4f4c236c0ab61dec811d58e7b7ab34a5b3a71921..c305ac66a7a5ba706f93d0fa0fe33300dd8b26a2 100644 (file)
@@ -37,9 +37,9 @@ public class CategorySeriesAxisRecord
     private  short      field_2_labelFrequency;
     private  short      field_3_tickMarkFrequency;
     private  short      field_4_options;
-    private  BitField   valueAxisCrossing                           = new BitField(0x1);
-    private  BitField   crossesFarRight                             = new BitField(0x2);
-    private  BitField   reversed                                    = new BitField(0x4);
+    private  BitField   valueAxisCrossing                           = BitFieldFactory.getInstance(0x1);
+    private  BitField   crossesFarRight                             = BitFieldFactory.getInstance(0x2);
+    private  BitField   reversed                                    = BitFieldFactory.getInstance(0x4);
 
 
     public CategorySeriesAxisRecord()
index 658d98bd7272504f078f4fd98ed8a08f7ef2f034..2b22c64a70df571a93ef3840a2cea9d57a77971f 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.poi.hssf.record;
 
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
 
 /**
  * Class ChartFormatRecord
@@ -40,7 +41,7 @@ public class ChartFormatRecord
     private int               field3_width;
     private int               field4_height;
     private short             field5_grbit;
-    private BitField          varyDisplayPattern = new BitField(0x01);
+    private BitField          varyDisplayPattern = BitFieldFactory.getInstance(0x01);
 
     public ChartFormatRecord()
     {
index edd3a000fca41831c6ed17c3b1114bbb440f099e..c141a356e4e749c15267cdf87390d0bfc612a501 100644 (file)
@@ -25,6 +25,7 @@ package org.apache.poi.hssf.record;
 
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
 
 /**
  * Title: ColumnInfo Record<P>
@@ -43,9 +44,9 @@ public class ColumnInfoRecord
     private short                 field_3_col_width;
     private short                 field_4_xf_index;
     private short                 field_5_options;
-    static final private BitField hidden    = new BitField(0x01);
-    static final private BitField outlevel  = new BitField(0x0700);
-    static final private BitField collapsed = new BitField(0x1000);
+    static final private BitField hidden    = BitFieldFactory.getInstance(0x01);
+    static final private BitField outlevel  = BitFieldFactory.getInstance(0x0700);
+    static final private BitField collapsed = BitFieldFactory.getInstance(0x1000);
     private short                 field_6_reserved;
 
     public ColumnInfoRecord()
index 105bd86f5d1e166ecd1335e2063052dbb6fdb57f..aa68c8a2f0e5da283a1e38385043f0f879867904 100644 (file)
@@ -67,10 +67,10 @@ public class CommonObjectDataSubRecord
     public final static short       OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING = 30;
     private  short      field_2_objectId;
     private  short      field_3_option;
-    private  BitField   locked                                      = new BitField(0x1);
-    private  BitField   printable                                   = new BitField(0x10);
-    private  BitField   autofill                                    = new BitField(0x2000);
-    private  BitField   autoline                                    = new BitField(0x4000);
+    private  BitField   locked                                      = BitFieldFactory.getInstance(0x1);
+    private  BitField   printable                                   = BitFieldFactory.getInstance(0x10);
+    private  BitField   autofill                                    = BitFieldFactory.getInstance(0x2000);
+    private  BitField   autoline                                    = BitFieldFactory.getInstance(0x4000);
     private  int        field_4_reserved1;
     private  int        field_5_reserved2;
     private  int        field_6_reserved3;
index 223f936b19fbd1b8bfeecb3407d9db08daf6a67f..182142826ede222469bd0fc078f164d6ca2ac330 100644 (file)
@@ -34,10 +34,10 @@ public class DatRecord
 {
     public final static short      sid                             = 0x1063;
     private  short      field_1_options;
-    private  BitField   horizontalBorder                            = new BitField(0x1);
-    private  BitField   verticalBorder                              = new BitField(0x2);
-    private  BitField   border                                      = new BitField(0x4);
-    private  BitField   showSeriesKey                               = new BitField(0x8);
+    private  BitField   horizontalBorder                            = BitFieldFactory.getInstance(0x1);
+    private  BitField   verticalBorder                              = BitFieldFactory.getInstance(0x2);
+    private  BitField   border                                      = BitFieldFactory.getInstance(0x4);
+    private  BitField   showSeriesKey                               = BitFieldFactory.getInstance(0x8);
 
 
     public DatRecord()
index c605186aabc7912a1c115e94976c40e92f219d52..5f6ee27a05f5a64c4f7134f36c415c5ea251d6c4 100644 (file)
@@ -37,7 +37,7 @@ public class DataFormatRecord
     private  short      field_2_seriesIndex;
     private  short      field_3_seriesNumber;
     private  short      field_4_formatFlags;
-    private  BitField   useExcel4Colors                             = new BitField(0x1);
+    private  BitField   useExcel4Colors                             = BitFieldFactory.getInstance(0x1);
 
 
     public DataFormatRecord()
index f7d0226ac9e0bdd89185bb9696b2e7aad76ee11c..e19d8948081d44e64c4512365e57e56a261091e8 100644 (file)
@@ -19,6 +19,7 @@
 package org.apache.poi.hssf.record;
 
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.LittleEndian;
 
 /**
@@ -104,81 +105,81 @@ public class ExtendedFormatRecord
     private short                 field_2_format_index;           // not bit-mapped
 
     // field_3_cell_options bit map
-    static final private BitField _locked       = new BitField(0x0001);
-    static final private BitField _hidden       = new BitField(0x0002);
-    static final private BitField _xf_type      = new BitField(0x0004);
-    static final private BitField _123_prefix   = new BitField(0x0008);
-    static final private BitField _parent_index = new BitField(0xFFF0);
+    static final private BitField _locked       = BitFieldFactory.getInstance(0x0001);
+    static final private BitField _hidden       = BitFieldFactory.getInstance(0x0002);
+    static final private BitField _xf_type      = BitFieldFactory.getInstance(0x0004);
+    static final private BitField _123_prefix   = BitFieldFactory.getInstance(0x0008);
+    static final private BitField _parent_index = BitFieldFactory.getInstance(0xFFF0);
     private short                 field_3_cell_options;
 
     // field_4_alignment_options bit map
-    static final private BitField _alignment          = new BitField(0x0007);
-    static final private BitField _wrap_text          = new BitField(0x0008);
-    static final private BitField _vertical_alignment = new BitField(0x0070);
-    static final private BitField _justify_last       = new BitField(0x0080);
-    static final private BitField _rotation           = new BitField(0xFF00);
+    static final private BitField _alignment          = BitFieldFactory.getInstance(0x0007);
+    static final private BitField _wrap_text          = BitFieldFactory.getInstance(0x0008);
+    static final private BitField _vertical_alignment = BitFieldFactory.getInstance(0x0070);
+    static final private BitField _justify_last       = BitFieldFactory.getInstance(0x0080);
+    static final private BitField _rotation           = BitFieldFactory.getInstance(0xFF00);
     private short                 field_4_alignment_options;
 
     // field_5_indention_options
     static final private BitField _indent                         =
-        new BitField(0x000F);
+        BitFieldFactory.getInstance(0x000F);
     static final private BitField _shrink_to_fit                  =
-        new BitField(0x0010);
+        BitFieldFactory.getInstance(0x0010);
     static final private BitField _merge_cells                    =
-        new BitField(0x0020);
+        BitFieldFactory.getInstance(0x0020);
     static final private BitField _reading_order                  =
-        new BitField(0x00C0);
+        BitFieldFactory.getInstance(0x00C0);
 
     // apparently bits 8 and 9 are unused
     static final private BitField _indent_not_parent_format       =
-        new BitField(0x0400);
+        BitFieldFactory.getInstance(0x0400);
     static final private BitField _indent_not_parent_font         =
-        new BitField(0x0800);
+        BitFieldFactory.getInstance(0x0800);
     static final private BitField _indent_not_parent_alignment    =
-        new BitField(0x1000);
+        BitFieldFactory.getInstance(0x1000);
     static final private BitField _indent_not_parent_border       =
-        new BitField(0x2000);
+        BitFieldFactory.getInstance(0x2000);
     static final private BitField _indent_not_parent_pattern      =
-        new BitField(0x4000);
+        BitFieldFactory.getInstance(0x4000);
     static final private BitField _indent_not_parent_cell_options =
-        new BitField(0x8000);
+        BitFieldFactory.getInstance(0x8000);
     private short                 field_5_indention_options;
 
     // field_6_border_options bit map
-    static final private BitField _border_left   = new BitField(0x000F);
-    static final private BitField _border_right  = new BitField(0x00F0);
-    static final private BitField _border_top    = new BitField(0x0F00);
-    static final private BitField _border_bottom = new BitField(0xF000);
+    static final private BitField _border_left   = BitFieldFactory.getInstance(0x000F);
+    static final private BitField _border_right  = BitFieldFactory.getInstance(0x00F0);
+    static final private BitField _border_top    = BitFieldFactory.getInstance(0x0F00);
+    static final private BitField _border_bottom = BitFieldFactory.getInstance(0xF000);
     private short                 field_6_border_options;
 
     // all three of the following attributes are palette options
     // field_7_palette_options bit map
     static final private BitField _left_border_palette_idx  =
-        new BitField(0x007F);
+        BitFieldFactory.getInstance(0x007F);
     static final private BitField _right_border_palette_idx =
-        new BitField(0x3F80);
+        BitFieldFactory.getInstance(0x3F80);
     static final private BitField _diag                     =
-        new BitField(0xC000);
+        BitFieldFactory.getInstance(0xC000);
     private short                 field_7_palette_options;
 
     // field_8_adtl_palette_options bit map
     static final private BitField _top_border_palette_idx    =
-        new BitField(0x0000007F);
+        BitFieldFactory.getInstance(0x0000007F);
     static final private BitField _bottom_border_palette_idx =
-        new BitField(0x00003F80);
+        BitFieldFactory.getInstance(0x00003F80);
     static final private BitField _adtl_diag                 =
-        new BitField(0x001fc000);
+        BitFieldFactory.getInstance(0x001fc000);
     static final private BitField _adtl_diag_line_style      =
-        new BitField(0x01e00000);
+        BitFieldFactory.getInstance(0x01e00000);
 
     // apparently bit 25 is unused
     static final private BitField _adtl_fill_pattern         =
-        new BitField(0xfc000000);
+        BitFieldFactory.getInstance(0xfc000000);
     private int                   field_8_adtl_palette_options;   // additional to avoid 2
 
     // field_9_fill_palette_options bit map
-    static final private BitField _fill_foreground = new BitField(0x007F);
-    static final private BitField _fill_background = new BitField(0x3f80);
+    static final private BitField _fill_foreground = BitFieldFactory.getInstance(0x007F);
+    static final private BitField _fill_background = BitFieldFactory.getInstance(0x3f80);
 
     // apparently bits 15 and 14 are unused
     private short                 field_9_fill_palette_options;
index 0c7021a67dc5d345fc3f5cb62c3a11916303a97a..8c01008933bb9ff330ae039961e486c246c3b7af 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.poi.hssf.record;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.StringUtil;
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
 
 /**
  * Title:        Font Record - descrbes a font in the workbook (index = 0-3,5-infinity - skip 4)<P>
@@ -48,14 +49,14 @@ public class FontRecord
 
     // 0 0x01 - Reserved bit must be 0
     static final private BitField italic     =
-        new BitField(0x02);                                   // is this font in italics
+        BitFieldFactory.getInstance(0x02);                                   // is this font in italics
 
     // 2 0x04 - reserved bit must be 0
     static final private BitField strikeout  =
-        new BitField(0x08);                                   // is this font has a line through the center
-    static final private BitField macoutline = new BitField(
+        BitFieldFactory.getInstance(0x08);                                   // is this font has a line through the center
+    static final private BitField macoutline = BitFieldFactory.getInstance(
         0x10);                                                // some weird macintosh thing....but who understands those mac people anyhow
-    static final private BitField macshadow  = new BitField(
+    static final private BitField macshadow  = BitFieldFactory.getInstance(
         0x20);                                                // some weird macintosh thing....but who understands those mac people anyhow
 
     // 7-6 - reserved bits must be 0
index 7345c364312e6d48a426d994fb8ed0403194ceaf..48e6bb430c27e720a6d7b82a1b817546d2a10a8d 100644 (file)
@@ -37,8 +37,8 @@ public class FrameRecord
     public final static short       BORDER_TYPE_REGULAR            = 0;
     public final static short       BORDER_TYPE_SHADOW             = 1;
     private  short      field_2_options;
-    private  BitField   autoSize                                    = new BitField(0x1);
-    private  BitField   autoPosition                                = new BitField(0x2);
+    private  BitField   autoSize                                    = BitFieldFactory.getInstance(0x1);
+    private  BitField   autoPosition                                = BitFieldFactory.getInstance(0x2);
 
 
     public FrameRecord()
index 55d99c57e4dc5cc3b5d16c5ec681af3036aba892..7f402e2aad04ba37cb2170210f115a7d79e20a93 100644 (file)
@@ -49,12 +49,12 @@ public class LegendRecord
     public final static byte        SPACING_MEDIUM                 = 1;
     public final static byte        SPACING_OPEN                   = 2;
     private  short      field_7_options;
-    private  BitField   autoPosition                                = new BitField(0x1);
-    private  BitField   autoSeries                                  = new BitField(0x2);
-    private  BitField   autoXPositioning                            = new BitField(0x4);
-    private  BitField   autoYPositioning                            = new BitField(0x8);
-    private  BitField   vertical                                    = new BitField(0x10);
-    private  BitField   dataTable                                   = new BitField(0x20);
+    private  BitField   autoPosition                                = BitFieldFactory.getInstance(0x1);
+    private  BitField   autoSeries                                  = BitFieldFactory.getInstance(0x2);
+    private  BitField   autoXPositioning                            = BitFieldFactory.getInstance(0x4);
+    private  BitField   autoYPositioning                            = BitFieldFactory.getInstance(0x8);
+    private  BitField   vertical                                    = BitFieldFactory.getInstance(0x10);
+    private  BitField   dataTable                                   = BitFieldFactory.getInstance(0x20);
 
 
     public LegendRecord()
index e49082d8849dddcd72fc6ad6455f2dc58af27f36..756f81b7be4c28f5546969fefcd7e985d3a363d5 100644 (file)
@@ -50,9 +50,9 @@ public class LineFormatRecord
     public final static short       WEIGHT_MEDIUM                  = 1;
     public final static short       WEIGHT_WIDE                    = 2;
     private  short      field_4_format;
-    private  BitField   auto                                        = new BitField(0x1);
-    private  BitField   drawTicks                                   = new BitField(0x4);
-    private  BitField   unknown                                     = new BitField(0x4);
+    private  BitField   auto                                        = BitFieldFactory.getInstance(0x1);
+    private  BitField   drawTicks                                   = BitFieldFactory.getInstance(0x4);
+    private  BitField   unknown                                     = BitFieldFactory.getInstance(0x4);
     private  short      field_5_colourPaletteIndex;
 
 
index 5b0a3bc6ff2c41fa211bb8ba06f0ab6b5de06b2c..20a64fe0eecb06a0fa3c3153bb5f9c32275f67e8 100644 (file)
@@ -44,7 +44,7 @@ public class LinkedDataRecord
     public final static byte        REFERENCE_TYPE_NOT_USED        = 3;
     public final static byte        REFERENCE_TYPE_ERROR_REPORTED  = 4;
     private  short      field_3_options;
-    private  BitField   customNumberFormat                          = new BitField(0x1);
+    private  BitField   customNumberFormat                          = BitFieldFactory.getInstance(0x1);
     private  short      field_4_indexNumberFmtRecord;
     private  LinkedDataFormulaField field_5_formulaOfLink;
 
index dc6abd493b6d336d0abf6965411b136429fa4fa8..c7ee3d06e2eb66fa3f35f8eb670d31e685fb4cc9 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.poi.hssf.record;
 
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
 
 /**
  * Title:        Print Setup Record<P>
@@ -41,24 +42,24 @@ public class PrintSetupRecord
     private short                 field_5_fit_height;
     private short                 field_6_options;
     static final private BitField lefttoright   =
-        new BitField(0x01);   // print over then down
+        BitFieldFactory.getInstance(0x01);   // print over then down
     static final private BitField landscape     =
-        new BitField(0x02);   // landscape mode
-    static final private BitField validsettings = new BitField(
+        BitFieldFactory.getInstance(0x02);   // landscape mode
+    static final private BitField validsettings = BitFieldFactory.getInstance(
         0x04);                // if papersize, scale, resolution, copies, landscape
 
     // weren't obtained from the print consider them
     // mere bunk
     static final private BitField nocolor       =
-        new BitField(0x08);   // print mono/b&w, colorless
+        BitFieldFactory.getInstance(0x08);   // print mono/b&w, colorless
     static final private BitField draft         =
-        new BitField(0x10);   // print draft quality
+        BitFieldFactory.getInstance(0x10);   // print draft quality
     static final private BitField notes         =
-        new BitField(0x20);   // print the notes
+        BitFieldFactory.getInstance(0x20);   // print the notes
     static final private BitField noOrientation =
-        new BitField(0x40);   // the orientation is not set
+        BitFieldFactory.getInstance(0x40);   // the orientation is not set
     static final private BitField usepage       =
-        new BitField(0x80);   // use a user set page no, instead of auto
+        BitFieldFactory.getInstance(0x80);   // use a user set page no, instead of auto
     private short                 field_7_hresolution;
     private short                 field_8_vresolution;
     private double                field_9_headermargin;
index d30e03c41e116aa8fbb08bf09192d560e98af9f1..73aa1db6a5e7df7b4aa6c84a0599d60f701822db 100644 (file)
@@ -19,6 +19,7 @@
 package org.apache.poi.hssf.record;
 
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.LittleEndian;
 
 /**
@@ -51,13 +52,13 @@ public class RowRecord
     // for generated sheets.
     private short             field_6_reserved;
     private short             field_7_option_flags;
-    private BitField          outlineLevel  = new BitField(0x07);
+    private BitField          outlineLevel  = BitFieldFactory.getInstance(0x07);
 
     // bit 3 reserved
-    private BitField          colapsed      = new BitField(0x10);
-    private BitField          zeroHeight    = new BitField(0x20);
-    private BitField          badFontHeight = new BitField(0x40);
-    private BitField          formatted     = new BitField(0x80);
+    private BitField          colapsed      = BitFieldFactory.getInstance(0x10);
+    private BitField          zeroHeight    = BitFieldFactory.getInstance(0x20);
+    private BitField          badFontHeight = BitFieldFactory.getInstance(0x40);
+    private BitField          formatted     = BitFieldFactory.getInstance(0x80);
     private short             field_8_xf_index;   // only if isFormatted
 
     public RowRecord()
index 1b7f12b053db0b7076cb1a5288bbe2c584e44801..762175654b3eb2fb12cce4130aa9ffff39a04cad 100644 (file)
@@ -34,12 +34,12 @@ public class SeriesLabelsRecord
 {
     public final static short      sid                             = 0x100c;
     private  short      field_1_formatFlags;
-    private  BitField   showActual                                  = new BitField(0x1);
-    private  BitField   showPercent                                 = new BitField(0x2);
-    private  BitField   labelAsPercentage                           = new BitField(0x4);
-    private  BitField   smoothedLine                                = new BitField(0x8);
-    private  BitField   showLabel                                   = new BitField(0x10);
-    private  BitField   showBubbleSizes                             = new BitField(0x20);
+    private  BitField   showActual                                  = BitFieldFactory.getInstance(0x1);
+    private  BitField   showPercent                                 = BitFieldFactory.getInstance(0x2);
+    private  BitField   labelAsPercentage                           = BitFieldFactory.getInstance(0x4);
+    private  BitField   smoothedLine                                = BitFieldFactory.getInstance(0x8);
+    private  BitField   showLabel                                   = BitFieldFactory.getInstance(0x10);
+    private  BitField   showBubbleSizes                             = BitFieldFactory.getInstance(0x20);
 
 
     public SeriesLabelsRecord()
index 9676d32107d53e037f6a21067d152056187e11b9..94c857bda82e9147bc96f8a5e9d1af49ce47b708 100644 (file)
@@ -34,11 +34,11 @@ public class SheetPropertiesRecord
 {
     public final static short      sid                             = 0x1044;
     private  short      field_1_flags;
-    private  BitField   chartTypeManuallyFormatted                  = new BitField(0x1);
-    private  BitField   plotVisibleOnly                             = new BitField(0x2);
-    private  BitField   doNotSizeWithWindow                         = new BitField(0x4);
-    private  BitField   defaultPlotDimensions                       = new BitField(0x8);
-    private  BitField   autoPlotArea                                = new BitField(0x10);
+    private  BitField   chartTypeManuallyFormatted                  = BitFieldFactory.getInstance(0x1);
+    private  BitField   plotVisibleOnly                             = BitFieldFactory.getInstance(0x2);
+    private  BitField   doNotSizeWithWindow                         = BitFieldFactory.getInstance(0x4);
+    private  BitField   defaultPlotDimensions                       = BitFieldFactory.getInstance(0x8);
+    private  BitField   autoPlotArea                                = BitFieldFactory.getInstance(0x10);
     private  byte       field_2_empty;
     public final static byte        EMPTY_NOT_PLOTTED              = 0;
     public final static byte        EMPTY_ZERO                     = 1;
index aa750301252527f6ca1fb327735bd991e4d236af..0779e036b2a74a54d01a1f0f0f44f24073cd6594 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.poi.hssf.record;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.StringUtil;
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
 
 /**
  * Title:        Style Record<P>
@@ -78,7 +79,7 @@ public class StyleRecord
 
     protected void fillFields(RecordInputStream in)
     {
-        fHighByte = new BitField(0x01); //have to init here, since we are being called
+        fHighByte = BitFieldFactory.getInstance(0x01); //have to init here, since we are being called
                                         //from super, and class level init hasnt been done. 
         field_1_xf_index = in.readShort();
         if (getType() == STYLE_BUILT_IN)
index 1232efd437292a64b1f601bfb7a0ebf3ced0f380..b27fbf68abcb5765eb464d792dac46f043e35f5e 100644 (file)
@@ -36,20 +36,20 @@ public class TextObjectBaseRecord
 {
     public final static short      sid                             = 0x1B6;
     private  short      field_1_options;
-    private  BitField   reserved1                                   = new BitField(0x1);
-    private BitField   HorizontalTextAlignment                    = new BitField(0x000E);
+    private  BitField   reserved1                                   = BitFieldFactory.getInstance(0x1);
+    private BitField   HorizontalTextAlignment                    = BitFieldFactory.getInstance(0x000E);
     public final static short  HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED = 1;
     public final static short  HORIZONTAL_TEXT_ALIGNMENT_CENTERED = 2;
     public final static short  HORIZONTAL_TEXT_ALIGNMENT_RIGHT_ALIGNED = 3;
     public final static short  HORIZONTAL_TEXT_ALIGNMENT_JUSTIFIED = 4;
-    private BitField   VerticalTextAlignment                      = new BitField(0x0070);
+    private BitField   VerticalTextAlignment                      = BitFieldFactory.getInstance(0x0070);
     public final static short  VERTICAL_TEXT_ALIGNMENT_TOP    = 1;
     public final static short  VERTICAL_TEXT_ALIGNMENT_CENTER = 2;
     public final static short  VERTICAL_TEXT_ALIGNMENT_BOTTOM = 3;
     public final static short  VERTICAL_TEXT_ALIGNMENT_JUSTIFY = 4;
-    private BitField   reserved2                                  = new BitField(0x0180);
-    private  BitField   textLocked                                  = new BitField(0x200);
-    private BitField   reserved3                                  = new BitField(0xFC00);
+    private BitField   reserved2                                  = BitFieldFactory.getInstance(0x0180);
+    private  BitField   textLocked                                  = BitFieldFactory.getInstance(0x200);
+    private BitField   reserved3                                  = BitFieldFactory.getInstance(0xFC00);
     private  short      field_2_textOrientation;
     public final static short       TEXT_ORIENTATION_NONE          = 0;
     public final static short       TEXT_ORIENTATION_TOP_TO_BOTTOM = 1;
index b9cdca30ea758e28c82a02d44a1376670aec457b..b11f6d5748dbbb92202b52e44136fd3d1980f1fd 100644 (file)
@@ -38,16 +38,20 @@ public class TextObjectRecord
     protected void fillFields(RecordInputStream in)
     {
       super.fillFields(in);
+      if (getTextLength() > 0) {
       if (in.isContinueNext() && in.remaining() == 0) {
         //1st Continue
         in.nextRecord();
         processRawString(in);
+        } else
+          throw new RecordFormatException("Expected Continue record to hold string data for TextObjectRecord");        
+      }
+      if (getFormattingRunLength() > 0) {
         if (in.isContinueNext() && in.remaining() == 0) {
           in.nextRecord();
           processFontRuns(in);
         } else throw new RecordFormatException("Expected Continue Record to hold font runs for TextObjectRecord");
-      } else
-        throw new RecordFormatException("Expected Continue record to hold string data for TextObjectRecord");
+      }
     }
 
 
index 1bddd1538609cb1c833e6741e0dc2b06071a407f..e15be8c3491cbb5b7bce74a85b97ea31e5169adf 100644 (file)
@@ -52,26 +52,26 @@ public class TextRecord
     private  int        field_7_width;
     private  int        field_8_height;
     private  short      field_9_options1;
-    private  BitField   autoColor                                   = new BitField(0x1);
-    private  BitField   showKey                                     = new BitField(0x2);
-    private  BitField   showValue                                   = new BitField(0x4);
-    private  BitField   vertical                                    = new BitField(0x8);
-    private  BitField   autoGeneratedText                           = new BitField(0x10);
-    private  BitField   generated                                   = new BitField(0x20);
-    private  BitField   autoLabelDeleted                            = new BitField(0x40);
-    private  BitField   autoBackground                              = new BitField(0x80);
-    private BitField   rotation                                   = new BitField(0x0700);
+    private  BitField   autoColor                                   = BitFieldFactory.getInstance(0x1);
+    private  BitField   showKey                                     = BitFieldFactory.getInstance(0x2);
+    private  BitField   showValue                                   = BitFieldFactory.getInstance(0x4);
+    private  BitField   vertical                                    = BitFieldFactory.getInstance(0x8);
+    private  BitField   autoGeneratedText                           = BitFieldFactory.getInstance(0x10);
+    private  BitField   generated                                   = BitFieldFactory.getInstance(0x20);
+    private  BitField   autoLabelDeleted                            = BitFieldFactory.getInstance(0x40);
+    private  BitField   autoBackground                              = BitFieldFactory.getInstance(0x80);
+    private BitField   rotation                                   = BitFieldFactory.getInstance(0x0700);
     public final static short  ROTATION_NONE                  = 0;
     public final static short  ROTATION_TOP_TO_BOTTOM         = 1;
     public final static short  ROTATION_ROTATED_90_DEGREES    = 2;
     public final static short  ROTATION_ROTATED_90_DEGREES_CLOCKWISE = 3;
-    private  BitField   showCategoryLabelAsPercentage               = new BitField(0x800);
-    private  BitField   showValueAsPercentage                       = new BitField(0x1000);
-    private  BitField   showBubbleSizes                             = new BitField(0x2000);
-    private  BitField   showLabel                                   = new BitField(0x4000);
+    private  BitField   showCategoryLabelAsPercentage               = BitFieldFactory.getInstance(0x800);
+    private  BitField   showValueAsPercentage                       = BitFieldFactory.getInstance(0x1000);
+    private  BitField   showBubbleSizes                             = BitFieldFactory.getInstance(0x2000);
+    private  BitField   showLabel                                   = BitFieldFactory.getInstance(0x4000);
     private  short      field_10_indexOfColorValue;
     private  short      field_11_options2;
-    private BitField   dataLabelPlacement                         = new BitField(0x000F);
+    private BitField   dataLabelPlacement                         = BitFieldFactory.getInstance(0x000F);
     public final static short  DATA_LABEL_PLACEMENT_CHART_DEPENDENT = 0;
     public final static short  DATA_LABEL_PLACEMENT_OUTSIDE   = 1;
     public final static short  DATA_LABEL_PLACEMENT_INSIDE    = 2;
index b6b3ec0a2fdf36099081c80af1f391d52765b471..0e4b4d3f0b12ccd3dc4f054e1a0026b8c6adb092 100644 (file)
@@ -43,10 +43,10 @@ public class TickRecord
     private  int        field_8_zero3;
     private  int        field_9_zero4;
     private  short      field_10_options;
-    private  BitField   autoTextColor                               = new BitField(0x1);
-    private  BitField   autoTextBackground                          = new BitField(0x2);
-    private BitField   rotation                                   = new BitField(0x1c);
-    private  BitField   autorotate                                  = new BitField(0x20);
+    private  BitField   autoTextColor                               = BitFieldFactory.getInstance(0x1);
+    private  BitField   autoTextBackground                          = BitFieldFactory.getInstance(0x2);
+    private BitField   rotation                                   = BitFieldFactory.getInstance(0x1c);
+    private  BitField   autorotate                                  = BitFieldFactory.getInstance(0x20);
     private  short      field_11_tickColor;
     private  short      field_12_zero5;
 
index 290b0517fe2221a27f754c550dc8ba1f8103c130..353f669d9b07659c8ea5e233b52bfb14ae85775f 100644 (file)
@@ -39,15 +39,15 @@ public class ValueRangeRecord
     private  double     field_4_minorIncrement;
     private  double     field_5_categoryAxisCross;
     private  short      field_6_options;
-    private  BitField   automaticMinimum                            = new BitField(0x1);
-    private  BitField   automaticMaximum                            = new BitField(0x2);
-    private  BitField   automaticMajor                              = new BitField(0x4);
-    private  BitField   automaticMinor                              = new BitField(0x8);
-    private  BitField   automaticCategoryCrossing                   = new BitField(0x10);
-    private  BitField   logarithmicScale                            = new BitField(0x20);
-    private  BitField   valuesInReverse                             = new BitField(0x40);
-    private  BitField   crossCategoryAxisAtMaximum                  = new BitField(0x80);
-    private  BitField   reserved                                    = new BitField(0x100);
+    private  BitField   automaticMinimum                            = BitFieldFactory.getInstance(0x1);
+    private  BitField   automaticMaximum                            = BitFieldFactory.getInstance(0x2);
+    private  BitField   automaticMajor                              = BitFieldFactory.getInstance(0x4);
+    private  BitField   automaticMinor                              = BitFieldFactory.getInstance(0x8);
+    private  BitField   automaticCategoryCrossing                   = BitFieldFactory.getInstance(0x10);
+    private  BitField   logarithmicScale                            = BitFieldFactory.getInstance(0x20);
+    private  BitField   valuesInReverse                             = BitFieldFactory.getInstance(0x40);
+    private  BitField   crossCategoryAxisAtMaximum                  = BitFieldFactory.getInstance(0x80);
+    private  BitField   reserved                                    = BitFieldFactory.getInstance(0x100);
 
 
     public ValueRangeRecord()
index db7bbfd53c4e1775bb97c26b904d971f2db3156e..d5fedd457c508aea6b6d2f58b5592d49b90cc3a1 100644 (file)
@@ -19,6 +19,7 @@
 package org.apache.poi.hssf.record;
 
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.LittleEndian;
 
 /**
@@ -41,29 +42,29 @@ public class WSBoolRecord
 
     // I decided to be consistant in this way.
     static final private BitField autobreaks          =
-        new BitField(0x01);                               // are automatic page breaks visible
+        BitFieldFactory.getInstance(0x01);                               // are automatic page breaks visible
 
     // bits 1 to 3 unused
     static final private BitField dialog              =
-        new BitField(0x10);                               // is sheet dialog sheet
+        BitFieldFactory.getInstance(0x10);                               // is sheet dialog sheet
     static final private BitField applystyles         =
-        new BitField(0x20);                               // whether to apply automatic styles to outlines
-    static final private BitField rowsumsbelow        = new BitField(
+        BitFieldFactory.getInstance(0x20);                               // whether to apply automatic styles to outlines
+    static final private BitField rowsumsbelow        = BitFieldFactory.getInstance(
         0x40);                                            // whether summary rows will appear below detail in outlines
-    static final private BitField rowsumsright        = new BitField(
+    static final private BitField rowsumsright        = BitFieldFactory.getInstance(
         0x80);                                            // whether summary rows will appear right of the detail in outlines
     static final private BitField fittopage           =
-        new BitField(0x01);                               // whether to fit stuff to the page
+        BitFieldFactory.getInstance(0x01);                               // whether to fit stuff to the page
 
     // bit 2 reserved
-    static final private BitField displayguts         = new BitField(
+    static final private BitField displayguts         = BitFieldFactory.getInstance(
         0x06);                                            // whether to display outline symbols (in the gutters)
 
     // bits 4-5 reserved
     static final private BitField alternateexpression =   // whether to use alternate expression eval
-        new BitField(0x40);
+        BitFieldFactory.getInstance(0x40);
     static final private BitField alternateformula    =   // whether to use alternate formula entry
-        new BitField(0x80);
+        BitFieldFactory.getInstance(0x80);
 
     public WSBoolRecord()
     {
index b8d720bcdf0ab9549f95cb4fd15c425322213660..e8482d0d9b5a8b2d47f5c0424a5abcb90ffd5cda 100644 (file)
@@ -19,6 +19,7 @@
 package org.apache.poi.hssf.record;
 
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.LittleEndian;
 
 /**
@@ -43,16 +44,16 @@ public class WindowOneRecord
     private short                 field_4_height;
     private short                 field_5_options;
     static final private BitField hidden   =
-        new BitField(0x01);                                        // is this window is hidden
+        BitFieldFactory.getInstance(0x01);                                        // is this window is hidden
     static final private BitField iconic   =
-        new BitField(0x02);                                        // is this window is an icon
-    static final private BitField reserved = new BitField(0x04);   // reserved
+        BitFieldFactory.getInstance(0x02);                                        // is this window is an icon
+    static final private BitField reserved = BitFieldFactory.getInstance(0x04);   // reserved
     static final private BitField hscroll  =
-        new BitField(0x08);                                        // display horizontal scrollbar
+        BitFieldFactory.getInstance(0x08);                                        // display horizontal scrollbar
     static final private BitField vscroll  =
-        new BitField(0x10);                                        // display vertical scrollbar
+        BitFieldFactory.getInstance(0x10);                                        // display vertical scrollbar
     static final private BitField tabs     =
-        new BitField(0x20);                                        // display tabs at the bottom
+        BitFieldFactory.getInstance(0x20);                                        // display tabs at the bottom
 
     // all the rest are "reserved"
     private short                 field_6_selected_tab;
index 8224629da15f69956dee80ddd158b7e3309daae7..335ab1dd7a44437e580bf40505810eacd8a58e87 100644 (file)
@@ -19,6 +19,7 @@
 package org.apache.poi.hssf.record;
 
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.LittleEndian;
 
 /**
@@ -37,23 +38,23 @@ public class WindowTwoRecord
     private short             field_1_options;
 
     // bitfields
-    private BitField          displayFormulas         = new BitField(0x01);
-    private BitField          displayGridlines        = new BitField(0x02);
-    private BitField          displayRowColHeadings   = new BitField(0x04);
-    private BitField          freezePanes             = new BitField(0x08);
-    private BitField          displayZeros            = new BitField(0x10);
+    private BitField          displayFormulas         = BitFieldFactory.getInstance(0x01);
+    private BitField          displayGridlines        = BitFieldFactory.getInstance(0x02);
+    private BitField          displayRowColHeadings   = BitFieldFactory.getInstance(0x04);
+    private BitField          freezePanes             = BitFieldFactory.getInstance(0x08);
+    private BitField          displayZeros            = BitFieldFactory.getInstance(0x10);
     private BitField          defaultHeader           =
-        new BitField(0x20);   // if false use color in field 4
+        BitFieldFactory.getInstance(0x20);   // if false use color in field 4
 
     // if true use default foreground
     // for headers
     private BitField          arabic                  =
-        new BitField(0x40);   // for our desert dwelling friends
-    private BitField          displayGuts             = new BitField(0x80);
-    private BitField          freezePanesNoSplit      = new BitField(0x100);
-    private BitField          selected                = new BitField(0x200);
-    private BitField          paged                   = new BitField(0x400);
-    private BitField          savedInPageBreakPreview = new BitField(0x800);
+        BitFieldFactory.getInstance(0x40);   // for our desert dwelling friends
+    private BitField          displayGuts             = BitFieldFactory.getInstance(0x80);
+    private BitField          freezePanesNoSplit      = BitFieldFactory.getInstance(0x100);
+    private BitField          selected                = BitFieldFactory.getInstance(0x200);
+    private BitField          paged                   = BitFieldFactory.getInstance(0x400);
+    private BitField          savedInPageBreakPreview = BitFieldFactory.getInstance(0x800);
 
     // 4-7 reserved
     // end bitfields
index 395c6a78477e221e81112fe0f0d52e4b1d306181..d5ffe3ee5bbde596d2712e3ee4b309a886e9b108 100644 (file)
@@ -25,6 +25,8 @@ import org.apache.poi.hssf.util.SheetReferences;
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
+
 
 /**
  * Title:        Area 3D Ptg - 3D referecnce (Sheet + Area)<P>
@@ -46,8 +48,8 @@ public class Area3DPtg extends Ptg
        private short field_4_first_column;
        private short field_5_last_column;
 
-       private BitField rowRelative = new BitField( 0x8000 );
-       private BitField colRelative = new BitField( 0x4000 );
+       private BitField rowRelative = BitFieldFactory.getInstance( 0x8000 );
+       private BitField colRelative = BitFieldFactory.getInstance( 0x4000 );
 
        /** Creates new AreaPtg */
        public Area3DPtg()
index 2a5aba1b1fbac497c3aa06ee6afc23f02dc085c9..0abc1bc1e380e00c316c9cbf0854fd4d7e7042fb 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
 
 import org.apache.poi.hssf.util.AreaReference;
 import org.apache.poi.hssf.util.CellReference;
@@ -41,9 +42,9 @@ public class AreaPtg
     private short             field_3_first_column;
     private short             field_4_last_column;
     
-    private BitField         rowRelative = new BitField(0x8000);
-    private BitField         colRelative = new BitField(0x4000);
-    private BitField         column      = new BitField(0x3FFF);
+    private BitField         rowRelative = BitFieldFactory.getInstance(0x8000);
+    private BitField         colRelative = BitFieldFactory.getInstance(0x4000);
+    private BitField         column      = BitFieldFactory.getInstance(0x3FFF);
 
     private AreaPtg() {
       //Required for clone methods
index 7033422123e8451a5249e665160ff5826e3acadc..39642a464f2482b7927df1a722161d7a1955442d 100644 (file)
@@ -22,6 +22,7 @@ import org.apache.poi.hssf.record.RecordInputStream;
 
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
 
 import java.util.List;
 
@@ -40,13 +41,13 @@ public class AttrPtg
     private final static int  SIZE = 4;
     private byte              field_1_options;
     private short             field_2_data;
-    private BitField          semiVolatile = new BitField(0x01);
-    private BitField          optiIf       = new BitField(0x02);
-    private BitField          optiChoose   = new BitField(0x04);
-    private BitField          optGoto      = new BitField(0x08);
-    private BitField          sum          = new BitField(0x10);
-    private BitField          baxcel       = new BitField(0x20);
-    private BitField          space        = new BitField(0x40);
+    private BitField          semiVolatile = BitFieldFactory.getInstance(0x01);
+    private BitField          optiIf       = BitFieldFactory.getInstance(0x02);
+    private BitField          optiChoose   = BitFieldFactory.getInstance(0x04);
+    private BitField          optGoto      = BitFieldFactory.getInstance(0x08);
+    private BitField          sum          = BitFieldFactory.getInstance(0x10);
+    private BitField          baxcel       = BitFieldFactory.getInstance(0x20);
+    private BitField          space        = BitFieldFactory.getInstance(0x40);
 
     public AttrPtg() {
     }
index 16f4ff922a12f847a688827ca8a049f338baddd0..a603816550f9cdf5d06fcc400de3bedec6fcf9ad 100644 (file)
@@ -24,6 +24,7 @@ import org.apache.poi.hssf.util.CellReference;
 import org.apache.poi.hssf.util.SheetReferences;
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
@@ -42,8 +43,8 @@ public class Ref3DPtg extends Ptg {
     private short             field_1_index_extern_sheet;
     private short             field_2_row;
     private short             field_3_column;
-    private BitField         rowRelative = new BitField(0x8000);
-    private BitField         colRelative = new BitField(0x4000);
+    private BitField         rowRelative = BitFieldFactory.getInstance(0x8000);
+    private BitField         colRelative = BitFieldFactory.getInstance(0x4000);
 
     /** Creates new AreaPtg */
     public Ref3DPtg() {}
index 35793bfcb11310249ffb310b857a5ecb36deafe8..677327750e32e52c2d3e3c22eb2a4bb042f07176 100644 (file)
@@ -18,6 +18,7 @@ package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
 
 import org.apache.poi.hssf.util.CellReference;
 import org.apache.poi.hssf.model.Workbook;
@@ -36,8 +37,8 @@ public class ReferencePtg extends Ptg
     //public final static byte sid = 0x44;
     private short            field_1_row;
     private short            field_2_col;
-    private BitField         rowRelative = new BitField(0x8000);
-    private BitField         colRelative = new BitField(0x4000);
+    private BitField         rowRelative = BitFieldFactory.getInstance(0x8000);
+    private BitField         colRelative = BitFieldFactory.getInstance(0x4000);
 
     private ReferencePtg() {
       //Required for clone methods
index dd6f7ceb3157a4c46bd73ed0547bc1edce4c7412..c15578610b49a4ad2063f9047d5d3ed8448c4e21 100644 (file)
@@ -18,6 +18,7 @@ package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.StringUtil;
 import org.apache.poi.hssf.record.RecordInputStream;
 
@@ -38,7 +39,7 @@ public class StringPtg
     // Book says something totally different, so dont look there!
     int field_1_length;
     byte field_2_options;
-    BitField fHighByte = new BitField(0x01);
+    BitField fHighByte = BitFieldFactory.getInstance(0x01);
     private String            field_3_string;
 
     private StringPtg() {
index 7d4c950d7b823b79431a07ceb680e5867a63d6a4..41453d3be4f2c8590faeda4cc6cc64d7e89182bf 100644 (file)
@@ -103,6 +103,7 @@ public class HSSFCell
      */
 
     public final static int          CELL_TYPE_ERROR             = 5;
+    public final static short        ENCODING_UNCHANGED          = -1;
     public final static short        ENCODING_COMPRESSED_UNICODE = 0;
     public final static short        ENCODING_UTF_16             = 1;
     private short                    cellNum;
@@ -112,7 +113,7 @@ public class HSSFCell
     private HSSFRichTextString       stringValue;
     private boolean                  booleanValue;
     private byte                     errorValue;
-    private short                    encoding = ENCODING_COMPRESSED_UNICODE;
+    private short                    encoding = ENCODING_UNCHANGED;
     private Workbook                 book;
     private Sheet                    sheet;
     //private short                    row;
@@ -467,19 +468,17 @@ public class HSSFCell
                     {
                         int sst = 0;
 
+                        UnicodeString str = getRichStringCellValue().getUnicodeString();
                         if (encoding == ENCODING_COMPRESSED_UNICODE)
                         {
-                            UnicodeString str = getRichStringCellValue().getUnicodeString();
                             str.setCompressedUnicode();
-                            sst = book.addSSTString(str);
-                        }
-                        if (encoding == ENCODING_UTF_16)
+                        } else if (encoding == ENCODING_UTF_16)
                         {
-                            UnicodeString str = getRichStringCellValue().getUnicodeString();
                             str.setUncompressedUnicode();
-                            sst = book.addSSTString(str);
                         }
+                        sst = book.addSSTString(str);
                         lrec.setSSTIndex(sst);
+                        getRichStringCellValue().setUnicodeString(book.getSSTString(sst));
                     }
                 }
                 record = lrec;
@@ -661,21 +660,19 @@ public class HSSFCell
             }
             int index = 0;
 
+            UnicodeString str = value.getUnicodeString();            
             if (encoding == ENCODING_COMPRESSED_UNICODE)
             {
-                UnicodeString str = value.getUnicodeString();
                 str.setCompressedUnicode();
-                index = book.addSSTString(str);
-            }
-            if (encoding == ENCODING_UTF_16)
+            } else if (encoding == ENCODING_UTF_16)
             {
-                UnicodeString str = value.getUnicodeString();
                 str.setUncompressedUnicode();
-                index = book.addSSTString(str);
             }
+            index = book.addSSTString(str);            
             (( LabelSSTRecord ) record).setSSTIndex(index);
             stringValue = value;
             stringValue.setWorkbookReferences(book, (( LabelSSTRecord ) record));
+            stringValue.setUnicodeString(book.getSSTString(index));            
         }
     }
 
@@ -924,14 +921,14 @@ public class HSSFCell
     }
 
     /**
-     * used for internationalization, currently 0 for compressed unicode or 1 for 16-bit
+     * used for internationalization, currently -1 for unchanged, 0 for compressed unicode or 1 for 16-bit
      *
+     * @see #ENCODING_UNCHANGED
      * @see #ENCODING_COMPRESSED_UNICODE
      * @see #ENCODING_UTF_16
      *
-     * @return 1 or 0 for compressed or uncompressed (used only with String type)
+     * @return -1, 1 or 0 for unchanged, compressed or uncompressed (used only with String type)
      */
-
     public short getEncoding()
     {
         return encoding;
@@ -940,6 +937,7 @@ public class HSSFCell
     /**
      * set the encoding to either 8 or 16 bit. (US/UK use 8-bit, rest of the western world use 16bit)
      *
+     * @see #ENCODING_UNCHANGED
      * @see #ENCODING_COMPRESSED_UNICODE
      * @see #ENCODING_UTF_16
      *
index 29d87cd72fdb23ed6ccbfa6311eaa97060ffd4bd..9c45ab1a7ff5be68afcf43cf85f59b5a9cf85cc5 100644 (file)
@@ -77,7 +77,11 @@ public class HSSFRichTextString
 
     private void addToSSTIfRequired() {
       if (book != null) {
-        record.setSSTIndex(book.addSSTString(string));
+        int index = book.addSSTString(string);
+        record.setSSTIndex(index);
+        //The act of adding the string to the SST record may have meant that
+        //a extsing string was returned for the index, so update our local version
+        string = book.getSSTString(index);
       }
     }
 
@@ -162,10 +166,17 @@ public class HSSFRichTextString
         return string.getString();
     }
 
+    /** Used internally by the HSSFCell to get the internal string value*/
     UnicodeString getUnicodeString() {
       return cloneStringIfRequired();
     }
 
+    /** Used internally by the HSSFCell to set the internal string value*/
+    void setUnicodeString(UnicodeString str) {
+      this.string = str;
+    }
+    
+
     /**
      * @return  the number of characters in the font.
      */
@@ -240,6 +251,14 @@ public class HSSFRichTextString
        return string.compareTo(r.string);
     }
 
+    public boolean equals(Object o) {
+      if (o instanceof HSSFRichTextString) {
+        return string.equals(((HSSFRichTextString)o).string);
+      }
+      return false;
+    
+    }
+
     /**
      * @return  the plain text representation of this string.
      */