Package com.sun.mail.util.logging
Class SeverityComparator
- java.lang.Object
-
- com.sun.mail.util.logging.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:
- The natural comparison of the LogRecord level.
- 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 ajava.lang.RuntimeException
or ajava.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.
- All LogRecords with a
- The natural comparison of the LogRecord sequence.
- The natural comparison of the LogRecord millis.
- Since:
- JavaMail 1.5.2
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SeverityComparator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Throwable
apply(Throwable chain)
Identifies a single throwable that best describes the given throwable and the entire cause chain.int
applyThenCompare(Throwable tc1, Throwable tc2)
Reduces
each throwable chain argument then compare each throwable result.int
compare(LogRecord o1, LogRecord o2)
Compares two log records based on severity.int
compareThrowable(Throwable t1, Throwable t2)
Compares two throwable objects or null.boolean
equals(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(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
-
-
-
-
Method Detail
-
apply
public Throwable apply(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 ofcompare(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(Throwable tc1, 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(Throwable t1, Throwable t2)
Compares two throwable objects or null. This method does notreduce
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 interfaceComparator<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 interfaceComparator<LogRecord>
- Overrides:
equals
in classObject
- 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.
-
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. Anyjava.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".
-
-