You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2019/12/22 21:44:48 UTC
svn commit: r1871911 [2/15] - in /poi/trunk/src:
integrationtest/org/apache/poi/
integrationtest/org/apache/poi/hssf/usermodel/ java/org/apache/poi/common/
java/org/apache/poi/ddf/
java/org/apache/poi/hssf/eventusermodel/dummyrecord/ java/org/apache/po...
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CFHeaderBase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CFHeaderBase.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CFHeaderBase.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CFHeaderBase.java Sun Dec 22 21:44:45 2019
@@ -21,20 +21,28 @@ import org.apache.poi.ss.util.CellRangeA
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.ss.util.CellRangeUtil;
import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.Removal;
/**
* Parent of Conditional Formatting Header records,
* {@link CFHeaderRecord} and {@link CFHeader12Record}.
*/
-public abstract class CFHeaderBase extends StandardRecord implements Cloneable {
+public abstract class CFHeaderBase extends StandardRecord {
private int field_1_numcf;
private int field_2_need_recalculation_and_id;
private CellRangeAddress field_3_enclosing_cell_range;
private CellRangeAddressList field_4_cell_ranges;
- /** Creates new CFHeaderBase */
- protected CFHeaderBase() {
+ protected CFHeaderBase() {}
+
+ protected CFHeaderBase(CFHeaderBase other) {
+ super(other);
+ field_1_numcf = other.field_1_numcf;
+ field_2_need_recalculation_and_id = other.field_2_need_recalculation_and_id;
+ field_3_enclosing_cell_range = other.field_3_enclosing_cell_range.copy();
+ field_4_cell_ranges = other.field_4_cell_ranges.copy();
}
+
protected CFHeaderBase(CellRangeAddress[] regions, int nRules) {
CellRangeAddress[] mergeCellRanges = CellRangeUtil.mergeCellRanges(regions);
setCellRanges(mergeCellRanges);
@@ -97,7 +105,7 @@ public abstract class CFHeaderBase exten
}
/**
- * Set cell ranges list to a single cell range and
+ * Set cell ranges list to a single cell range and
* modify the enclosing cell range accordingly.
* @param cellRanges - list of CellRange objects
*/
@@ -151,13 +159,12 @@ public abstract class CFHeaderBase exten
field_4_cell_ranges.serialize(out);
}
- protected void copyTo(CFHeaderBase result) {
- result.field_1_numcf = field_1_numcf;
- result.field_2_need_recalculation_and_id = field_2_need_recalculation_and_id;
- result.field_3_enclosing_cell_range = field_3_enclosing_cell_range.copy();
- result.field_4_cell_ranges = field_4_cell_ranges.copy();
- }
+ @Override
+ @SuppressWarnings("squid:S2975")
+ @Deprecated
+ @Removal(version = "5.0.0")
+ public abstract CFHeaderBase clone();
@Override
- public abstract CFHeaderBase clone(); // NOSONAR
+ public abstract CFHeaderBase copy();
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java Sun Dec 22 21:44:45 2019
@@ -18,19 +18,24 @@
package org.apache.poi.hssf.record;
import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.util.Removal;
/**
* Conditional Formatting Header record CFHEADER (0x01B0).
* Used to describe a {@link CFRuleRecord}.
* @see CFHeader12Record
*/
-public final class CFHeaderRecord extends CFHeaderBase implements Cloneable {
+public final class CFHeaderRecord extends CFHeaderBase {
public static final short sid = 0x01B0;
- /** Creates new CFHeaderRecord */
public CFHeaderRecord() {
createEmpty();
}
+
+ public CFHeaderRecord(CFHeaderRecord other) {
+ super(other);
+ }
+
public CFHeaderRecord(CellRangeAddress[] regions, int nRules) {
super(regions, nRules);
}
@@ -48,9 +53,15 @@ public final class CFHeaderRecord extend
}
@Override
+ @SuppressWarnings("squid:S2975")
+ @Deprecated
+ @Removal(version = "5.0.0")
public CFHeaderRecord clone() {
- CFHeaderRecord result = new CFHeaderRecord();
- super.copyTo(result);
- return result;
+ return copy();
+ }
+
+ @Override
+ public CFHeaderRecord copy() {
+ return new CFHeaderRecord(this);
}
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CFRule12Record.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CFRule12Record.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CFRule12Record.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CFRule12Record.java Sun Dec 22 21:44:45 2019
@@ -39,18 +39,19 @@ import org.apache.poi.util.HexDump;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndianOutput;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Removal;
/**
- * Conditional Formatting v12 Rule Record (0x087A).
- *
+ * Conditional Formatting v12 Rule Record (0x087A).
+ *
* <p>This is for newer-style Excel conditional formattings,
* from Excel 2007 onwards.
- *
+ *
* <p>{@link CFRuleRecord} is used where the condition type is
* {@link #CONDITION_TYPE_CELL_VALUE_IS} or {@link #CONDITION_TYPE_FORMULA},
* this is only used for the other types
*/
-public final class CFRule12Record extends CFRuleBase implements FutureRecord, Cloneable {
+public final class CFRule12Record extends CFRuleBase implements FutureRecord {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
@@ -66,14 +67,35 @@ public final class CFRule12Record extend
private int template_type;
private byte template_param_length;
private byte[] template_params;
-
+
private DataBarFormatting data_bar;
private IconMultiStateFormatting multistate;
private ColorGradientFormatting color_gradient;
// TODO Parse this, see #58150
private byte[] filter_data;
- /** Creates new CFRuleRecord */
+ public CFRule12Record(CFRule12Record other) {
+ super(other);
+ futureHeader = (other.futureHeader == null) ? null : other.futureHeader.copy();
+
+ // use min() to gracefully handle cases where the length-property and the array-length do not match
+ // we saw some such files in circulation
+ ext_formatting_length = Math.min(other.ext_formatting_length, other.ext_formatting_data.length);
+ ext_formatting_data = other.ext_formatting_data.clone();
+
+ formula_scale = other.formula_scale.copy();
+
+ ext_opts = other.ext_opts;
+ priority = other.priority;
+ template_type = other.template_type;
+ template_param_length = other.template_param_length;
+ template_params = (other.template_params == null) ? null : other.template_params.clone();
+ color_gradient = (other.color_gradient == null) ? null : other.color_gradient.copy();
+ multistate = (other.multistate == null) ? null : other.multistate.copy();
+ data_bar = (other.data_bar == null) ? null : other.data_bar.copy();
+ filter_data = (other.filter_data == null) ? null : other.filter_data.clone();
+ }
+
private CFRule12Record(byte conditionType, byte comparisonOperation) {
super(conditionType, comparisonOperation);
setDefaults();
@@ -84,15 +106,17 @@ public final class CFRule12Record extend
setDefaults();
this.formula_scale = Formula.create(formulaScale);
}
+
+
private void setDefaults() {
futureHeader = new FtrHeader();
futureHeader.setRecordType(sid);
-
+
ext_formatting_length = 0;
ext_formatting_data = new byte[4];
-
+
formula_scale = Formula.create(Ptg.EMPTY_PTG_ARRAY);
-
+
ext_opts = 0;
priority = 0;
template_type = getConditionType();
@@ -102,10 +126,10 @@ public final class CFRule12Record extend
/**
* Creates a new comparison operation rule
- *
+ *
* @param sheet the sheet
* @param formulaText the first formula text
- *
+ *
* @return a new comparison operation rule
*/
public static CFRule12Record create(HSSFSheet sheet, String formulaText) {
@@ -113,34 +137,34 @@ public final class CFRule12Record extend
return new CFRule12Record(CONDITION_TYPE_FORMULA, ComparisonOperator.NO_COMPARISON,
formula1, null, null);
}
-
+
/**
* Creates a new comparison operation rule
- *
+ *
* @param sheet the sheet
* @param comparisonOperation the comparison operation
* @param formulaText1 the first formula text
* @param formulaText2 the second formula text
- *
+ *
* @return a new comparison operation rule
*/
public static CFRule12Record create(HSSFSheet sheet, byte comparisonOperation,
String formulaText1, String formulaText2) {
Ptg[] formula1 = parseFormula(formulaText1, sheet);
Ptg[] formula2 = parseFormula(formulaText2, sheet);
- return new CFRule12Record(CONDITION_TYPE_CELL_VALUE_IS, comparisonOperation,
+ return new CFRule12Record(CONDITION_TYPE_CELL_VALUE_IS, comparisonOperation,
formula1, formula2, null);
}
-
+
/**
* Creates a new comparison operation rule
- *
+ *
* @param sheet the sheet
* @param comparisonOperation the comparison operation
* @param formulaText1 the first formula text
* @param formulaText2 the second formula text
* @param formulaTextScale the scale to apply for the comparison
- *
+ *
* @return a new comparison operation rule
*/
public static CFRule12Record create(HSSFSheet sheet, byte comparisonOperation,
@@ -148,43 +172,43 @@ public final class CFRule12Record extend
Ptg[] formula1 = parseFormula(formulaText1, sheet);
Ptg[] formula2 = parseFormula(formulaText2, sheet);
Ptg[] formula3 = parseFormula(formulaTextScale, sheet);
- return new CFRule12Record(CONDITION_TYPE_CELL_VALUE_IS, comparisonOperation,
+ return new CFRule12Record(CONDITION_TYPE_CELL_VALUE_IS, comparisonOperation,
formula1, formula2, formula3);
}
-
+
/**
* Creates a new Data Bar formatting
- *
+ *
* @param sheet the sheet
* @param color the data bar color
- *
+ *
* @return a new Data Bar formatting
*/
public static CFRule12Record create(HSSFSheet sheet, ExtendedColor color) {
- CFRule12Record r = new CFRule12Record(CONDITION_TYPE_DATA_BAR,
+ CFRule12Record r = new CFRule12Record(CONDITION_TYPE_DATA_BAR,
ComparisonOperator.NO_COMPARISON);
DataBarFormatting dbf = r.createDataBarFormatting();
dbf.setColor(color);
dbf.setPercentMin((byte)0);
dbf.setPercentMax((byte)100);
-
+
DataBarThreshold min = new DataBarThreshold();
min.setType(RangeType.MIN.id);
dbf.setThresholdMin(min);
-
+
DataBarThreshold max = new DataBarThreshold();
max.setType(RangeType.MAX.id);
dbf.setThresholdMax(max);
-
+
return r;
}
-
+
/**
* Creates a new Icon Set / Multi-State formatting
- *
+ *
* @param sheet the sheet
* @param iconSet the icon set
- *
+ *
* @return a new Icon Set / Multi-State formatting
*/
public static CFRule12Record create(HSSFSheet sheet, IconSet iconSet) {
@@ -192,20 +216,20 @@ public final class CFRule12Record extend
for (int i=0; i<ts.length; i++) {
ts[i] = new IconMultiStateThreshold();
}
-
- CFRule12Record r = new CFRule12Record(CONDITION_TYPE_ICON_SET,
+
+ CFRule12Record r = new CFRule12Record(CONDITION_TYPE_ICON_SET,
ComparisonOperator.NO_COMPARISON);
IconMultiStateFormatting imf = r.createMultiStateFormatting();
imf.setIconSet(iconSet);
imf.setThresholds(ts);
return r;
}
-
+
/**
* Creates a new Color Scale / Color Gradient formatting
- *
+ *
* @param sheet the sheet
- *
+ *
* @return a new Color Scale / Color Gradient formatting
*/
public static CFRule12Record createColorScale(HSSFSheet sheet) {
@@ -216,8 +240,8 @@ public final class CFRule12Record extend
ts[i] = new ColorGradientThreshold();
colors[i] = new ExtendedColor();
}
-
- CFRule12Record r = new CFRule12Record(CONDITION_TYPE_COLOR_SCALE,
+
+ CFRule12Record r = new CFRule12Record(CONDITION_TYPE_COLOR_SCALE,
ComparisonOperator.NO_COMPARISON);
ColorGradientFormatting cgf = r.createColorGradientFormatting();
cgf.setNumControlPoints(numPoints);
@@ -232,7 +256,7 @@ public final class CFRule12Record extend
setComparisonOperation(in.readByte());
int field_3_formula1_len = in.readUShort();
int field_4_formula2_len = in.readUShort();
-
+
ext_formatting_length = in.readInt();
ext_formatting_data = new byte[0];
if (ext_formatting_length == 0) {
@@ -245,13 +269,13 @@ public final class CFRule12Record extend
in.readFully(ext_formatting_data);
}
}
-
+
setFormula1(Formula.read(field_3_formula1_len, in));
setFormula2(Formula.read(field_4_formula2_len, in));
-
+
int formula_scale_len = in.readUShort();
formula_scale = Formula.read(formula_scale_len, in);
-
+
ext_opts = in.readByte();
priority = in.readUShort();
template_type = in.readUShort();
@@ -263,7 +287,7 @@ public final class CFRule12Record extend
logger.log(POILogger.WARN, "CF Rule v12 template params length should be 0 or 16, found " + template_param_length);
in.readRemainder();
}
-
+
byte type = getConditionType();
if (type == CONDITION_TYPE_COLOR_SCALE) {
color_gradient = new ColorGradientFormatting(in);
@@ -275,7 +299,7 @@ public final class CFRule12Record extend
multistate = new IconMultiStateFormatting(in);
}
}
-
+
public boolean containsDataBarBlock() {
return (data_bar != null);
}
@@ -284,7 +308,7 @@ public final class CFRule12Record extend
}
public DataBarFormatting createDataBarFormatting() {
if (data_bar != null) return data_bar;
-
+
// Convert, setup and return
setConditionType(CONDITION_TYPE_DATA_BAR);
data_bar = new DataBarFormatting();
@@ -299,7 +323,7 @@ public final class CFRule12Record extend
}
public IconMultiStateFormatting createMultiStateFormatting() {
if (multistate != null) return multistate;
-
+
// Convert, setup and return
setConditionType(CONDITION_TYPE_ICON_SET);
multistate = new IconMultiStateFormatting();
@@ -314,7 +338,7 @@ public final class CFRule12Record extend
}
public ColorGradientFormatting createColorGradientFormatting() {
if (color_gradient != null) return color_gradient;
-
+
// Convert, setup and return
setConditionType(CONDITION_TYPE_COLOR_SCALE);
color_gradient = new ColorGradientFormatting();
@@ -356,7 +380,7 @@ public final class CFRule12Record extend
*/
public void serialize(LittleEndianOutput out) {
futureHeader.serialize(out);
-
+
int formula1Len=getFormulaSize(getFormula1());
int formula2Len=getFormulaSize(getFormula2());
@@ -364,7 +388,7 @@ public final class CFRule12Record extend
out.writeByte(getComparisonOperation());
out.writeShort(formula1Len);
out.writeShort(formula2Len);
-
+
// TODO Update ext_formatting_length
if (ext_formatting_length == 0) {
out.writeInt(0);
@@ -374,18 +398,18 @@ public final class CFRule12Record extend
serializeFormattingBlock(out);
out.write(ext_formatting_data);
}
-
+
getFormula1().serializeTokens(out);
getFormula2().serializeTokens(out);
out.writeShort(getFormulaSize(formula_scale));
formula_scale.serializeTokens(out);
-
+
out.writeByte(ext_opts);
out.writeShort(priority);
out.writeShort(template_type);
out.writeByte(template_param_length);
out.write(template_params);
-
+
byte type = getConditionType();
if (type == CONDITION_TYPE_COLOR_SCALE) {
color_gradient.serialize(out);
@@ -409,7 +433,7 @@ public final class CFRule12Record extend
len += getFormulaSize(getFormula2());
len += 2 + getFormulaSize(formula_scale);
len += 6 + template_params.length;
-
+
byte type = getConditionType();
if (type == CONDITION_TYPE_COLOR_SCALE) {
len += color_gradient.getDataLength();
@@ -461,44 +485,18 @@ public final class CFRule12Record extend
}
@Override
+ @SuppressWarnings("squid:S2975")
+ @Deprecated
+ @Removal(version = "5.0.0")
public CFRule12Record clone() {
- CFRule12Record rec = new CFRule12Record(getConditionType(), getComparisonOperation());
- rec.futureHeader.setAssociatedRange(futureHeader.getAssociatedRange().copy());
-
- super.copyTo(rec);
-
- // use min() to gracefully handle cases where the length-property and the array-length do not match
- // we saw some such files in circulation
- rec.ext_formatting_length = Math.min(ext_formatting_length, ext_formatting_data.length);
- rec.ext_formatting_data = IOUtils.safelyAllocate(ext_formatting_length, MAX_RECORD_LENGTH);
- System.arraycopy(ext_formatting_data, 0, rec.ext_formatting_data, 0, rec.ext_formatting_length);
-
- rec.formula_scale = formula_scale.copy();
-
- rec.ext_opts = ext_opts;
- rec.priority = priority;
- rec.template_type = template_type;
- rec.template_param_length = template_param_length;
- rec.template_params = IOUtils.safelyAllocate(template_param_length, MAX_RECORD_LENGTH);
- System.arraycopy(template_params, 0, rec.template_params, 0, template_param_length);
+ return copy();
+ }
- if (color_gradient != null) {
- rec.color_gradient = (ColorGradientFormatting)color_gradient.clone();
- }
- if (multistate != null) {
- rec.multistate = (IconMultiStateFormatting)multistate.clone();
- }
- if (data_bar != null) {
- rec.data_bar = (DataBarFormatting)data_bar.clone();
- }
- if (filter_data != null) {
- rec.filter_data = IOUtils.safelyAllocate(filter_data.length, MAX_RECORD_LENGTH);
- System.arraycopy(filter_data, 0, rec.filter_data, 0, filter_data.length);
- }
-
- return rec;
+ @Override
+ public CFRule12Record copy() {
+ return new CFRule12Record(this);
}
-
+
public short getFutureRecordType() {
return futureHeader.getRecordType();
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleBase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleBase.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleBase.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleBase.java Sun Dec 22 21:44:45 2019
@@ -30,32 +30,31 @@ import org.apache.poi.util.BitFieldFacto
import org.apache.poi.util.LittleEndianOutput;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Removal;
/**
* Conditional Formatting Rules. This can hold old-style rules
- *
- *
+ *
+ *
* <p>This is for the older-style Excel conditional formattings,
* new-style (Excel 2007+) also make use of {@link CFRule12Record}
* for their rules.</p>
*/
-public abstract class CFRuleBase extends StandardRecord implements Cloneable {
+public abstract class CFRuleBase extends StandardRecord {
// FIXME: Merge with org.apache.poi.ss.usermodel.ComparisonOperator and rewrite as an enum
- public static final class ComparisonOperator {
- public static final byte NO_COMPARISON = 0;
- public static final byte BETWEEN = 1;
- public static final byte NOT_BETWEEN = 2;
- public static final byte EQUAL = 3;
- public static final byte NOT_EQUAL = 4;
- public static final byte GT = 5;
- public static final byte LT = 6;
- public static final byte GE = 7;
- public static final byte LE = 8;
- private static final byte max_operator = 8;
+ public interface ComparisonOperator {
+ byte NO_COMPARISON = 0;
+ byte BETWEEN = 1;
+ byte NOT_BETWEEN = 2;
+ byte EQUAL = 3;
+ byte NOT_EQUAL = 4;
+ byte GT = 5;
+ byte LT = 6;
+ byte GE = 7;
+ byte LE = 8;
+ byte max_operator = 8;
}
- protected static final POILogger logger = POILogFactory.getLogger(CFRuleBase.class);
- private byte condition_type;
// The only kinds that CFRuleRecord handles
public static final byte CONDITION_TYPE_CELL_VALUE_IS = 1;
public static final byte CONDITION_TYPE_FORMULA = 2;
@@ -65,8 +64,6 @@ public abstract class CFRuleBase extends
public static final byte CONDITION_TYPE_FILTER = 5;
public static final byte CONDITION_TYPE_ICON_SET = 6;
- private byte comparison_operator;
-
public static final int TEMPLATE_CELL_VALUE = 0x0000;
public static final int TEMPLATE_FORMULA = 0x0001;
public static final int TEMPLATE_COLOR_SCALE_FORMATTING = 0x0002;
@@ -94,7 +91,9 @@ public abstract class CFRuleBase extends
public static final int TEMPLATE_DUPLICATE_VALUES = 0x001B;
public static final int TEMPLATE_ABOVE_OR_EQUAL_TO_AVERAGE = 0x001D;
public static final int TEMPLATE_BELOW_OR_EQUAL_TO_AVERAGE = 0x001E;
-
+
+ protected static final POILogger logger = POILogFactory.getLogger(CFRuleBase.class);
+
static final BitField modificationBits = bf(0x003FFFFF); // Bits: font,align,bord,patt,prot
static final BitField alignHor = bf(0x00000001); // 0 = Horizontal alignment modified
static final BitField alignVer = bf(0x00000002); // 0 = Vertical alignment modified
@@ -129,19 +128,24 @@ public abstract class CFRuleBase extends
return BitFieldFactory.getInstance(i);
}
+
+ private byte condition_type;
+ private byte comparison_operator;
+
protected int formatting_options;
- protected short formatting_not_used; // TODO Decode this properly
+ // TODO Decode this properly
+ protected short formatting_not_used;
protected FontFormatting _fontFormatting;
protected BorderFormatting _borderFormatting;
protected PatternFormatting _patternFormatting;
-
+
private Formula formula1;
private Formula formula2;
/**
* Creates new CFRuleRecord
- *
+ *
* @param conditionType the condition type
* @param comparisonOperation the comparison operation
*/
@@ -151,19 +155,34 @@ public abstract class CFRuleBase extends
formula1 = Formula.create(Ptg.EMPTY_PTG_ARRAY);
formula2 = Formula.create(Ptg.EMPTY_PTG_ARRAY);
}
+
protected CFRuleBase(byte conditionType, byte comparisonOperation, Ptg[] formula1, Ptg[] formula2) {
this(conditionType, comparisonOperation);
this.formula1 = Formula.create(formula1);
this.formula2 = Formula.create(formula2);
}
+
protected CFRuleBase() {}
-
+
+ protected CFRuleBase(CFRuleBase other) {
+ super(other);
+ setConditionType(other.getConditionType());
+ setComparisonOperation(other.getComparisonOperation());
+ formatting_options = other.formatting_options;
+ formatting_not_used = other.formatting_not_used;
+ _fontFormatting = (!other.containsFontFormattingBlock()) ? null : other.getFontFormatting().copy();
+ _borderFormatting = (!other.containsBorderFormattingBlock()) ? null : other.getBorderFormatting().copy();
+ _patternFormatting = (!other.containsPatternFormattingBlock()) ? null : other.getPatternFormatting().copy();
+ formula1 = other.getFormula1().copy();
+ formula2 = other.getFormula2().copy();
+ }
+
protected int readFormatOptions(RecordInputStream in) {
formatting_options = in.readInt();
formatting_not_used = in.readShort();
int len = 6;
-
+
if (containsFontFormattingBlock()) {
_fontFormatting = new FontFormatting(in);
len += _fontFormatting.getDataLength();
@@ -178,7 +197,7 @@ public abstract class CFRuleBase extends
_patternFormatting = new PatternFormatting(in);
len += _patternFormatting.getDataLength();
}
-
+
return len;
}
@@ -187,10 +206,8 @@ public abstract class CFRuleBase extends
}
protected void setConditionType(byte condition_type) {
if ((this instanceof CFRuleRecord)) {
- if (condition_type == CONDITION_TYPE_CELL_VALUE_IS ||
- condition_type == CONDITION_TYPE_FORMULA) {
- // Good, valid combination
- } else {
+ if (!(condition_type == CONDITION_TYPE_CELL_VALUE_IS ||
+ condition_type == CONDITION_TYPE_FORMULA)) {
throw new IllegalArgumentException("CFRuleRecord only accepts Value-Is and Formula types");
}
}
@@ -201,7 +218,7 @@ public abstract class CFRuleBase extends
if (operation < 0 || operation > ComparisonOperator.max_operator)
throw new IllegalArgumentException(
"Valid operators are only in the range 0 to " +ComparisonOperator.max_operator);
-
+
this.comparison_operator = operation;
}
public byte getComparisonOperation() {
@@ -351,7 +368,7 @@ public abstract class CFRuleBase extends
private void setOptionFlag(boolean flag, BitField field) {
formatting_options = field.setBoolean(formatting_options, flag);
}
-
+
protected int getFormattingBlockSize() {
return 6 +
(containsFontFormattingBlock()?_fontFormatting.getRawRecord().length:0)+
@@ -375,7 +392,7 @@ public abstract class CFRuleBase extends
_patternFormatting.serialize(out);
}
}
-
+
/**
* get the stack of the 1st expression as a list
*
@@ -440,27 +457,13 @@ public abstract class CFRuleBase extends
int sheetIndex = sheet.getWorkbook().getSheetIndex(sheet);
return HSSFFormulaParser.parse(formula, sheet.getWorkbook(), FormulaType.CELL, sheetIndex);
}
-
- protected void copyTo(CFRuleBase rec) {
- rec.condition_type = condition_type;
- rec.comparison_operator = comparison_operator;
-
- rec.formatting_options = formatting_options;
- rec.formatting_not_used = formatting_not_used;
- if (containsFontFormattingBlock()) {
- rec._fontFormatting = _fontFormatting.clone();
- }
- if (containsBorderFormattingBlock()) {
- rec._borderFormatting = _borderFormatting.clone();
- }
- if (containsPatternFormattingBlock()) {
- rec._patternFormatting = (PatternFormatting) _patternFormatting.clone();
- }
-
- rec.setFormula1(getFormula1().copy());
- rec.setFormula2(getFormula2().copy());
- }
-
+
@Override
+ @SuppressWarnings("squid:S2975")
+ @Deprecated
+ @Removal(version = "5.0.0")
public abstract CFRuleBase clone();
+
+ @Override
+ public abstract CFRuleBase copy();
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java Sun Dec 22 21:44:45 2019
@@ -23,18 +23,22 @@ import org.apache.poi.hssf.usermodel.HSS
import org.apache.poi.ss.formula.Formula;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.Removal;
/**
- * Conditional Formatting Rule Record (0x01B1).
- *
+ * Conditional Formatting Rule Record (0x01B1).
+ *
* <p>This is for the older-style Excel conditional formattings,
* new-style (Excel 2007+) also make use of {@link CFRule12Record}
* for their rules.</p>
*/
-public final class CFRuleRecord extends CFRuleBase implements Cloneable {
+public final class CFRuleRecord extends CFRuleBase {
public static final short sid = 0x01B1;
- /** Creates new CFRuleRecord */
+ public CFRuleRecord(CFRuleRecord other) {
+ super(other);
+ }
+
private CFRuleRecord(byte conditionType, byte comparisonOperation) {
super(conditionType, comparisonOperation);
setDefaults();
@@ -59,10 +63,10 @@ public final class CFRuleRecord extends
/**
* Creates a new comparison operation rule
- *
+ *
* @param sheet the sheet
* @param formulaText the formula text
- *
+ *
* @return a new comparison operation rule
*/
public static CFRuleRecord create(HSSFSheet sheet, String formulaText) {
@@ -72,12 +76,12 @@ public final class CFRuleRecord extends
}
/**
* Creates a new comparison operation rule
- *
+ *
* @param sheet the sheet
* @param comparisonOperation the comparison operation
* @param formulaText1 the first formula text
* @param formulaText2 the second formula text
- *
+ *
* @return a new comparison operation rule
*/
public static CFRuleRecord create(HSSFSheet sheet, byte comparisonOperation,
@@ -120,7 +124,7 @@ public final class CFRuleRecord extends
out.writeByte(getComparisonOperation());
out.writeShort(formula1Len);
out.writeShort(formula2Len);
-
+
serializeFormattingBlock(out);
getFormula1().serializeTokens(out);
@@ -156,9 +160,15 @@ public final class CFRuleRecord extends
}
@Override
+ @SuppressWarnings("squid:S2975")
+ @Deprecated
+ @Removal(version = "5.0.0")
public CFRuleRecord clone() {
- CFRuleRecord rec = new CFRuleRecord(getConditionType(), getComparisonOperation());
- super.copyTo(rec);
- return rec;
+ return copy();
+ }
+
+ @Override
+ public CFRuleRecord copy() {
+ return new CFRuleRecord(this);
}
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CRNCountRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CRNCountRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CRNCountRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CRNCountRecord.java Sun Dec 22 21:44:45 2019
@@ -19,30 +19,26 @@ package org.apache.poi.hssf.record;
import org.apache.poi.util.LittleEndianOutput;
/**
- * XCT - CRN Count <P>
- *
- * REFERENCE: 5.114<P>
- *
- * @author Josh Micich
+ * XCT - CRN Count
*/
public final class CRNCountRecord extends StandardRecord {
- public final static short sid = 0x59;
+ public static final short sid = 0x59;
private static final short DATA_SIZE = 4;
+ private int field_1_number_crn_records;
+ private int field_2_sheet_table_index;
- private int field_1_number_crn_records;
- private int field_2_sheet_table_index;
-
- public CRNCountRecord() {
- throw new RuntimeException("incomplete code");
+ private CRNCountRecord() {
+ // incomplete code
}
- public int getNumberOfCRNs() {
- return field_1_number_crn_records;
+ public CRNCountRecord(CRNCountRecord other) {
+ super(other);
+ field_1_number_crn_records = other.field_1_number_crn_records;
+ field_2_sheet_table_index = other.field_2_sheet_table_index;
}
-
public CRNCountRecord(RecordInputStream in) {
field_1_number_crn_records = in.readShort();
if(field_1_number_crn_records < 0) {
@@ -53,6 +49,9 @@ public final class CRNCountRecord extend
field_2_sheet_table_index = in.readShort();
}
+ public int getNumberOfCRNs() {
+ return field_1_number_crn_records;
+ }
public String toString() {
StringBuilder sb = new StringBuilder();
@@ -77,4 +76,9 @@ public final class CRNCountRecord extend
public short getSid() {
return sid;
}
+
+ @Override
+ public CRNCountRecord copy() {
+ return new CRNCountRecord(this);
+ }
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CRNRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CRNRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CRNRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CRNRecord.java Sun Dec 22 21:44:45 2019
@@ -21,27 +21,30 @@ import org.apache.poi.ss.formula.constan
import org.apache.poi.util.LittleEndianOutput;
/**
- * Title: CRN(0x005A)<p>
- * Description: This record stores the contents of an external cell or cell range<p>
- * REFERENCE: OOO 5.23
+ * This record stores the contents of an external cell or cell range
*/
public final class CRNRecord extends StandardRecord {
- public final static short sid = 0x005A;
+ public static final short sid = 0x005A;
- private int field_1_last_column_index;
- private int field_2_first_column_index;
- private int field_3_row_index;
+ private int field_1_last_column_index;
+ private int field_2_first_column_index;
+ private int field_3_row_index;
private Object[] field_4_constant_values;
- public CRNRecord() {
- throw new RuntimeException("incomplete code");
+ private CRNRecord() {
+ // incomplete code
}
- public int getNumberOfCRNs() {
- return field_1_last_column_index;
+ public CRNRecord(CRNRecord other) {
+ super(other);
+ field_1_last_column_index = other.field_1_last_column_index;
+ field_2_first_column_index = other.field_2_first_column_index;
+ field_3_row_index = other.field_3_row_index;
+ // field_4_constant_values are instances of Double, Boolean, String, ErrorCode,
+ // i.e. they are immutable and can their references can be simply cloned
+ field_4_constant_values = (other.field_4_constant_values == null) ? null : other.field_4_constant_values.clone();
}
-
public CRNRecord(RecordInputStream in) {
field_1_last_column_index = in.readUByte();
field_2_first_column_index = in.readUByte();
@@ -50,6 +53,9 @@ public final class CRNRecord extends Sta
field_4_constant_values = ConstantValueParser.parse(in, nValues);
}
+ public int getNumberOfCRNs() {
+ return field_1_last_column_index;
+ }
public String toString() {
StringBuilder sb = new StringBuilder();
@@ -77,4 +83,9 @@ public final class CRNRecord extends Sta
public short getSid() {
return sid;
}
+
+ @Override
+ public CRNRecord copy() {
+ return new CRNRecord(this);
+ }
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CalcCountRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CalcCountRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CalcCountRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CalcCountRecord.java Sun Dec 22 21:44:45 2019
@@ -15,34 +15,37 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hssf.record;
import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.Removal;
/**
- * Title: Calc Count Record
- * Description: Specifies the maximum times the gui should perform a formula
- * recalculation. For instance: in the case a formula includes
- * cells that are themselves a result of a formula and a value
- * changes. This is essentially a failsafe against an infinate
- * loop in the event the formulas are not independant. <P>
- * REFERENCE: PG 292 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
+ * Specifies the maximum times the gui should perform a formula recalculation.
+ * For instance: in the case a formula includes cells that are themselves a result of a formula and
+ * a value changes. This is essentially a failsafe against an infinite loop in the event the formulas
+ * are not independent.
+ *
* @version 2.0-pre
- * @see org.apache.poi.hssf.record.CalcModeRecord
+ * @see CalcModeRecord
*/
-public final class CalcCountRecord extends StandardRecord implements Cloneable {
- public final static short sid = 0xC;
- private short field_1_iterations;
+public final class CalcCountRecord extends StandardRecord {
+ public static final short sid = 0xC;
- public CalcCountRecord()
- {
+ private short field_1_iterations;
+
+ public CalcCountRecord() {}
+
+ public CalcCountRecord(CalcCountRecord other) {
+ super(other);
+ field_1_iterations = other.field_1_iterations;
}
- public CalcCountRecord(RecordInputStream in)
- {
+
+ public CalcCountRecord(RecordInputStream in) {
field_1_iterations = in.readShort();
}
@@ -91,9 +94,15 @@ public final class CalcCountRecord exten
}
@Override
+ @SuppressWarnings("squid:S2975")
+ @Deprecated
+ @Removal(version = "5.0.0")
public CalcCountRecord clone() {
- CalcCountRecord rec = new CalcCountRecord();
- rec.field_1_iterations = field_1_iterations;
- return rec;
+ return copy();
+ }
+
+ @Override
+ public CalcCountRecord copy() {
+ return new CalcCountRecord(this);
}
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CalcModeRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CalcModeRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CalcModeRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CalcModeRecord.java Sun Dec 22 21:44:45 2019
@@ -15,52 +15,42 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hssf.record;
import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.Removal;
/**
- * Title: Calc Mode Record<P>
- * Description: Tells the gui whether to calculate formulas
- * automatically, manually or automatically
- * except for tables.<P>
- * REFERENCE: PG 292 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
- * @author Andrew C. Oliver (acoliver at apache dot org)
- * @author Jason Height (jheight at chariot dot net dot au)
+ * Tells the gui whether to calculate formulas automatically, manually or automatically except for tables.
+ *
* @version 2.0-pre
- * @see org.apache.poi.hssf.record.CalcCountRecord
+ * @see CalcCountRecord
*/
-public final class CalcModeRecord extends StandardRecord implements Cloneable {
- public final static short sid = 0xD;
+public final class CalcModeRecord extends StandardRecord {
+ public static final short sid = 0xD;
- /**
- * manually calculate formulas (0)
- */
+ /** manually calculate formulas (0) */
+ public static final short MANUAL = 0;
- public final static short MANUAL = 0;
+ /** automatically calculate formulas (1) */
+ public static final short AUTOMATIC = 1;
- /**
- * automatically calculate formulas (1)
- */
+ /** automatically calculate formulas except for tables (-1) */
+ public static final short AUTOMATIC_EXCEPT_TABLES = -1;
- public final static short AUTOMATIC = 1;
+ private short field_1_calcmode;
- /**
- * automatically calculate formulas except for tables (-1)
- */
+ public CalcModeRecord() {}
- public final static short AUTOMATIC_EXCEPT_TABLES = -1;
- private short field_1_calcmode;
-
- public CalcModeRecord()
- {
+ public CalcModeRecord(CalcModeRecord other) {
+ super(other);
+ field_1_calcmode = other.field_1_calcmode;
}
- public CalcModeRecord(RecordInputStream in)
- {
+ public CalcModeRecord(RecordInputStream in) {
field_1_calcmode = in.readShort();
}
@@ -119,9 +109,15 @@ public final class CalcModeRecord extend
}
@Override
+ @SuppressWarnings("squid:S2975")
+ @Deprecated
+ @Removal(version = "5.0.0")
public CalcModeRecord clone() {
- CalcModeRecord rec = new CalcModeRecord();
- rec.field_1_calcmode = field_1_calcmode;
- return rec;
+ return copy();
+ }
+
+ @Override
+ public CalcModeRecord copy() {
+ return new CalcModeRecord(this);
}
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CellRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CellRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CellRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CellRecord.java Sun Dec 22 21:44:45 2019
@@ -29,8 +29,13 @@ public abstract class CellRecord extends
private int _columnIndex;
private int _formatIndex;
- protected CellRecord() {
- // fields uninitialised
+ protected CellRecord() {}
+
+ protected CellRecord(CellRecord other) {
+ super(other);
+ _rowIndex = other.getRow();
+ _columnIndex = other.getColumn();
+ _formatIndex = other.getXFIndex();
}
protected CellRecord(RecordInputStream in) {
@@ -100,21 +105,21 @@ public abstract class CellRecord extends
* Append specific debug info (used by {@link #toString()} for the value
* contained in this record. Trailing new-line should not be appended
* (superclass does that).
- *
+ *
* @param sb the StringBuilder to write to
*/
protected abstract void appendValueText(StringBuilder sb);
/**
* Gets the debug info BIFF record type name (used by {@link #toString()}.
- *
+ *
* @return the record type name
*/
protected abstract String getRecordName();
/**
* writes out the value data for this cell record
- *
+ *
* @param out the output
*/
protected abstract void serializeValue(LittleEndianOutput out);
@@ -137,9 +142,6 @@ public abstract class CellRecord extends
return 6 + getValueDataSize();
}
- protected final void copyBaseFields(CellRecord rec) {
- rec._rowIndex = _rowIndex;
- rec._columnIndex = _columnIndex;
- rec._formatIndex = _formatIndex;
- }
+ @Override
+ public abstract CellRecord copy();
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CodepageRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CodepageRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CodepageRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CodepageRecord.java Sun Dec 22 21:44:45 2019
@@ -15,7 +15,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hssf.record;
@@ -23,33 +23,33 @@ import org.apache.poi.util.CodePageUtil;
import org.apache.poi.util.LittleEndianOutput;
/**
- * Title: Codepage Record
- * <p>Description: the default characterset. for the workbook</p>
- * <p>REFERENCE: PG 293 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)</p>
- * <p>Use {@link CodePageUtil} to turn these values into Java code pages
- * to encode/decode strings.</p>
+ * The default characterset. for the workbook<p>
+ *
+ * Use {@link CodePageUtil} to turn these values into Java code pages to encode/decode strings.
+ *
* @version 2.0-pre
*/
-public final class CodepageRecord
- extends StandardRecord
-{
- public final static short sid = 0x42;
- private short field_1_codepage; // = 0;
+public final class CodepageRecord extends StandardRecord {
+ public static final short sid = 0x42;
/**
* Excel 97+ (Biff 8) should always store strings as UTF-16LE or
* compressed versions of that. As such, this should always be
* 0x4b0 = UTF_16, except for files coming from older versions.
*/
- public final static short CODEPAGE = ( short ) 0x4b0;
+ public static final short CODEPAGE = ( short ) 0x4b0;
- public CodepageRecord()
- {
+ private short field_1_codepage;
+
+ public CodepageRecord() {}
+
+ public CodepageRecord(CodepageRecord other) {
+ super(other);
+ field_1_codepage = other.field_1_codepage;
}
- public CodepageRecord(RecordInputStream in)
- {
+ public CodepageRecord(RecordInputStream in) {
field_1_codepage = in.readShort();
}
@@ -100,4 +100,9 @@ public final class CodepageRecord
{
return sid;
}
+
+ @Override
+ public CodepageRecord copy() {
+ return new CodepageRecord(this);
+ }
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ColumnInfoRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ColumnInfoRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/ColumnInfoRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/ColumnInfoRecord.java Sun Dec 22 21:44:45 2019
@@ -17,27 +17,27 @@
package org.apache.poi.hssf.record;
-import org.apache.poi.util.HexDump;
-import org.apache.poi.util.LittleEndianOutput;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
+import org.apache.poi.util.HexDump;
+import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.Removal;
/**
- * Title: COLINFO Record (0x007D)<p>
- * Description: Defines with width and formatting for a range of columns<p>
- * REFERENCE: PG 293 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)
+ * Defines with width and formatting for a range of columns
*/
-public final class ColumnInfoRecord extends StandardRecord implements Cloneable {
+public final class ColumnInfoRecord extends StandardRecord {
public static final short sid = 0x007D;
+ private static final BitField hidden = BitFieldFactory.getInstance(0x01);
+ private static final BitField outlevel = BitFieldFactory.getInstance(0x0700);
+ private static final BitField collapsed = BitFieldFactory.getInstance(0x1000);
+
private int _firstCol;
private int _lastCol;
private int _colWidth;
private int _xfIndex;
private int _options;
- private static final BitField hidden = BitFieldFactory.getInstance(0x01);
- private static final BitField outlevel = BitFieldFactory.getInstance(0x0700);
- private static final BitField collapsed = BitFieldFactory.getInstance(0x1000);
// Excel seems write values 2, 10, and 260, even though spec says "must be zero"
private int field_6_reserved;
@@ -51,6 +51,16 @@ public final class ColumnInfoRecord exte
field_6_reserved = 2; // seems to be the most common value
}
+ public ColumnInfoRecord(ColumnInfoRecord other) {
+ super(other);
+ _firstCol = other._firstCol;
+ _lastCol = other._lastCol;
+ _colWidth = other._colWidth;
+ _xfIndex = other._xfIndex;
+ _options = other._options;
+ field_6_reserved = other.field_6_reserved;
+ }
+
public ColumnInfoRecord(RecordInputStream in) {
_firstCol = in.readUShort();
_lastCol = in.readUShort();
@@ -196,7 +206,7 @@ public final class ColumnInfoRecord exte
/**
* @param other the format to match with
- *
+ *
* @return {@code true} if the format, options and column width match
*/
public boolean formatMatches(ColumnInfoRecord other) {
@@ -246,14 +256,15 @@ public final class ColumnInfoRecord exte
}
@Override
+ @SuppressWarnings("squid:S2975")
+ @Deprecated
+ @Removal(version = "5.0.0")
public ColumnInfoRecord clone() {
- ColumnInfoRecord rec = new ColumnInfoRecord();
- rec._firstCol = _firstCol;
- rec._lastCol = _lastCol;
- rec._colWidth = _colWidth;
- rec._xfIndex = _xfIndex;
- rec._options = _options;
- rec.field_6_reserved = field_6_reserved;
- return rec;
+ return copy();
+ }
+
+ @Override
+ public ColumnInfoRecord copy() {
+ return new ColumnInfoRecord(this);
}
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CommonObjectDataSubRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CommonObjectDataSubRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CommonObjectDataSubRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CommonObjectDataSubRecord.java Sun Dec 22 21:44:45 2019
@@ -23,50 +23,51 @@ import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
import org.apache.poi.util.RecordFormatException;
+import org.apache.poi.util.Removal;
/**
* The common object data record is used to store all common preferences for an excel object.
*/
-public final class CommonObjectDataSubRecord extends SubRecord implements Cloneable {
- public final static short sid = 0x0015;
+public final class CommonObjectDataSubRecord extends SubRecord {
+ public static final short sid = 0x0015;
private static final BitField locked = BitFieldFactory.getInstance(0x0001);
private static final BitField printable = BitFieldFactory.getInstance(0x0010);
private static final BitField autofill = BitFieldFactory.getInstance(0x2000);
private static final BitField autoline = BitFieldFactory.getInstance(0x4000);
- public final static short OBJECT_TYPE_GROUP = 0;
- public final static short OBJECT_TYPE_LINE = 1;
- public final static short OBJECT_TYPE_RECTANGLE = 2;
- public final static short OBJECT_TYPE_OVAL = 3;
- public final static short OBJECT_TYPE_ARC = 4;
- public final static short OBJECT_TYPE_CHART = 5;
- public final static short OBJECT_TYPE_TEXT = 6;
- public final static short OBJECT_TYPE_BUTTON = 7;
- public final static short OBJECT_TYPE_PICTURE = 8;
- public final static short OBJECT_TYPE_POLYGON = 9;
- public final static short OBJECT_TYPE_RESERVED1 = 10;
- public final static short OBJECT_TYPE_CHECKBOX = 11;
- public final static short OBJECT_TYPE_OPTION_BUTTON = 12;
- public final static short OBJECT_TYPE_EDIT_BOX = 13;
- public final static short OBJECT_TYPE_LABEL = 14;
- public final static short OBJECT_TYPE_DIALOG_BOX = 15;
- public final static short OBJECT_TYPE_SPINNER = 16;
- public final static short OBJECT_TYPE_SCROLL_BAR = 17;
- public final static short OBJECT_TYPE_LIST_BOX = 18;
- public final static short OBJECT_TYPE_GROUP_BOX = 19;
- public final static short OBJECT_TYPE_COMBO_BOX = 20;
- public final static short OBJECT_TYPE_RESERVED2 = 21;
- public final static short OBJECT_TYPE_RESERVED3 = 22;
- public final static short OBJECT_TYPE_RESERVED4 = 23;
- public final static short OBJECT_TYPE_RESERVED5 = 24;
- public final static short OBJECT_TYPE_COMMENT = 25;
- public final static short OBJECT_TYPE_RESERVED6 = 26;
- public final static short OBJECT_TYPE_RESERVED7 = 27;
- public final static short OBJECT_TYPE_RESERVED8 = 28;
- public final static short OBJECT_TYPE_RESERVED9 = 29;
- public final static short OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING = 30;
-
+ public static final short OBJECT_TYPE_GROUP = 0;
+ public static final short OBJECT_TYPE_LINE = 1;
+ public static final short OBJECT_TYPE_RECTANGLE = 2;
+ public static final short OBJECT_TYPE_OVAL = 3;
+ public static final short OBJECT_TYPE_ARC = 4;
+ public static final short OBJECT_TYPE_CHART = 5;
+ public static final short OBJECT_TYPE_TEXT = 6;
+ public static final short OBJECT_TYPE_BUTTON = 7;
+ public static final short OBJECT_TYPE_PICTURE = 8;
+ public static final short OBJECT_TYPE_POLYGON = 9;
+ public static final short OBJECT_TYPE_RESERVED1 = 10;
+ public static final short OBJECT_TYPE_CHECKBOX = 11;
+ public static final short OBJECT_TYPE_OPTION_BUTTON = 12;
+ public static final short OBJECT_TYPE_EDIT_BOX = 13;
+ public static final short OBJECT_TYPE_LABEL = 14;
+ public static final short OBJECT_TYPE_DIALOG_BOX = 15;
+ public static final short OBJECT_TYPE_SPINNER = 16;
+ public static final short OBJECT_TYPE_SCROLL_BAR = 17;
+ public static final short OBJECT_TYPE_LIST_BOX = 18;
+ public static final short OBJECT_TYPE_GROUP_BOX = 19;
+ public static final short OBJECT_TYPE_COMBO_BOX = 20;
+ public static final short OBJECT_TYPE_RESERVED2 = 21;
+ public static final short OBJECT_TYPE_RESERVED3 = 22;
+ public static final short OBJECT_TYPE_RESERVED4 = 23;
+ public static final short OBJECT_TYPE_RESERVED5 = 24;
+ public static final short OBJECT_TYPE_COMMENT = 25;
+ public static final short OBJECT_TYPE_RESERVED6 = 26;
+ public static final short OBJECT_TYPE_RESERVED7 = 27;
+ public static final short OBJECT_TYPE_RESERVED8 = 28;
+ public static final short OBJECT_TYPE_RESERVED9 = 29;
+ public static final short OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING = 30;
+
private short field_1_objectType;
private int field_2_objectId;
private short field_3_option;
@@ -75,9 +76,16 @@ public final class CommonObjectDataSubRe
private int field_6_reserved3;
- public CommonObjectDataSubRecord()
- {
+ public CommonObjectDataSubRecord() {}
+ public CommonObjectDataSubRecord(CommonObjectDataSubRecord other) {
+ super(other);
+ field_1_objectType = other.field_1_objectType;
+ field_2_objectId = other.field_2_objectId;
+ field_3_option = other.field_3_option;
+ field_4_reserved1 = other.field_4_reserved1;
+ field_5_reserved2 = other.field_5_reserved2;
+ field_6_reserved3 = other.field_6_reserved3;
}
public CommonObjectDataSubRecord(LittleEndianInput in, int size) {
@@ -101,31 +109,31 @@ public final class CommonObjectDataSubRe
buffer.append(" .objectType = ")
.append("0x").append(HexDump.toHex( getObjectType ()))
.append(" (").append( getObjectType() ).append(" )");
- buffer.append(System.getProperty("line.separator"));
+ buffer.append(System.getProperty("line.separator"));
buffer.append(" .objectId = ")
.append("0x").append(HexDump.toHex( getObjectId ()))
.append(" (").append( getObjectId() ).append(" )");
- buffer.append(System.getProperty("line.separator"));
+ buffer.append(System.getProperty("line.separator"));
buffer.append(" .option = ")
.append("0x").append(HexDump.toHex( getOption ()))
.append(" (").append( getOption() ).append(" )");
- buffer.append(System.getProperty("line.separator"));
- buffer.append(" .locked = ").append(isLocked()).append('\n');
- buffer.append(" .printable = ").append(isPrintable()).append('\n');
- buffer.append(" .autofill = ").append(isAutofill()).append('\n');
- buffer.append(" .autoline = ").append(isAutoline()).append('\n');
+ buffer.append(System.getProperty("line.separator"));
+ buffer.append(" .locked = ").append(isLocked()).append('\n');
+ buffer.append(" .printable = ").append(isPrintable()).append('\n');
+ buffer.append(" .autofill = ").append(isAutofill()).append('\n');
+ buffer.append(" .autoline = ").append(isAutoline()).append('\n');
buffer.append(" .reserved1 = ")
.append("0x").append(HexDump.toHex( getReserved1 ()))
.append(" (").append( getReserved1() ).append(" )");
- buffer.append(System.getProperty("line.separator"));
+ buffer.append(System.getProperty("line.separator"));
buffer.append(" .reserved2 = ")
.append("0x").append(HexDump.toHex( getReserved2 ()))
.append(" (").append( getReserved2() ).append(" )");
- buffer.append(System.getProperty("line.separator"));
+ buffer.append(System.getProperty("line.separator"));
buffer.append(" .reserved3 = ")
.append("0x").append(HexDump.toHex( getReserved3 ()))
.append(" (").append( getReserved3() ).append(" )");
- buffer.append(System.getProperty("line.separator"));
+ buffer.append(System.getProperty("line.separator"));
buffer.append("[/ftCmo]\n");
return buffer.toString();
@@ -159,23 +167,23 @@ public final class CommonObjectDataSubRe
}
@Override
+ @SuppressWarnings("squid:S2975")
+ @Deprecated
+ @Removal(version = "5.0.0")
public CommonObjectDataSubRecord clone() {
- CommonObjectDataSubRecord rec = new CommonObjectDataSubRecord();
-
- rec.field_1_objectType = field_1_objectType;
- rec.field_2_objectId = field_2_objectId;
- rec.field_3_option = field_3_option;
- rec.field_4_reserved1 = field_4_reserved1;
- rec.field_5_reserved2 = field_5_reserved2;
- rec.field_6_reserved3 = field_6_reserved3;
- return rec;
+ return copy();
+ }
+
+ @Override
+ public CommonObjectDataSubRecord copy() {
+ return new CommonObjectDataSubRecord(this);
}
/**
* Get the object type field for the CommonObjectData record.
*
- * @return One of
+ * @return One of
* OBJECT_TYPE_GROUP
* OBJECT_TYPE_LINE
* OBJECT_TYPE_RECTANGLE
@@ -217,7 +225,7 @@ public final class CommonObjectDataSubRe
* Set the object type field for the CommonObjectData record.
*
* @param field_1_objectType
- * One of
+ * One of
* OBJECT_TYPE_GROUP
* OBJECT_TYPE_LINE
* OBJECT_TYPE_RECTANGLE
@@ -257,7 +265,7 @@ public final class CommonObjectDataSubRe
/**
* Get the object id field for the CommonObjectData record.
- *
+ *
* @return the object id field
*/
public int getObjectId()
@@ -267,7 +275,7 @@ public final class CommonObjectDataSubRe
/**
* Set the object id field for the CommonObjectData record.
- *
+ *
* @param field_2_objectId the object id field
*/
public void setObjectId(int field_2_objectId)
@@ -277,7 +285,7 @@ public final class CommonObjectDataSubRe
/**
* Get the option field for the CommonObjectData record.
- *
+ *
* @return the option field
*/
public short getOption()
@@ -287,7 +295,7 @@ public final class CommonObjectDataSubRe
/**
* Set the option field for the CommonObjectData record.
- *
+ *
* @param field_3_option the option field
*/
public void setOption(short field_3_option)
@@ -297,7 +305,7 @@ public final class CommonObjectDataSubRe
/**
* Get the reserved1 field for the CommonObjectData record.
- *
+ *
* @return the reserved1 field
*/
public int getReserved1()
@@ -307,7 +315,7 @@ public final class CommonObjectDataSubRe
/**
* Set the reserved1 field for the CommonObjectData record.
- *
+ *
* @param field_4_reserved1 the reserved1 field
*/
public void setReserved1(int field_4_reserved1)
@@ -317,7 +325,7 @@ public final class CommonObjectDataSubRe
/**
* Get the reserved2 field for the CommonObjectData record.
- *
+ *
* @return the reserved2 field
*/
public int getReserved2()
@@ -327,7 +335,7 @@ public final class CommonObjectDataSubRe
/**
* Set the reserved2 field for the CommonObjectData record.
- *
+ *
* @param field_5_reserved2 the reserved2 field
*/
public void setReserved2(int field_5_reserved2)
@@ -337,7 +345,7 @@ public final class CommonObjectDataSubRe
/**
* Get the reserved3 field for the CommonObjectData record.
- *
+ *
* @return the reserved3 field
*/
public int getReserved3()
@@ -347,7 +355,7 @@ public final class CommonObjectDataSubRe
/**
* Set the reserved3 field for the CommonObjectData record.
- *
+ *
* @param field_6_reserved3 the reserved3 field
*/
public void setReserved3(int field_6_reserved3)
@@ -358,7 +366,7 @@ public final class CommonObjectDataSubRe
/**
* Sets the locked field value.
* true if object is locked when sheet has been protected
- *
+ *
* @param value {@code true} if object is locked when sheet has been protected
*/
public void setLocked(boolean value)
@@ -378,7 +386,7 @@ public final class CommonObjectDataSubRe
/**
* Sets the printable field value.
* object appears when printed
- *
+ *
* @param value {@code true} if object appears when printed
*/
public void setPrintable(boolean value)
@@ -398,7 +406,7 @@ public final class CommonObjectDataSubRe
/**
* Sets the autofill field value.
* whether object uses an automatic fill style
- *
+ *
* @param value {@code true} if object uses an automatic fill style
*/
public void setAutofill(boolean value)
@@ -418,7 +426,7 @@ public final class CommonObjectDataSubRe
/**
* Sets the autoline field value.
* whether object uses an automatic line style
- *
+ *
* @param value {@code true} if object uses an automatic line style
*/
public void setAutoline(boolean value)
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ContinueRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ContinueRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/ContinueRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/ContinueRecord.java Sun Dec 22 21:44:45 2019
@@ -19,23 +19,26 @@ package org.apache.poi.hssf.record;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.Removal;
/**
- * Title: Continue Record(0x003C) - Helper class used primarily for SST Records <P>
- * Description: handles overflow for prior record in the input
- * stream; content is tailored to that prior record<P>
- * @author Marc Johnson (mjohnson at apache dot org)
- * @author Andrew C. Oliver (acoliver at apache dot org)
- * @author Csaba Nagy (ncsaba at yahoo dot com)
+ * Helper class used primarily for SST Records<p>
+ *
+ * handles overflow for prior record in the input stream; content is tailored to that prior record
*/
-public final class ContinueRecord extends StandardRecord implements Cloneable {
- public final static short sid = 0x003C;
+public final class ContinueRecord extends StandardRecord {
+ public static final short sid = 0x003C;
private byte[] _data;
public ContinueRecord(byte[] data) {
_data = data;
}
+ public ContinueRecord(ContinueRecord other) {
+ super(other);
+ _data = (other._data == null) ? null : other._data.clone();
+ }
+
protected int getDataSize() {
return _data.length;
}
@@ -70,7 +73,15 @@ public final class ContinueRecord extend
}
@Override
+ @SuppressWarnings("squid:S2975")
+ @Deprecated
+ @Removal(version = "5.0.0")
public ContinueRecord clone() {
- return new ContinueRecord(_data);
+ return copy();
+ }
+
+ @Override
+ public ContinueRecord copy() {
+ return new ContinueRecord(this);
}
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CountryRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CountryRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CountryRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CountryRecord.java Sun Dec 22 21:44:45 2019
@@ -15,37 +15,36 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hssf.record;
import org.apache.poi.util.LittleEndianOutput;
/**
- * Title: Country Record (aka WIN.INI country)<P>
- * Description: used for localization. Currently HSSF always sets this to 1
- * and it seems to work fine even in Germany. (es geht's auch fuer Deutschland)<P>
+ * Country Record (aka WIN.INI country) - used for localization<p>
+ *
+ * Currently HSSF always sets this to 1 and it seems to work fine even in Germany.
*
- * REFERENCE: PG 298 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
- * @author Andrew C. Oliver (acoliver at apache dot org)
* @version 2.0-pre
*/
-public final class CountryRecord
- extends StandardRecord
-{
- public final static short sid = 0x8c;
+public final class CountryRecord extends StandardRecord {
+ public static final short sid = 0x8c;
// 1 for US
- private short field_1_default_country;
- private short field_2_current_country;
+ private short field_1_default_country;
+ private short field_2_current_country;
- public CountryRecord()
- {
+ public CountryRecord() {}
+
+ public CountryRecord(CountryRecord other) {
+ super(other);
+ field_1_default_country = other.field_1_default_country;
+ field_2_current_country = other.field_2_current_country;
}
- public CountryRecord(RecordInputStream in)
- {
+ public CountryRecord(RecordInputStream in) {
field_1_default_country = in.readShort();
field_2_current_country = in.readShort();
}
@@ -120,4 +119,9 @@ public final class CountryRecord
{
return sid;
}
+
+ @Override
+ public CountryRecord copy() {
+ return new CountryRecord(this);
+ }
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DBCellRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DBCellRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/DBCellRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/DBCellRecord.java Sun Dec 22 21:44:45 2019
@@ -19,39 +19,15 @@ package org.apache.poi.hssf.record;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.Removal;
/**
- * Title: DBCell Record (0x00D7)<p>
- * Description: Used by Excel and other MS apps to quickly find rows in the sheets.<P>
- * REFERENCE: PG 299/440 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)
+ * Used by Excel and other MS apps to quickly find rows in the sheets.
*/
-public final class DBCellRecord extends StandardRecord implements Cloneable {
- public final static short sid = 0x00D7;
- public final static int BLOCK_SIZE = 32;
-
- public static final class Builder {
- private short[] _cellOffsets;
- private int _nCellOffsets;
- public Builder() {
- _cellOffsets = new short[4];
- }
-
- public void addCellOffset(int cellRefOffset) {
- if (_cellOffsets.length <= _nCellOffsets) {
- short[] temp = new short[_nCellOffsets * 2];
- System.arraycopy(_cellOffsets, 0, temp, 0, _nCellOffsets);
- _cellOffsets = temp;
- }
- _cellOffsets[_nCellOffsets] = (short) cellRefOffset;
- _nCellOffsets++;
- }
+public final class DBCellRecord extends StandardRecord {
+ public static final short sid = 0x00D7;
+ public static final int BLOCK_SIZE = 32;
- public DBCellRecord build(int rowOffset) {
- short[] cellOffsets = new short[_nCellOffsets];
- System.arraycopy(_cellOffsets, 0, cellOffsets, 0, _nCellOffsets);
- return new DBCellRecord(rowOffset, cellOffsets);
- }
- }
/**
* offset from the start of this DBCellRecord to the start of the first cell in
* the next DBCell block.
@@ -59,23 +35,21 @@ public final class DBCellRecord extends
private final int field_1_row_offset;
private final short[] field_2_cell_offsets;
- DBCellRecord(int rowOffset, short[]cellOffsets) {
+ public DBCellRecord(int rowOffset, short[] cellOffsets) {
field_1_row_offset = rowOffset;
field_2_cell_offsets = cellOffsets;
}
public DBCellRecord(RecordInputStream in) {
field_1_row_offset = in.readUShort();
- int size = in.remaining();
+ int size = in.remaining();
field_2_cell_offsets = new short[ size / 2 ];
- for (int i=0;i<field_2_cell_offsets.length;i++)
- {
+ for (int i=0;i<field_2_cell_offsets.length;i++) {
field_2_cell_offsets[ i ] = in.readShort();
}
}
-
public String toString() {
StringBuilder buffer = new StringBuilder();
@@ -91,8 +65,8 @@ public final class DBCellRecord extends
public void serialize(LittleEndianOutput out) {
out.writeInt(field_1_row_offset);
- for (int k = 0; k < field_2_cell_offsets.length; k++) {
- out.writeShort(field_2_cell_offsets[ k ]);
+ for (short field_2_cell_offset : field_2_cell_offsets) {
+ out.writeShort(field_2_cell_offset);
}
}
protected int getDataSize() {
@@ -104,7 +78,15 @@ public final class DBCellRecord extends
}
@Override
+ @SuppressWarnings("squid:S2975")
+ @Deprecated
+ @Removal(version = "5.0.0")
public DBCellRecord clone() {
+ return copy();
+ }
+
+ @Override
+ public DBCellRecord copy() {
// safe because immutable
return this;
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DConRefRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DConRefRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/DConRefRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/DConRefRecord.java Sun Dec 22 21:44:45 2019
@@ -18,10 +18,10 @@
*/
package org.apache.poi.hssf.record;
+import java.io.ByteArrayInputStream;
import java.util.Arrays;
import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianOutput;
import org.apache.poi.util.RecordFormatException;
import org.apache.poi.util.StringUtil;
@@ -67,8 +67,7 @@ import org.apache.poi.util.StringUtil;
*
* At the moment this class is read-only.
*/
-public class DConRefRecord extends StandardRecord
-{
+public class DConRefRecord extends StandardRecord {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
@@ -108,54 +107,25 @@ public class DConRefRecord extends Stand
*/
private byte[] _unused;
+ public DConRefRecord(DConRefRecord other) {
+ super(other);
+ firstCol = other.firstCol;
+ firstRow = other.firstRow;
+ lastCol = other.lastCol;
+ lastRow = other.lastRow;
+ charCount = other.charCount;
+ charType = other.charType;
+ path = (other.path == null) ? null : other.path.clone();
+ _unused = (other._unused == null) ? null : other._unused.clone();
+ }
+
/**
* Read constructor.
*
* @param data byte array containing a DConRef Record, including the header.
*/
- public DConRefRecord(byte[] data)
- {
- int offset = 0;
- if (!(LittleEndian.getShort(data, offset) == DConRefRecord.sid))
- throw new RecordFormatException("incompatible sid.");
- offset += LittleEndian.SHORT_SIZE;
-
- //length = LittleEndian.getShort(data, offset);
- offset += LittleEndian.SHORT_SIZE;
-
- firstRow = LittleEndian.getUShort(data, offset);
- offset += LittleEndian.SHORT_SIZE;
- lastRow = LittleEndian.getUShort(data, offset);
- offset += LittleEndian.SHORT_SIZE;
- firstCol = LittleEndian.getUByte(data, offset);
- offset += LittleEndian.BYTE_SIZE;
- lastCol = LittleEndian.getUByte(data, offset);
- offset += LittleEndian.BYTE_SIZE;
- charCount = LittleEndian.getUShort(data, offset);
- offset += LittleEndian.SHORT_SIZE;
- if (charCount < 2)
- throw new RecordFormatException("Character count must be >= 2");
-
- charType = LittleEndian.getUByte(data, offset);
- offset += LittleEndian.BYTE_SIZE; //7 bits reserved + 1 bit type
-
- /*
- * bytelength is the length of the string in bytes, which depends on whether the string is
- * made of single- or double-byte chars. This is given by charType, which equals 0 if
- * single-byte, 1 if double-byte.
- */
- int byteLength = charCount * ((charType & 1) + 1);
-
- path = LittleEndian.getByteArray(data, offset, byteLength, MAX_RECORD_LENGTH);
- offset += byteLength;
-
- /*
- * If it's a self reference, the last one or two bytes (depending on char type) are the
- * unused field. Not sure If i need to bother with this...
- */
- if (path[0] == 0x02)
- _unused = LittleEndian.getByteArray(data, offset, (charType + 1), MAX_RECORD_LENGTH);
-
+ public DConRefRecord(byte[] data) {
+ this(bytesToRIStream(data));
}
/**
@@ -163,10 +133,10 @@ public class DConRefRecord extends Stand
*
* @param inStream RecordInputStream containing a DConRefRecord structure.
*/
- public DConRefRecord(RecordInputStream inStream)
- {
- if (inStream.getSid() != sid)
+ public DConRefRecord(RecordInputStream inStream) {
+ if (inStream.getSid() != sid) {
throw new RecordFormatException("Wrong sid: " + inStream.getSid());
+ }
firstRow = inStream.readUShort();
lastRow = inStream.readUShort();
@@ -174,17 +144,23 @@ public class DConRefRecord extends Stand
lastCol = inStream.readUByte();
charCount = inStream.readUShort();
- charType = inStream.readUByte() & 0x01; //first bit only.
- // byteLength depends on whether we are using single- or double-byte chars.
- int byteLength = charCount * (charType + 1);
+ // 7 bits reserved + 1 bit type - first bit only
+ charType = inStream.readUByte() & 0x01;
+
+ // bytelength is the length of the string in bytes, which depends on whether the string is
+ // made of single- or double-byte chars. This is given by charType, which equals 0 if
+ // single-byte, 1 if double-byte.
+ final int byteLength = charCount * (charType + 1);
path = IOUtils.safelyAllocate(byteLength, MAX_RECORD_LENGTH);
inStream.readFully(path);
- if (path[0] == 0x02)
+ // If it's a self reference, the last one or two bytes (depending on char type) are the
+ // unused field. Not sure If i need to bother with this...
+ if (path[0] == 0x02) {
_unused = inStream.readRemainder();
-
+ }
}
/*
@@ -291,8 +267,7 @@ public class DConRefRecord extends Stand
//all of the path strings start with either 0x02 or 0x01 followed by zero or
//more of 0x01..0x08
int offset = 1;
- while (path[offset] < 0x20 && offset < path.length)
- {
+ while (offset < path.length && path[offset] < 0x20) {
offset++;
}
String out = new String(Arrays.copyOfRange(path, offset, path.length), StringUtil.UTF8);
@@ -310,8 +285,17 @@ public class DConRefRecord extends Stand
*/
public boolean isExternalRef()
{
- if (path[0] == 0x01)
- return true;
- return false;
+ return path[0] == 0x01;
+ }
+
+ @Override
+ public DConRefRecord copy() {
+ return new DConRefRecord(this);
+ }
+
+ private static RecordInputStream bytesToRIStream(byte[] data) {
+ RecordInputStream ric = new RecordInputStream(new ByteArrayInputStream(data));
+ ric.nextRecord();
+ return ric;
}
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DSFRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DSFRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/DSFRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/DSFRecord.java Sun Dec 22 21:44:45 2019
@@ -23,21 +23,26 @@ import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianOutput;
/**
- * Title: Double Stream Flag Record (0x0161)<p>
- * Description: tells if this is a double stream file. (always no for HSSF generated files)<p>
- * Double Stream files contain both BIFF8 and BIFF7 workbooks.<p>
- * REFERENCE: PG 305 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)
+ * Tells if this is a double stream file. (never applies to HSSF generated files)<p>
+ *
+ * Double Stream files contain both BIFF8 and BIFF7 workbooks.
*/
public final class DSFRecord extends StandardRecord {
- public final static short sid = 0x0161;
+ public static final short sid = 0x0161;
private static final BitField biff5BookStreamFlag = BitFieldFactory.getInstance(0x0001);
private int _options;
+ private DSFRecord(DSFRecord other) {
+ super(other);
+ _options = other._options;
+ }
+
private DSFRecord(int options) {
_options = options;
}
+
public DSFRecord(boolean isBiff5BookStreamPresent) {
this(0);
_options = biff5BookStreamFlag.setBoolean(0, isBiff5BookStreamPresent);
@@ -71,4 +76,9 @@ public final class DSFRecord extends Sta
public short getSid() {
return sid;
}
+
+ @Override
+ public DSFRecord copy() {
+ return new DSFRecord(this);
+ }
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DVALRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DVALRecord.java?rev=1871911&r1=1871910&r2=1871911&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/DVALRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/DVALRecord.java Sun Dec 22 21:44:45 2019
@@ -18,14 +18,13 @@
package org.apache.poi.hssf.record;
import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.Removal;
/**
- * Title: DATAVALIDATIONS Record (0x01B2)<p>
- * Description: used in data validation ;
- * This record is the list header of all data validation records (0x01BE) in the current sheet.
+ * This record is the list header of all data validation records (0x01BE) in the current sheet.
*/
-public final class DVALRecord extends StandardRecord implements Cloneable {
- public final static short sid = 0x01B2;
+public final class DVALRecord extends StandardRecord {
+ public static final short sid = 0x01B2;
/** Options of the DVAL */
private short field_1_options;
@@ -47,12 +46,21 @@ public final class DVALRecord extends St
field_5_dv_no = 0x00000000;
}
+ public DVALRecord(DVALRecord other) {
+ super(other);
+ field_1_options = other.field_1_options;
+ field_2_horiz_pos = other.field_2_horiz_pos;
+ field_3_vert_pos = other.field_3_vert_pos;
+ field_cbo_id = other.field_cbo_id;
+ field_5_dv_no = other.field_5_dv_no;
+ }
+
public DVALRecord(RecordInputStream in) {
field_1_options = in.readShort();
field_2_horiz_pos = in.readInt();
field_3_vert_pos = in.readInt();
- field_cbo_id = in.readInt();
- field_5_dv_no = in.readInt();
+ field_cbo_id = in.readInt();
+ field_5_dv_no = in.readInt();
}
/**
@@ -142,7 +150,6 @@ public final class DVALRecord extends St
}
public void serialize(LittleEndianOutput out) {
-
out.writeShort(getOptions());
out.writeInt(getHorizontalPos());
out.writeInt(getVerticalPos());
@@ -158,14 +165,16 @@ public final class DVALRecord extends St
return sid;
}
- @Override
- public DVALRecord clone() {
- DVALRecord rec = new DVALRecord();
- rec.field_1_options = field_1_options;
- rec.field_2_horiz_pos = field_2_horiz_pos;
- rec.field_3_vert_pos = field_3_vert_pos;
- rec.field_cbo_id = field_cbo_id;
- rec.field_5_dv_no = field_5_dv_no;
- return rec;
+ @Override
+ @SuppressWarnings("squid:S2975")
+ @Deprecated
+ @Removal(version = "5.0.0")
+ public DVALRecord clone() {
+ return copy();
+ }
+
+ @Override
+ public DVALRecord copy() {
+ return new DVALRecord(this);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org