Top Description Fields Constructors Methods
com.sun.mail.util.logging

public Class SeverityComparator

extends Object
implements Comparator<LogRecord>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.util.Comparator
Imports
java.io.Serializable, java.util.Comparator, java.util.logging.Level, .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:

  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.
Author
Jason Mehrens
Since
JavaMail 1.5.2

Field Summary

Modifier and TypeField and Description
private static final Comparator<LogRecord>
INSTANCE

A single instance that is shared among the logging package.

private static final long
serialVersionUID

The generated serial version UID.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Throwable

Returns:

null if null was given, otherwise the throwable that best describes the entire chain.
apply
(final Throwable
the throwable or null.
chain
)

Identifies a single throwable that best describes the given throwable and the entire cause chain.

public final int

Returns:

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
applyThenCompare
(Throwable
the first throwable chain or null.
tc1
,
Throwable
the second throwable chain or null.
tc2
)

Reduces each throwable chain argument then compare each throwable result.

public int

Returns:

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
compare
(final LogRecord
the first log record.
o1
,
final LogRecord
the second log record.
o2
)

Implements java.util.Comparator.compare.

Compares two log records based on severity.
private int

Returns:

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
compare
(final Level
the first level.
a
,
final Level
the second level.
b
)

Implements java.util.Comparator.compare.

Compare two level objects.
private int

Returns:

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
compare
(final long
the first long.
x
,
final long
the second long.
y
)

Implements java.util.Comparator.compare.

Compare two longs.
public int

Returns:

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
compareThrowable
(final Throwable
the first throwable or null.
t1
,
final Throwable
the second throwable or null.
t2
)

Compares two throwable objects or null.

public boolean

Returns:

true if this object equal to the argument; false otherwise.
equals
(final Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Implements java.util.Comparator.equals.

Determines if the given object is also a comparator and it imposes the same ordering as this comparator.
pack-priv static SeverityComparator

Returns:

a shared instance of a SeverityComparator.
getInstance
()

A shared instance of a SeverityComparator.

public int

Returns:

Returns a hash code value for the object.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean

Returns:

true the given throwable is a "normal occurrence".
isNormal
(final Throwable
a throwable or null.
t
)

Determines if the given throwable instance is "normal occurrence".

private static String

Returns:

the message string.
toString
(final Object
argument one.
o1
,
final Object
argument two.
o2
)

Outline the message create string.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
private static final Comparator<LogRecord> INSTANCE

A single instance that is shared among the logging package. The field is declared as java.util.Comparator so WebappClassLoader.clearReferencesStaticFinal() method will ignore this field.

serialVersionUIDback to summary
private static final long serialVersionUID

The generated serial version UID.

Constructor Detail

SeverityComparatorback to summary
public SeverityComparator()

Method Detail

applyback to summary
public Throwable apply(final 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:Throwable

the throwable or null.

Returns:Throwable

null if null was given, otherwise the throwable that best describes the entire chain.

See Also
isNormal(java.lang.Throwable)
applyThenCompareback to summary
public final int applyThenCompare(Throwable tc1, Throwable tc2)

Reduces each throwable chain argument then compare each throwable result.

Parameters
tc1:Throwable

the first throwable chain or null.

tc2:Throwable

the second throwable chain or null.

Returns:int

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)
compareback to summary
public int compare(final LogRecord o1, final LogRecord o2)

Implements java.util.Comparator.compare.

Compares two log records based on severity.

Parameters
o1:LogRecord

the first log record.

o2:LogRecord

the second log record.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Annotations
@SuppressWarnings:override
Exceptions
NullPointerException:
if either argument is null.
compareback to summary
private int compare(final Level a, final Level b)

Implements java.util.Comparator.compare.

Compare two level objects.

Parameters
a:Level

the first level.

b:Level

the second level.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
private int compare(final long x, final long y)

Implements java.util.Comparator.compare.

Compare two longs. Can be removed when JDK 1.7 is required.

Parameters
x:long

the first long.

y:long

the second long.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareThrowableback to summary
public int compareThrowable(final Throwable t1, final 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:Throwable

the first throwable or null.

t2:Throwable

the second throwable or null.

Returns:int

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)
equalsback to summary
public boolean equals(final Object o)

Overrides java.lang.Object.equals.

Implements java.util.Comparator.equals.

Determines if the given object is also a comparator and it imposes the same ordering as this comparator.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object equal to the argument; false otherwise.

Annotations
@Override
getInstanceback to summary
pack-priv static SeverityComparator getInstance()

A shared instance of a SeverityComparator. This is package private so the public API is not polluted with more methods.

Returns:SeverityComparator

a shared instance of a SeverityComparator.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.

Returns:int

Returns a hash code value for the object.

Annotations
@Override
isNormalback to summary
public boolean isNormal(final 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:Throwable

a throwable or null.

Returns:boolean

true the given throwable is a "normal occurrence".

toStringback to summary
private static String toString(final Object o1, final Object o2)

Outline the message create string.

Parameters
o1:Object

argument one.

o2:Object

argument two.

Returns:String

the message string.