Class SessionComparators

java.lang.Object
org.apache.catalina.util.SessionComparators

public class SessionComparators extends Object
Utility class for building Comparators over Sessions.
  • Method Details

    • comparingLongSnapshot

      public static Comparator<Session> comparingLongSnapshot(ToLongFunction<Session> keyExtractor)
      Builds a Comparator equivalent to Comparator.comparingLong(ToLongFunction), except that each session's extracted value is only read once and then cached for the remainder of the sort. Some values used to sort sessions (e.g. last accessed time, or values derived from the current time) can change while a sort is in progress, either because the session is concurrently accessed or simply because time passes. Without caching, that can make the comparator return inconsistent results for the same pair of sessions across different comparisons in the same sort, which trips java.util.TimSort's consistency check.
      Parameters:
      keyExtractor - Function that extracts the sort key from a session
      Returns:
      a comparator that sorts sessions by the (cached) extracted key