Skip to content

Commit 3cd209a

Browse files
committed
fix sorter
1 parent 4b5892d commit 3cd209a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

srv/src/main/java/my/bookshop/handlers/HierarchyHandler.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,20 @@ public int compare(GenreHierarchy gh1, GenreHierarchy gh2) {
275275
Deque<String> path2 = getPath(gh2);
276276
int res = 0;
277277

278-
while (!path1.isEmpty() && !path2.isEmpty()) {
278+
while (true) {
279+
if (path1.isEmpty()) {
280+
return path2.isEmpty() ? 0 : -1;
281+
}
282+
if (path2.isEmpty()) {
283+
return +1;
284+
}
279285
String last1 = path1.pop();
280286
String last2 = path2.pop();
281287
res = last1.compareTo(last2);
282288
if (res != 0) {
283289
return res;
284290
}
285291
}
286-
return res;
287292
}
288293

289294
Deque<String> getPath(GenreHierarchy gh) {

0 commit comments

Comments
 (0)