Skip to content

Commit 1a9f153

Browse files
committed
Improve compare table cell code
1 parent c0ddd71 commit 1a9f153

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);
@@ -211,17 +158,6 @@ private static CompareCellContent createCompareCellContent(
211158
private CompareTableCellContent createTableCompareCellContent(
212159
final TableCell mainTableCell, final TableCell compareTableCell) {
213160

214-
if (isSameValue(
215-
EObjectExtensions
216-
.getNullableObject(mainTableCell, TableCell::getContent)
217-
.orElse(null),
218-
EObjectExtensions
219-
.getNullableObject(compareTableCell,
220-
TableCell::getContent)
221-
.orElse(null))) {
222-
return null;
223-
}
224-
225161
final CompareTableCellContent compareTableCellContent = TablemodelFactory.eINSTANCE
226162
.createCompareTableCellContent();
227163
compareTableCellContent
@@ -364,7 +300,7 @@ private static Table expandNewRowGroups(final Table oldTable,
364300
return result;
365301
}
366302

367-
private static void matchRow(final TableRow row, final Table newTable) {
303+
private void matchRow(final TableRow row, final Table newTable) {
368304
final TableRow match = TableExtensions.getMatchingRow(newTable, row);
369305
// Create diff content
370306
for (int i = 0; i < row.getCells().size(); i++) {
@@ -413,7 +349,7 @@ private static List<Bearbeitungsvermerk> getFootnotes(final TableRow row) {
413349
return ((SimpleFootnoteContainer) row.getFootnotes()).getFootnotes();
414350
}
415351

416-
private static Table matchRows(final Table expanded, final Table newTable) {
352+
private Table matchRows(final Table expanded, final Table newTable) {
417353
final Table result = EcoreUtil.copy(expanded);
418354
final List<TableRow> rows = TableExtensions.getTableRows(result);
419355
rows.forEach(row -> matchRow(row, newTable));

0 commit comments

Comments
 (0)