From b0f692b92c5e7a76cbfab7b14d0017de3e3dcbfa Mon Sep 17 00:00:00 2001 From: Jason Height Date: Fri, 2 Sep 2005 03:48:31 +0000 Subject: [PATCH] Performance and memory improvements: 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 --- src/java/org/apache/poi/hssf/model/Sheet.java | 6 ++ .../org/apache/poi/hssf/model/Workbook.java | 1 + .../poi/hssf/record/AreaFormatRecord.java | 4 +- .../apache/poi/hssf/record/AreaRecord.java | 6 +- .../poi/hssf/record/AxisOptionsRecord.java | 16 ++--- .../org/apache/poi/hssf/record/BarRecord.java | 8 +-- .../hssf/record/CategorySeriesAxisRecord.java | 6 +- .../poi/hssf/record/ChartFormatRecord.java | 3 +- .../poi/hssf/record/ColumnInfoRecord.java | 7 +- .../record/CommonObjectDataSubRecord.java | 8 +-- .../org/apache/poi/hssf/record/DatRecord.java | 8 +-- .../poi/hssf/record/DataFormatRecord.java | 2 +- .../poi/hssf/record/ExtendedFormatRecord.java | 69 ++++++++++--------- .../apache/poi/hssf/record/FontRecord.java | 9 +-- .../apache/poi/hssf/record/FrameRecord.java | 4 +- .../apache/poi/hssf/record/LegendRecord.java | 12 ++-- .../poi/hssf/record/LineFormatRecord.java | 6 +- .../poi/hssf/record/LinkedDataRecord.java | 2 +- .../poi/hssf/record/PrintSetupRecord.java | 17 ++--- .../org/apache/poi/hssf/record/RowRecord.java | 11 +-- .../poi/hssf/record/SeriesLabelsRecord.java | 12 ++-- .../hssf/record/SheetPropertiesRecord.java | 10 +-- .../apache/poi/hssf/record/StyleRecord.java | 3 +- .../poi/hssf/record/TextObjectBaseRecord.java | 12 ++-- .../poi/hssf/record/TextObjectRecord.java | 8 ++- .../apache/poi/hssf/record/TextRecord.java | 28 ++++---- .../apache/poi/hssf/record/TickRecord.java | 8 +-- .../poi/hssf/record/ValueRangeRecord.java | 18 ++--- .../apache/poi/hssf/record/WSBoolRecord.java | 19 ++--- .../poi/hssf/record/WindowOneRecord.java | 13 ++-- .../poi/hssf/record/WindowTwoRecord.java | 25 +++---- .../poi/hssf/record/formula/Area3DPtg.java | 6 +- .../poi/hssf/record/formula/AreaPtg.java | 7 +- .../poi/hssf/record/formula/AttrPtg.java | 15 ++-- .../poi/hssf/record/formula/Ref3DPtg.java | 5 +- .../poi/hssf/record/formula/ReferencePtg.java | 5 +- .../poi/hssf/record/formula/StringPtg.java | 3 +- .../apache/poi/hssf/usermodel/HSSFCell.java | 30 ++++---- .../hssf/usermodel/HSSFRichTextString.java | 21 +++++- 39 files changed, 249 insertions(+), 204 deletions(-) diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index 222972716..34f0e9d88 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -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); /* diff --git a/src/java/org/apache/poi/hssf/model/Workbook.java b/src/java/org/apache/poi/hssf/model/Workbook.java index 4bc93eb96..ad2b9e27a 100644 --- a/src/java/org/apache/poi/hssf/model/Workbook.java +++ b/src/java/org/apache/poi/hssf/model/Workbook.java @@ -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); diff --git a/src/java/org/apache/poi/hssf/record/AreaFormatRecord.java b/src/java/org/apache/poi/hssf/record/AreaFormatRecord.java index cdcfeab94..4067dd2e4 100644 --- a/src/java/org/apache/poi/hssf/record/AreaFormatRecord.java +++ b/src/java/org/apache/poi/hssf/record/AreaFormatRecord.java @@ -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; diff --git a/src/java/org/apache/poi/hssf/record/AreaRecord.java b/src/java/org/apache/poi/hssf/record/AreaRecord.java index 9278293bb..8282ce2de 100644 --- a/src/java/org/apache/poi/hssf/record/AreaRecord.java +++ b/src/java/org/apache/poi/hssf/record/AreaRecord.java @@ -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() diff --git a/src/java/org/apache/poi/hssf/record/AxisOptionsRecord.java b/src/java/org/apache/poi/hssf/record/AxisOptionsRecord.java index e1b4a7725..03eede06b 100644 --- a/src/java/org/apache/poi/hssf/record/AxisOptionsRecord.java +++ b/src/java/org/apache/poi/hssf/record/AxisOptionsRecord.java @@ -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() diff --git a/src/java/org/apache/poi/hssf/record/BarRecord.java b/src/java/org/apache/poi/hssf/record/BarRecord.java index 77038ca00..5411581cb 100644 --- a/src/java/org/apache/poi/hssf/record/BarRecord.java +++ b/src/java/org/apache/poi/hssf/record/BarRecord.java @@ -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() diff --git a/src/java/org/apache/poi/hssf/record/CategorySeriesAxisRecord.java b/src/java/org/apache/poi/hssf/record/CategorySeriesAxisRecord.java index 4f4c236c0..c305ac66a 100644 --- a/src/java/org/apache/poi/hssf/record/CategorySeriesAxisRecord.java +++ b/src/java/org/apache/poi/hssf/record/CategorySeriesAxisRecord.java @@ -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() diff --git a/src/java/org/apache/poi/hssf/record/ChartFormatRecord.java b/src/java/org/apache/poi/hssf/record/ChartFormatRecord.java index 658d98bd7..2b22c64a7 100644 --- a/src/java/org/apache/poi/hssf/record/ChartFormatRecord.java +++ b/src/java/org/apache/poi/hssf/record/ChartFormatRecord.java @@ -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() { diff --git a/src/java/org/apache/poi/hssf/record/ColumnInfoRecord.java b/src/java/org/apache/poi/hssf/record/ColumnInfoRecord.java index edd3a000f..c141a356e 100644 --- a/src/java/org/apache/poi/hssf/record/ColumnInfoRecord.java +++ b/src/java/org/apache/poi/hssf/record/ColumnInfoRecord.java @@ -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

@@ -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() diff --git a/src/java/org/apache/poi/hssf/record/CommonObjectDataSubRecord.java b/src/java/org/apache/poi/hssf/record/CommonObjectDataSubRecord.java index 105bd86f5..aa68c8a2f 100644 --- a/src/java/org/apache/poi/hssf/record/CommonObjectDataSubRecord.java +++ b/src/java/org/apache/poi/hssf/record/CommonObjectDataSubRecord.java @@ -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; diff --git a/src/java/org/apache/poi/hssf/record/DatRecord.java b/src/java/org/apache/poi/hssf/record/DatRecord.java index 223f936b1..182142826 100644 --- a/src/java/org/apache/poi/hssf/record/DatRecord.java +++ b/src/java/org/apache/poi/hssf/record/DatRecord.java @@ -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() diff --git a/src/java/org/apache/poi/hssf/record/DataFormatRecord.java b/src/java/org/apache/poi/hssf/record/DataFormatRecord.java index c605186aa..5f6ee27a0 100644 --- a/src/java/org/apache/poi/hssf/record/DataFormatRecord.java +++ b/src/java/org/apache/poi/hssf/record/DataFormatRecord.java @@ -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() diff --git a/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java b/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java index f7d0226ac..e19d89480 100644 --- a/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java +++ b/src/java/org/apache/poi/hssf/record/ExtendedFormatRecord.java @@ -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; diff --git a/src/java/org/apache/poi/hssf/record/FontRecord.java b/src/java/org/apache/poi/hssf/record/FontRecord.java index 0c7021a67..8c0100893 100644 --- a/src/java/org/apache/poi/hssf/record/FontRecord.java +++ b/src/java/org/apache/poi/hssf/record/FontRecord.java @@ -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)

@@ -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 diff --git a/src/java/org/apache/poi/hssf/record/FrameRecord.java b/src/java/org/apache/poi/hssf/record/FrameRecord.java index 7345c3643..48e6bb430 100644 --- a/src/java/org/apache/poi/hssf/record/FrameRecord.java +++ b/src/java/org/apache/poi/hssf/record/FrameRecord.java @@ -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() diff --git a/src/java/org/apache/poi/hssf/record/LegendRecord.java b/src/java/org/apache/poi/hssf/record/LegendRecord.java index 55d99c57e..7f402e2aa 100644 --- a/src/java/org/apache/poi/hssf/record/LegendRecord.java +++ b/src/java/org/apache/poi/hssf/record/LegendRecord.java @@ -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() diff --git a/src/java/org/apache/poi/hssf/record/LineFormatRecord.java b/src/java/org/apache/poi/hssf/record/LineFormatRecord.java index e49082d88..756f81b7b 100644 --- a/src/java/org/apache/poi/hssf/record/LineFormatRecord.java +++ b/src/java/org/apache/poi/hssf/record/LineFormatRecord.java @@ -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; diff --git a/src/java/org/apache/poi/hssf/record/LinkedDataRecord.java b/src/java/org/apache/poi/hssf/record/LinkedDataRecord.java index 5b0a3bc6f..20a64fe0e 100644 --- a/src/java/org/apache/poi/hssf/record/LinkedDataRecord.java +++ b/src/java/org/apache/poi/hssf/record/LinkedDataRecord.java @@ -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; diff --git a/src/java/org/apache/poi/hssf/record/PrintSetupRecord.java b/src/java/org/apache/poi/hssf/record/PrintSetupRecord.java index dc6abd493..c7ee3d06e 100644 --- a/src/java/org/apache/poi/hssf/record/PrintSetupRecord.java +++ b/src/java/org/apache/poi/hssf/record/PrintSetupRecord.java @@ -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

@@ -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; diff --git a/src/java/org/apache/poi/hssf/record/RowRecord.java b/src/java/org/apache/poi/hssf/record/RowRecord.java index d30e03c41..73aa1db6a 100644 --- a/src/java/org/apache/poi/hssf/record/RowRecord.java +++ b/src/java/org/apache/poi/hssf/record/RowRecord.java @@ -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() diff --git a/src/java/org/apache/poi/hssf/record/SeriesLabelsRecord.java b/src/java/org/apache/poi/hssf/record/SeriesLabelsRecord.java index 1b7f12b05..762175654 100644 --- a/src/java/org/apache/poi/hssf/record/SeriesLabelsRecord.java +++ b/src/java/org/apache/poi/hssf/record/SeriesLabelsRecord.java @@ -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() diff --git a/src/java/org/apache/poi/hssf/record/SheetPropertiesRecord.java b/src/java/org/apache/poi/hssf/record/SheetPropertiesRecord.java index 9676d3210..94c857bda 100644 --- a/src/java/org/apache/poi/hssf/record/SheetPropertiesRecord.java +++ b/src/java/org/apache/poi/hssf/record/SheetPropertiesRecord.java @@ -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; diff --git a/src/java/org/apache/poi/hssf/record/StyleRecord.java b/src/java/org/apache/poi/hssf/record/StyleRecord.java index aa7503012..0779e036b 100644 --- a/src/java/org/apache/poi/hssf/record/StyleRecord.java +++ b/src/java/org/apache/poi/hssf/record/StyleRecord.java @@ -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

@@ -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) diff --git a/src/java/org/apache/poi/hssf/record/TextObjectBaseRecord.java b/src/java/org/apache/poi/hssf/record/TextObjectBaseRecord.java index 1232efd43..b27fbf68a 100644 --- a/src/java/org/apache/poi/hssf/record/TextObjectBaseRecord.java +++ b/src/java/org/apache/poi/hssf/record/TextObjectBaseRecord.java @@ -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; diff --git a/src/java/org/apache/poi/hssf/record/TextObjectRecord.java b/src/java/org/apache/poi/hssf/record/TextObjectRecord.java index b9cdca30e..b11f6d574 100644 --- a/src/java/org/apache/poi/hssf/record/TextObjectRecord.java +++ b/src/java/org/apache/poi/hssf/record/TextObjectRecord.java @@ -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"); + } } diff --git a/src/java/org/apache/poi/hssf/record/TextRecord.java b/src/java/org/apache/poi/hssf/record/TextRecord.java index 1bddd1538..e15be8c34 100644 --- a/src/java/org/apache/poi/hssf/record/TextRecord.java +++ b/src/java/org/apache/poi/hssf/record/TextRecord.java @@ -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; diff --git a/src/java/org/apache/poi/hssf/record/TickRecord.java b/src/java/org/apache/poi/hssf/record/TickRecord.java index b6b3ec0a2..0e4b4d3f0 100644 --- a/src/java/org/apache/poi/hssf/record/TickRecord.java +++ b/src/java/org/apache/poi/hssf/record/TickRecord.java @@ -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; diff --git a/src/java/org/apache/poi/hssf/record/ValueRangeRecord.java b/src/java/org/apache/poi/hssf/record/ValueRangeRecord.java index 290b0517f..353f669d9 100644 --- a/src/java/org/apache/poi/hssf/record/ValueRangeRecord.java +++ b/src/java/org/apache/poi/hssf/record/ValueRangeRecord.java @@ -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() diff --git a/src/java/org/apache/poi/hssf/record/WSBoolRecord.java b/src/java/org/apache/poi/hssf/record/WSBoolRecord.java index db7bbfd53..d5fedd457 100644 --- a/src/java/org/apache/poi/hssf/record/WSBoolRecord.java +++ b/src/java/org/apache/poi/hssf/record/WSBoolRecord.java @@ -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() { diff --git a/src/java/org/apache/poi/hssf/record/WindowOneRecord.java b/src/java/org/apache/poi/hssf/record/WindowOneRecord.java index b8d720bcd..e8482d0d9 100644 --- a/src/java/org/apache/poi/hssf/record/WindowOneRecord.java +++ b/src/java/org/apache/poi/hssf/record/WindowOneRecord.java @@ -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; diff --git a/src/java/org/apache/poi/hssf/record/WindowTwoRecord.java b/src/java/org/apache/poi/hssf/record/WindowTwoRecord.java index 8224629da..335ab1dd7 100644 --- a/src/java/org/apache/poi/hssf/record/WindowTwoRecord.java +++ b/src/java/org/apache/poi/hssf/record/WindowTwoRecord.java @@ -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 diff --git a/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java b/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java index 395c6a784..d5ffe3ee5 100644 --- a/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java @@ -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)

@@ -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() diff --git a/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java b/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java index 2a5aba1b1..0abc1bc1e 100644 --- a/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java @@ -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 diff --git a/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java b/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java index 703342212..39642a464 100644 --- a/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java @@ -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() { } diff --git a/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java b/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java index 16f4ff922..a60381655 100644 --- a/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java @@ -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() {} diff --git a/src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java b/src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java index 35793bfcb..677327750 100644 --- a/src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java @@ -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 diff --git a/src/java/org/apache/poi/hssf/record/formula/StringPtg.java b/src/java/org/apache/poi/hssf/record/formula/StringPtg.java index dd6f7ceb3..c15578610 100644 --- a/src/java/org/apache/poi/hssf/record/formula/StringPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/StringPtg.java @@ -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() { diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java index 7d4c950d7..41453d3be 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java @@ -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 * diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java b/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java index 29d87cd72..9c45ab1a7 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java @@ -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. */