Class SessionComparators


  • public class SessionComparators
    extends java.lang.Object
    Utility class for building Comparators over Sessions.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Comparator<Session> comparingLongSnapshot​(java.util.function.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • comparingLongSnapshot

        public static java.util.Comparator<Session> comparingLongSnapshot​(java.util.function.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