java.lang.Object
org.eclipse.angus.mail.util.logging.SeverityComparator
- All Implemented Interfaces:
Serializable
,Comparator<LogRecord>
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:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionIdentifies a single throwable that best describes the given throwable and the entire cause chain.final int
applyThenCompare
(Throwable tc1, Throwable tc2) Reduces
each throwable chain argument then compare each throwable result.int
Compares two log records based on severity.int
compareThrowable
(Throwable t1, Throwable t2) Compares two throwable objects or null.boolean
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
Determines if the given throwable instance is "normal occurrence".Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
SeverityComparator
public SeverityComparator()Creates a defaultSeverityComparator
.
-
-
Method Details
-
apply
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:
-
applyThenCompare
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:
-
compareThrowable
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:
-
compare
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
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
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".
-