From: Danny Mui Date: Sat, 28 Jun 2003 00:21:47 +0000 (+0000) Subject: SharedFormula clone patch that was already applied to HEAD X-Git-Tag: REL_2_5_1~120 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=639cc1fb15100946662a03956495ef9353fe124b;p=poi.git SharedFormula clone patch that was already applied to HEAD git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/branches/REL_2_BRANCH@353171 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/record/FormulaRecord.java b/src/java/org/apache/poi/hssf/record/FormulaRecord.java index ad926be474..c1ed74a9d5 100644 --- a/src/java/org/apache/poi/hssf/record/FormulaRecord.java +++ b/src/java/org/apache/poi/hssf/record/FormulaRecord.java @@ -607,8 +607,8 @@ public class FormulaRecord if (field_8_parsed_expr != null) size = field_8_parsed_expr.size(); for (int i=0; i< size; i++) { - Ptg ptg = (Ptg)((Ptg)field_8_parsed_expr.get(i)).clone(); - rec.field_8_parsed_expr.set(i, ptg); + Ptg ptg = (Ptg)((Ptg)field_8_parsed_expr.get(i)).clone(); + rec.field_8_parsed_expr.add(i, ptg); } rec.all_data = all_data; return rec; diff --git a/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java index 7d5b0b048d..9a7575c21e 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java @@ -82,6 +82,19 @@ public class FormulaRecordAggregate this.stringRecord = stringRecord; } + /** + * Used only in the clone + * @param formulaRecord + * @param stringRecord + * @param sharedRecord + */ + public FormulaRecordAggregate( FormulaRecord formulaRecord, StringRecord stringRecord, SharedFormulaRecord sharedRecord) + { + this.formulaRecord = formulaRecord; + this.stringRecord = stringRecord; + this.sharedFormulaRecord = sharedRecord; + } + protected void validateSid( short id ) @@ -221,7 +234,10 @@ public class FormulaRecordAggregate * @see java.lang.Object#clone() */ public Object clone() { - return new FormulaRecordAggregate((FormulaRecord) this.formulaRecord.clone(), (StringRecord) this.stringRecord.clone()); + StringRecord clonedString = (stringRecord == null) ? null : (StringRecord)stringRecord.clone(); + SharedFormulaRecord clonedShared = (sharedFormulaRecord == null) ? null : (SharedFormulaRecord)sharedFormulaRecord.clone(); + + return new FormulaRecordAggregate((FormulaRecord) this.formulaRecord.clone(), clonedString, clonedShared); } @@ -241,4 +257,14 @@ public class FormulaRecordAggregate this.sharedFormulaRecord = sharedFormulaRecord; } + /* + * Setting to true so that this value does not abort the whole ValueAggregation + * (non-Javadoc) + * @see org.apache.poi.hssf.record.Record#isInValueSection() + */ + public boolean isInValueSection() { + + return true; + } + } diff --git a/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java b/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java index 576bce3316..b100a1a762 100644 --- a/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java @@ -110,7 +110,10 @@ public class ExpPtg public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;} public Object clone() { - throw new RuntimeException("NO IDEA SHARED FORMULA EXP PTG"); + //can't clone one that doesnt have data can we?? + if (this.existing == null) throw new RuntimeException("NO IDEA SHARED FORMULA EXP PTG"); + + return new ExpPtg(this.existing, 0); } }