From 65332977ee78055ecc0077c8d04b68845904edc2 Mon Sep 17 00:00:00 2001 From: Patrick Strawderman Date: Tue, 31 Oct 2023 10:22:34 -0700 Subject: [PATCH] Simplify comparators in GcEvent Simplify TIME_ORDER and REVERSE_TIME_ORDER comparators by leveraging Comparator.comparing and .reversed. --- .../src/main/java/com/netflix/spectator/gc/GcEvent.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spectator-ext-gc/src/main/java/com/netflix/spectator/gc/GcEvent.java b/spectator-ext-gc/src/main/java/com/netflix/spectator/gc/GcEvent.java index 4010d7f24..e2c5ea87c 100644 --- a/spectator-ext-gc/src/main/java/com/netflix/spectator/gc/GcEvent.java +++ b/spectator-ext-gc/src/main/java/com/netflix/spectator/gc/GcEvent.java @@ -109,10 +109,8 @@ public String toString() { } /** Order events from oldest to newest. */ - public static final Comparator TIME_ORDER = - (e1, e2) -> (int) (e1.getStartTime() - e2.getStartTime()); + public static final Comparator TIME_ORDER = Comparator.comparing(GcEvent::getStartTime); /** Order events from newest to oldest. */ - public static final Comparator REVERSE_TIME_ORDER = - (e1, e2) -> (int) (e2.getStartTime() - e1.getStartTime()); + public static final Comparator REVERSE_TIME_ORDER = TIME_ORDER.reversed(); }