From 2611f4f464aa9b84325771c6386e6531dd0cca76 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 13 Mar 2024 13:45:38 +0100 Subject: [PATCH] code cleanup --- .../ch/ethz/seb/sebserver/gbl/util/Utils.java | 30 ++----------------- .../seb/sebserver/gui/table/EntityTable.java | 21 +++++++------ 2 files changed, 13 insertions(+), 38 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java index 94cd5156..3238d8a9 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java @@ -22,17 +22,7 @@ import java.nio.CharBuffer; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; +import java.util.*; import java.util.function.Predicate; import java.util.stream.Collector; import java.util.stream.Collectors; @@ -887,25 +877,11 @@ public final class Utils { } public static int compareDateTime(final DateTime dt1, final DateTime dt2, final boolean descending) { - return ((dt1 == dt2) - ? 0 - : (dt1 == null || dt1 == null) - ? 1 - : (dt2 == null || dt2 == null) - ? -1 - : dt1.compareTo(dt2)) - * ((descending) ? -1 : 1); + return Objects.compare(dt1, dt1, DateTime::compareTo ) * ((descending) ? -1 : 1); } public static int compareIds(final Long id1, final Long id2, final boolean descending) { - return ((id1 == id2) - ? 0 - : (id1 == null || id1 == null) - ? 1 - : (id2 == null || id2 == null) - ? -1 - : id1.compareTo(id2)) - * ((descending) ? -1 : 1); + return Objects.compare(id1, id2, Long::compareTo ) * ((descending) ? -1 : 1); } public static String toFileName(final String name) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java b/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java index ddcbeb9d..7bee271a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java @@ -544,13 +544,15 @@ public class EntityTable { .onError(this.pageContext::notifyUnexpectedError) .getOr(null); - this.isComplete = page.complete; this.composite.getParent().layout(true, true); PageService.updateScrolledComposite(this.composite); this.notifyContentChange(); this.notifySelectionChange(); - if (page != null && this.pageReloadListener != null) { + if (page != null) { + this.isComplete = page.complete; + } + if (this.pageReloadListener != null) { this.pageReloadListener.accept(this); } } @@ -633,8 +635,7 @@ public class EntityTable { private void adaptColumnWidthChange(final Event event) { final Widget widget = event.widget; - if (widget instanceof TableColumn) { - final TableColumn tableColumn = ((TableColumn) widget); + if (widget instanceof final TableColumn tableColumn) { if (this.filter != null) { this.filter.adaptColumnWidth( this.table.indexOf(tableColumn), @@ -676,10 +677,10 @@ public class EntityTable { for (int i = 0; i < columns.length; i++) { final ColumnDefinition columnDefinition = table.columns.get(i); if (columnDefinition.isLocalized()) { - for (int j = 0; j < items.length; j++) { + for (final TableItem item : items) { @SuppressWarnings("unchecked") - final ROW rowData = (ROW) items[j].getData(TABLE_ROW_DATA); - setValueToCell(items[j], i, columnDefinition, columnDefinition.valueSupplier.apply(rowData)); + final ROW rowData = (ROW) item.getData(TABLE_ROW_DATA); + setValueToCell(item, i, columnDefinition, columnDefinition.valueSupplier.apply(rowData)); } } } @@ -852,8 +853,7 @@ public class EntityTable { this.multiselection.remove(modelId); } else { this.multiselection.add(modelId); - Arrays.asList(this.table.getSelection()) - .stream() + Arrays.stream(this.table.getSelection()) .forEach(i -> this.multiselection.add(getModelId(i))); } multiselectFromPage(); @@ -862,8 +862,7 @@ public class EntityTable { private void multiselectFromPage() { if (this.multiselection != null) { - Arrays.asList(this.table.getItems()) - .stream() + Arrays.stream(this.table.getItems()) .forEach(item -> { final int index = this.table.indexOf(item); if (this.multiselection.contains(getModelId(item))) {