Fixed SharedValueManager to create separate empty instances in anticipation of instances becoming mutable.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@893057 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f11c66506d
commit
65a41cce66
|
@ -56,9 +56,12 @@ public final class RowRecordsAggregate extends RecordAggregate {
|
|||
|
||||
/** Creates a new instance of ValueRecordsAggregate */
|
||||
public RowRecordsAggregate() {
|
||||
this(SharedValueManager.EMPTY);
|
||||
this(SharedValueManager.createEmpty());
|
||||
}
|
||||
private RowRecordsAggregate(SharedValueManager svm) {
|
||||
if (svm == null) {
|
||||
throw new IllegalArgumentException("SharedValueManager must be provided.");
|
||||
}
|
||||
_rowRecords = new TreeMap<Integer, RowRecord>();
|
||||
_valuesAgg = new ValueRecordsAggregate();
|
||||
_unknownRecords = new ArrayList<Record>();
|
||||
|
@ -68,6 +71,8 @@ public final class RowRecordsAggregate extends RecordAggregate {
|
|||
/**
|
||||
* @param rs record stream with all {@link SharedFormulaRecord}
|
||||
* {@link ArrayRecord}, {@link TableRecord} {@link MergeCellsRecord} Records removed
|
||||
* @param svm an initialised {@link SharedValueManager} (from the shared formula, array
|
||||
* and table records of the current sheet). Never <code>null</code>.
|
||||
*/
|
||||
public RowRecordsAggregate(RecordStream rs, SharedValueManager svm) {
|
||||
this(svm);
|
||||
|
|
|
@ -109,8 +109,14 @@ public final class SharedValueManager {
|
|||
}
|
||||
}
|
||||
|
||||
public static final SharedValueManager EMPTY = new SharedValueManager(
|
||||
/**
|
||||
* @return a new empty {@link SharedValueManager}.
|
||||
*/
|
||||
public static final SharedValueManager createEmpty() {
|
||||
// Note - must create distinct instances because they are assumed to be mutable.
|
||||
return new SharedValueManager(
|
||||
new SharedFormulaRecord[0], new CellReference[0], new ArrayRecord[0], new TableRecord[0]);
|
||||
}
|
||||
private final ArrayRecord[] _arrayRecords;
|
||||
private final TableRecord[] _tableRecords;
|
||||
private final Map<SharedFormulaRecord, SharedFormulaGroup> _groupsBySharedFormulaRecord;
|
||||
|
@ -144,7 +150,7 @@ public final class SharedValueManager {
|
|||
public static SharedValueManager create(SharedFormulaRecord[] sharedFormulaRecords,
|
||||
CellReference[] firstCells, ArrayRecord[] arrayRecords, TableRecord[] tableRecords) {
|
||||
if (sharedFormulaRecords.length + firstCells.length + arrayRecords.length + tableRecords.length < 1) {
|
||||
return EMPTY;
|
||||
return createEmpty();
|
||||
}
|
||||
return new SharedValueManager(sharedFormulaRecords, firstCells, arrayRecords, tableRecords);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public final class TestFormulaRecordAggregate extends TestCase {
|
|||
f.setCachedResultTypeString();
|
||||
StringRecord s = new StringRecord();
|
||||
s.setString("abc");
|
||||
FormulaRecordAggregate fagg = new FormulaRecordAggregate(f, s, SharedValueManager.EMPTY);
|
||||
FormulaRecordAggregate fagg = new FormulaRecordAggregate(f, s, SharedValueManager.createEmpty());
|
||||
assertEquals("abc", fagg.getStringValue());
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ public final class TestFormulaRecordAggregate extends TestCase {
|
|||
fr.setValue(2.0);
|
||||
StringRecord sr = new StringRecord();
|
||||
sr.setString("NA");
|
||||
SharedValueManager svm = SharedValueManager.EMPTY;
|
||||
SharedValueManager svm = SharedValueManager.createEmpty();
|
||||
FormulaRecordAggregate fra;
|
||||
|
||||
try {
|
||||
|
|
|
@ -140,7 +140,7 @@ public final class TestRowRecordsAggregate extends TestCase {
|
|||
RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
|
||||
RowRecordsAggregate rra;
|
||||
try {
|
||||
rra = new RowRecordsAggregate(rs, SharedValueManager.EMPTY);
|
||||
rra = new RowRecordsAggregate(rs, SharedValueManager.createEmpty());
|
||||
} catch (RuntimeException e) {
|
||||
if (e.getMessage().startsWith("Unexpected record type")) {
|
||||
throw new AssertionFailedError("Identified bug 46280a");
|
||||
|
|
Loading…
Reference in New Issue