From b0e8e11d263dd66a8ffc49c9cedd63d906e600ee Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 18 Jul 2024 14:18:10 +0200 Subject: [PATCH] SEBSERV-569 fixed, regression due to code cleanup --- .../seb/sebserver/gbl/model/exam/QuizData.java | 2 ++ .../ch/ethz/seb/sebserver/gbl/util/Utils.java | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/QuizData.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/QuizData.java index c171ba5f..a456c7d3 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/QuizData.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/QuizData.java @@ -253,7 +253,9 @@ public final class QuizData implements GrantEntity { } public static Comparator getComparator(final String sort) { + final boolean descending = PageSortOrder.getSortOrder(sort) == PageSortOrder.DESCENDING; + System.out.println("**************** sort: " + sort + " descending " + descending); final String sortParam = PageSortOrder.decode(sort); if (QUIZ_ATTR_NAME.equals(sortParam)) { return (qd1, qd2) -> StringUtils.compare(qd1.name, qd2.name) * ((descending) ? -1 : 1); 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 bc4c28ef..03b604b2 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 @@ -857,11 +857,23 @@ public final class Utils { } public static int compareDateTime(final DateTime dt1, final DateTime dt2, final boolean descending) { - return Objects.compare(dt1, dt1, DateTime::compareTo ) * ((descending) ? -1 : 1); + return ((dt1 == dt2) + ? 0 + : (dt1 == null || dt1 == null) + ? 1 + : (dt2 == null || dt2 == null) + ? -1 + : dt1.compareTo(dt2)) * ((descending) ? -1 : 1); } public static int compareIds(final Long id1, final Long id2, final boolean descending) { - return Objects.compare(id1, id2, Long::compareTo ) * ((descending) ? -1 : 1); + return ((Objects.equals(id1, id2)) + ? 0 + : (id1 == null || id1 == null) + ? 1 + : (id2 == null || id2 == null) + ? -1 + : id1.compareTo(id2)) * ((descending) ? -1 : 1); } public static String toFileName(final String name) {