Class SeverityComparator

  • All Implemented Interfaces:
    Serializable, Comparator<LogRecord>

    public class SeverityComparator
    extends Object
    implements Comparator<LogRecord>, 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
    • Constructor Detail

      • SeverityComparator

        public SeverityComparator()
    • Method Detail

      • compareThrowable

        public int compareThrowable​(Throwable t1,
                                    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​(LogRecord o1,
                           LogRecord o2)
        Compares two log records based on severity.
        Specified by:
        compare in interface Comparator<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:
        NullPointerException - if either argument is null.
      • equals

        public boolean equals​(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 Comparator<LogRecord>
        Overrides:
        equals in class 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 Object
        Returns:
        Returns a hash code value for the object.
      • isNormal

        public boolean isNormal​(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".