Skip to content

Commit c25a037

Browse files
committed
IDE-suggested drive-by: extract comparator creation
1 parent 4b6410b commit c25a037

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

modules/dcache/src/main/java/org/dcache/pool/classic/IoQueueManager.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.dcache.pool.FaultEvent;
3333
import org.dcache.pool.FaultListener;
3434
import org.dcache.pool.classic.MoverRequestScheduler.Order;
35+
import org.dcache.pool.classic.MoverRequestScheduler.PrioritizedRequest;
3536
import org.dcache.util.IoPriority;
3637
import org.slf4j.Logger;
3738
import org.slf4j.LoggerFactory;
@@ -443,24 +444,7 @@ public Serializable call() throws CommandException {
443444
.toArray(IoJobInfo[]::new);
444445
} else {
445446

446-
Comparator<MoverRequestScheduler.PrioritizedRequest> comparator;
447-
if (sortBySize) {
448-
comparator = (b, a) -> Long.compare(
449-
a.getMover().getBytesTransferred(), b.getMover().getBytesTransferred()
450-
);
451-
} else if (sortByTime) {
452-
comparator = (b, a) -> Long.compare(
453-
a.getMover().getLastTransferred(), b.getMover().getLastTransferred()
454-
);
455-
} else {
456-
comparator = (b, a) -> Integer.compare(
457-
a.getId(), b.getId()
458-
);
459-
}
460-
461-
if (reverseSort) {
462-
comparator = comparator.reversed();
463-
}
447+
Comparator<PrioritizedRequest> comparator = getPrioritizedRequestComparator();
464448

465449
StringBuilder sb = new StringBuilder();
466450
if (groupByQueue) {
@@ -478,6 +462,28 @@ public Serializable call() throws CommandException {
478462
return sb.toString();
479463
}
480464
}
465+
466+
private Comparator<PrioritizedRequest> getPrioritizedRequestComparator() {
467+
Comparator<PrioritizedRequest> comparator;
468+
if (sortBySize) {
469+
comparator = (b, a) -> Long.compare(
470+
a.getMover().getBytesTransferred(), b.getMover().getBytesTransferred()
471+
);
472+
} else if (sortByTime) {
473+
comparator = (b, a) -> Long.compare(
474+
a.getMover().getLastTransferred(), b.getMover().getLastTransferred()
475+
);
476+
} else {
477+
comparator = (b, a) -> Integer.compare(
478+
a.getId(), b.getId()
479+
);
480+
}
481+
482+
if (reverseSort) {
483+
comparator = comparator.reversed();
484+
}
485+
return comparator;
486+
}
481487
}
482488

483489
@Command(name = "p2p ls", hint = "list pool to pool source movers",

0 commit comments

Comments
 (0)