Skip to content

Commit

Permalink
fix: Fix header cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
Romuald Rousseau committed Nov 21, 2024
1 parent c5afc06 commit ede1232
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ public BaseHeader(final BaseTable table, final BaseCell cell) {
this.columnEmpty = false;
}

protected BaseHeader(final BaseHeader parent) {
this.table = parent.table;
this.cell = parent.cell;
this.colIndex = parent.colIndex;
this.columnEmpty = parent.columnEmpty;
}

@Override
public BaseCell getCellAtRow(final Row row) {
return ((BaseRow) row).getCellAt(this.getColumnIndex());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ protected DataTableHeader(final BaseTable table, final BaseCell cell, final Stri
this.entities = entities;
}

protected DataTableHeader(final DataTableHeader parent) {
this(parent.getTable(), parent.getCell(), parent.name, parent.tag, parent.entities);
}

@Override
public BaseHeader clone() {
return new DataTableHeader(this);
return new DataTableHeader(this.getTable(), this.getCell(), this.name, this.tag, this.entities);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ public MetaGroupHeader(final BaseTable table, final BaseCell cell) {
super(table, cell);
}

protected MetaGroupHeader(final MetaGroupHeader parent) {
this(parent.getTable(), parent.getCell());
}

@Override
public BaseHeader clone() {
return new MetaGroupHeader(this);
return new MetaGroupHeader(this.getTable(), this.getCell());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,30 @@ public class MetaHeader extends BaseHeader {
private final String valueOfValue;

public MetaHeader(final BaseTable table, final BaseCell cell) {
this(table, cell, null, null, null);
}

protected MetaHeader(final BaseTable table, final BaseCell cell, final String name, final BaseCell value,
final String valueOfValue) {
super(table, cell);

final var model = table.getSheet().getDocument().getModel();
final var cellValue = cell.getValue();
this.name = this.getPivotKeyEntityAsString().orElseGet(() -> model.toEntityName(cellValue));
this.value = model.toEntityValue(cellValue).map(x -> new BaseCell(x, cell)).orElse(cell);
this.valueOfValue = this.value.getValue();
}

protected MetaHeader(final MetaHeader parent) {
super(parent.getTable(), parent.getCell());
this.name = parent.name;
this.value = parent.value;
this.valueOfValue = parent.valueOfValue;

this.name = (name == null)
? this.getPivotKeyEntityAsString().orElseGet(() -> model.toEntityName(cellValue))
: name;
this.value = (value == null)
? model.toEntityValue(cellValue).map(x -> new BaseCell(x, cell)).orElse(cell)
: value;
this.valueOfValue = (valueOfValue == null)
? this.value.getValue()
: valueOfValue;
}

@Override
public BaseHeader clone() {
return new MetaHeader(this);
return new MetaHeader(this.getTable(), this.getCell(), this.name, this.value, this.valueOfValue);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ public MetaKeyValueHeader(final BaseTable table, final BaseCell key, final BaseC
protected MetaKeyValueHeader(final BaseTable table, final BaseCell key, final String name, final BaseCell value,
final String valueOfValue) {
super(table, key);

final var model = table.getSheet().getDocument().getModel();
final var cellValue = value.getValue();

this.name = name;
this.value = value;
this.valueOfValue = (valueOfValue == null)
? table.getSheet().getDocument().getModel().toEntityValue(value.getValue()).orElse(value.getValue())
? model.toEntityValue(cellValue).orElse(cellValue)
: valueOfValue;
}

protected MetaKeyValueHeader(final MetaKeyValueHeader parent) {
this(parent.getTable(), parent.getCell(), parent.name, parent.value, parent.valueOfValue);
}

@Override
public BaseHeader clone() {
return new MetaKeyValueHeader(this);
return new MetaKeyValueHeader(this.getTable(), this.getCell(), this.name, this.value, this.valueOfValue);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ protected MetaTableHeader(final BaseTable table, final BaseCell cell, final RowG
this.rowGroup = rowGroup;
}

protected MetaTableHeader(final MetaTableHeader parent) {
this(parent.getTable(), parent.getCell(), parent.rowGroup);
}

@Override
public BaseHeader clone() {
return new MetaTableHeader(this);
return new MetaTableHeader(this.getTable(), this.getCell(), this.rowGroup);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ protected PivotKeyHeader(final BaseTable table, final BaseCell cell, final Strin
: entries;
}

protected PivotKeyHeader(final PivotKeyHeader parent) {
this(parent.getTable(), parent.getCell(), parent.pivotEntityName, parent.entries);
}

@Override
public BaseHeader clone() {
return new PivotKeyHeader(this);
return new PivotKeyHeader(this.getTable(), this.getCell(), this.pivotEntityName, this.entries);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
public class PivotTypeHeader extends PivotKeyHeader {

public PivotTypeHeader(final PivotKeyHeader parent, final String name) {
super(parent);
super(parent.getTable(), parent.getCell(), parent.getPivotEntityName(), parent.getEntries());
this.name = name;
}

protected PivotTypeHeader(final PivotTypeHeader parent) {
this(parent, parent.name);
}

@Override
public PivotTypeHeader clone() {
return new PivotTypeHeader(this);
return new PivotTypeHeader(this, this.name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
public class PivotValueHeader extends PivotKeyHeader {

public PivotValueHeader(final PivotKeyHeader parent, final String name) {
super(parent.getTable(), parent.getCell());
super(parent.getTable(), parent.getCell(), parent.getPivotEntityName(), parent.getEntries());
this.name = name;
}

protected PivotValueHeader(final PivotValueHeader parent) {
this(parent, parent.name);
}

@Override
public PivotValueHeader clone() {
return new PivotValueHeader(this);
return new PivotValueHeader(this, this.name);
}

@Override
Expand All @@ -25,5 +21,10 @@ public String getName() {
}
}

public PivotValueHeader setName(final String name) {
this.name = name;
return this;
}

private String name;
}

0 comments on commit ede1232

Please sign in to comment.