Skip to content

Commit e424092

Browse files
committed
Improve compare table cell code
1 parent af81935 commit e424092

File tree

1 file changed

+13
-77
lines changed

1 file changed

+13
-77
lines changed

java/bundles/org.eclipse.set.feature.export/src/org/eclipse/set/feature/export/tablediff/CustomTableDiffService.java

Lines changed: 13 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ private static void addEmptyValue(final TableRow row,
6868
row.getCells().add(cell);
6969
}
7070

71+
@SuppressWarnings("unused")
7172
private static void addMissingRowGroup(final RowGroup group,
7273
final Table table) {
7374
String groupGuid = null;
@@ -110,7 +111,7 @@ private static void addMissingRowGroup(final RowGroup group,
110111
}
111112
}
112113

113-
private static void createDiffContent(final int i, final TableRow row,
114+
private void createDiffContent(final int i, final TableRow row,
114115
final TableRow match,
115116
final BiFunction<TableCell, TableCell, CellContent> createCompareContent) {
116117
final TableCell oldCell = row.getCells().get(i);
@@ -120,76 +121,22 @@ private static void createDiffContent(final int i, final TableRow row,
120121
if (match != null) {
121122
newCell = match.getCells().get(i);
122123
}
123-
if (oldCell.getContent() instanceof MultiColorCellContent) {
124-
createMultiColorDiffCotent(oldCell, newCell);
124+
125+
final CellContent oldCellContent = EObjectExtensions
126+
.getNullableObject(oldCell, TableCell::getContent)
127+
.orElse(null);
128+
final CellContent newCellContent = EObjectExtensions
129+
.getNullableObject(newCell, TableCell::getContent)
130+
.orElse(null);
131+
if (isSameValue(oldCellContent, newCellContent)) {
125132
return;
126133
}
134+
127135
final CellContent compareCellContent = createCompareContent
128136
.apply(oldCell, newCell);
129-
if (compareCellContent == null) {
130-
return;
131-
}
132137
oldCell.setContent(compareCellContent);
133138
}
134139

135-
// IMPROVE: this function isn't completely.
136-
private static void createMultiColorDiffCotent(final TableCell oldCell,
137-
final TableCell newCell) {
138-
if (oldCell.getContent() instanceof MultiColorCellContent) {
139-
if (newCell != null && newCell
140-
.getContent() instanceof final MultiColorCellContent newCellContent) {
141-
final MultiColorCellContent clone = EcoreUtil
142-
.copy(newCellContent);
143-
144-
oldCell.setContent(clone);
145-
}
146-
final MultiColorCellContent oldCellContent = (MultiColorCellContent) oldCell
147-
.getContent();
148-
oldCellContent.getValue()
149-
.forEach(e -> e.setDisableMultiColor(false));
150-
}
151-
}
152-
153-
// if (oldCell
154-
// .getContent() instanceof final MultiColorCellContent oldCellContent
155-
// && newCell
156-
// .getContent() instanceof final MultiColorCellContent newCellContent)
157-
// {
158-
// final BiFunction<MultiColorCellContent, Function<MultiColorContent,
159-
// String>, Set<String>> getIterableStr = (
160-
// cellContent, getValueFunc) -> cellContent.getValue()
161-
// .stream()
162-
// .map(getValueFunc::apply)
163-
// .collect(Collectors.toSet());
164-
//
165-
// final Set<String> oldMultiColorValueStr = getIterableStr.apply(
166-
// oldCellContent, MultiColorContent::getMultiColorValue);
167-
// final Set<String> newMultiColorValueStr = getIterableStr.apply(
168-
// newCellContent, MultiColorContent::getMultiColorValue);
169-
// final Set<String> oldStringformatValueStr = getIterableStr
170-
// .apply(oldCellContent, MultiColorContent::getStringFormat);
171-
// final Set<String> newStringformatValueStr = getIterableStr
172-
// .apply(newCellContent, MultiColorContent::getStringFormat);
173-
// // Fall multicolor value of both is empty, but stringformat is
174-
// // difference, then replace OldContent with CompareCellContent
175-
// if (oldMultiColorValueStr.isEmpty()
176-
// && newMultiColorValueStr.isEmpty()
177-
// && !oldStringformatValueStr
178-
// .equals(newStringformatValueStr)) {
179-
// oldCell.setContent(createCompareCellContent(
180-
// oldStringformatValueStr, newStringformatValueStr,
181-
// oldCellContent.getSeparator()));
182-
// // Fall multicolor
183-
// } else if (!oldMultiColorValueStr.isEmpty()
184-
// && !newMultiColorValueStr.isEmpty()
185-
// && !oldMultiColorValueStr.equals(newMultiColorValueStr)) {
186-
// final MultiColorCellContent clone = EcoreUtil
187-
// .copy(newCellContent);
188-
// clone.getValue().forEach(e -> e.setDisableMultiColor(false));
189-
// oldCell.setContent(clone);
190-
// }
191-
// }
192-
193140
private static CompareCellContent createCompareCellContent(
194141
final TableCell oldCell, final TableCell newCell) {
195142
final Set<String> oldValues = getIterableStringValue(oldCell);
@@ -209,17 +156,6 @@ private static CompareCellContent createCompareCellContent(
209156
private CompareTableCellContent createTableCompareCellContent(
210157
final TableCell mainTableCell, final TableCell compareTableCell) {
211158

212-
if (isSameValue(
213-
EObjectExtensions
214-
.getNullableObject(mainTableCell, TableCell::getContent)
215-
.orElse(null),
216-
EObjectExtensions
217-
.getNullableObject(compareTableCell,
218-
TableCell::getContent)
219-
.orElse(null))) {
220-
return null;
221-
}
222-
223159
final CompareTableCellContent compareTableCellContent = TablemodelFactory.eINSTANCE
224160
.createCompareTableCellContent();
225161
compareTableCellContent
@@ -362,7 +298,7 @@ private static Table expandNewRowGroups(final Table oldTable,
362298
return result;
363299
}
364300

365-
private static void matchRow(final TableRow row, final Table newTable) {
301+
private void matchRow(final TableRow row, final Table newTable) {
366302
final TableRow match = TableExtensions.getMatchingRow(newTable, row);
367303
// Create diff content
368304
for (int i = 0; i < row.getCells().size(); i++) {
@@ -411,7 +347,7 @@ private static List<Bearbeitungsvermerk> getFootnotes(final TableRow row) {
411347
return ((SimpleFootnoteContainer) row.getFootnotes()).getFootnotes();
412348
}
413349

414-
private static Table matchRows(final Table expanded, final Table newTable) {
350+
private Table matchRows(final Table expanded, final Table newTable) {
415351
final Table result = EcoreUtil.copy(expanded);
416352
final List<TableRow> rows = TableExtensions.getTableRows(result);
417353
rows.forEach(row -> matchRow(row, newTable));

0 commit comments

Comments
 (0)