Class SeverityComparator

  • All Implemented Interfaces:
    java.io.Serializable, java.util.Comparator<java.util.logging.LogRecord>

    public class SeverityComparator
    extends java.lang.Object
    implements java.util.Comparator<java.util.logging.LogRecord>, java.io.Serializable
    Orders log records by level, thrown, sequence, and time. This comparator orders LogRecords by how severely each is attributed to failures in a program. The primary ordering is determined by the use of the logging API throughout a program by specifying a level to each log message. The secondary ordering is determined at runtime by the type of errors and exceptions generated by the program. The remaining ordering assumes that older log records are less severe than newer log records.

    The following LogRecord properties determine severity ordering:

    1. The natural comparison of the LogRecord level.
    2. The expected recovery order of thrown property of a LogRecord and its cause chain. This ordering is derived from the JLS 11.1.1. The Kinds of Exceptions and JLS 11.5 The Exception Hierarchy. This is performed by finding the throwable that best describes the entire cause chain. Once a specific throwable of each chain is identified it is then ranked lowest to highest by the following rules:
      • All LogRecords with a Throwable defined as "normal occurrence".
      • All LogRecords that do not have a thrown object.
      • All checked exceptions. This is any class that is assignable to the java.lang.Throwable class and is not a java.lang.RuntimeException or a java.lang.Error.
      • All unchecked exceptions. This is all java.lang.RuntimeException objects.
      • All errors that indicate a serious problem. This is all java.lang.Error objects.
    3. The natural comparison of the LogRecord sequence.
    4. The natural comparison of the LogRecord millis.
    Since:
    JavaMail 1.5.2
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Throwable apply​(java.lang.Throwable chain)
      Identifies a single throwable that best describes the given throwable and the entire cause chain.
      int applyThenCompare​(java.lang.Throwable tc1, java.lang.Throwable tc2)
      Reduces each throwable chain argument then compare each throwable result.
      int compare​(java.util.logging.LogRecord o1, java.util.logging.LogRecord o2)
      Compares two log records based on severity.
      int compareThrowable​(java.lang.Throwable t1, java.lang.Throwable t2)
      Compares two throwable objects or null.
      boolean equals​(java.lang.Object o)
      Determines if the given object is also a comparator and it imposes the same ordering as this comparator.
      int hashCode()
      Returns a hash code value for the object.
      boolean isNormal​(java.lang.Throwable t)
      Determines if the given throwable instance is "normal occurrence".
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Constructor Detail

      • SeverityComparator

        public SeverityComparator()
    • Method Detail

      • apply

        public java.lang.Throwable apply​(java.lang.Throwable chain)
        Identifies a single throwable that best describes the given throwable and the entire cause chain. This method can be overridden to change the behavior of compare(java.util.logging.LogRecord, java.util.logging.LogRecord).
        Parameters:
        chain - the throwable or null.
        Returns:
        null if null was given, otherwise the throwable that best describes the entire chain.
        See Also:
        isNormal(java.lang.Throwable)
      • applyThenCompare

        public final int applyThenCompare​(java.lang.Throwable tc1,
                                          java.lang.Throwable tc2)
        Reduces each throwable chain argument then compare each throwable result.
        Parameters:
        tc1 - the first throwable chain or null.
        tc2 - the second throwable chain or null.
        Returns:
        a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
        See Also:
        apply(java.lang.Throwable), compareThrowable(java.lang.Throwable, java.lang.Throwable)
      • compareThrowable

        public int compareThrowable​(java.lang.Throwable t1,
                                    java.lang.Throwable t2)
        Compares two throwable objects or null. This method does not reduce each argument before comparing. This is method can be overridden to change the behavior of compare(LogRecord, LogRecord).
        Parameters:
        t1 - the first throwable or null.
        t2 - the second throwable or null.
        Returns:
        a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
        See Also:
        isNormal(java.lang.Throwable)
      • compare

        public int compare​(java.util.logging.LogRecord o1,
                           java.util.logging.LogRecord o2)
        Compares two log records based on severity.
        Specified by:
        compare in interface java.util.Comparator<java.util.logging.LogRecord>
        Parameters:
        o1 - the first log record.
        o2 - the second log record.
        Returns:
        a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
        Throws:
        java.lang.NullPointerException - if either argument is null.
      • equals

        public boolean equals​(java.lang.Object o)
        Determines if the given object is also a comparator and it imposes the same ordering as this comparator.
        Specified by:
        equals in interface java.util.Comparator<java.util.logging.LogRecord>
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - the reference object with which to compare.
        Returns:
        true if this object equal to the argument; false otherwise.
      • hashCode

        public int hashCode()
        Returns a hash code value for the object.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        Returns a hash code value for the object.
      • isNormal

        public boolean isNormal​(java.lang.Throwable t)
        Determines if the given throwable instance is "normal occurrence". This is any checked or unchecked exception with 'Interrupt' in the class name or ancestral class name. Any java.lang.ThreadDeath object or subclasses. This method can be overridden to change the behavior of the apply(java.lang.Throwable) method.
        Parameters:
        t - a throwable or null.
        Returns:
        true the given throwable is a "normal occurrence".