Top Description Fields Constructors Methods
org.apache.commons.lang3.exception

public Class DefaultExceptionContext

extends Object
implements ExceptionContext, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.lang3.exception.ExceptionContext
Imports
java.io.Serializable, java.util.ArrayList, .List, .Objects, .Set, java.util.stream.Collectors, .Stream, org.apache.commons.lang3.Strings, org.apache.commons.lang3.tuple.ImmutablePair, .Pair

Default implementation of the context storing the label-value pairs for contexted exceptions.

This implementation is serializable, however this is dependent on the values that are added also being serializable.

Since
3.0
See Also
ContextedException, ContextedRuntimeException

Field Summary

Modifier and TypeField and Description
private final List<Pair<String, Object>>
contextValues

The list storing the label-data pairs.

private static final long
serialVersionUID

The serialization version.

Constructor Summary

AccessConstructor and Description
public
DefaultExceptionContext()

Constructs a new instance.

Method Summary

Modifier and TypeMethod and Description
public DefaultExceptionContext
addContextValue(final String label, final Object value)

Implements org.apache.commons.lang3.exception.ExceptionContext.addContextValue.

Adds a contextual label-value pair into this context.

public List<Pair<String, Object>>
getContextEntries()

Implements org.apache.commons.lang3.exception.ExceptionContext.getContextEntries.

Gets the full list of label-value pairs defined in the contextual data.

public Set<String>
getContextLabels()

Implements org.apache.commons.lang3.exception.ExceptionContext.getContextLabels.

Gets the full set of labels defined in the contextual data.

public List<Object>
getContextValues(final String label)

Implements org.apache.commons.lang3.exception.ExceptionContext.getContextValues.

Gets all the contextual data values associated with the label.

public Object
getFirstContextValue(final String label)

Implements org.apache.commons.lang3.exception.ExceptionContext.getFirstContextValue.

Gets the first available contextual data value associated with the label.

public String

Returns:

the exception message with context information appended, never null
getFormattedExceptionMessage
(final String
the base exception message without context information appended
baseMessage
)

Implements org.apache.commons.lang3.exception.ExceptionContext.getFormattedExceptionMessage.

Builds the message containing the contextual information.

public DefaultExceptionContext
setContextValue(final String label, final Object value)

Implements org.apache.commons.lang3.exception.ExceptionContext.setContextValue.

Sets a contextual label-value pair into this context.

private Stream<Pair<String, Object>>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextValuesback to summary
private final List<Pair<String, Object>> contextValues

The list storing the label-data pairs.

serialVersionUIDback to summary
private static final long serialVersionUID

The serialization version.

Constructor Detail

DefaultExceptionContextback to summary
public DefaultExceptionContext()

Constructs a new instance.

Method Detail

addContextValueback to summary
public DefaultExceptionContext addContextValue(final String label, final Object value)

Implements org.apache.commons.lang3.exception.ExceptionContext.addContextValue.

Doc from org.apache.commons.lang3.exception.ExceptionContext.addContextValue.

Adds a contextual label-value pair into this context.

The pair will be added to the context, independently of an already existing pair with the same label.

Annotations
@Override
getContextEntriesback to summary
public List<Pair<String, Object>> getContextEntries()

Implements org.apache.commons.lang3.exception.ExceptionContext.getContextEntries.

Doc from org.apache.commons.lang3.exception.ExceptionContext.getContextEntries.

Gets the full list of label-value pairs defined in the contextual data.

Annotations
@Override
getContextLabelsback to summary
public Set<String> getContextLabels()

Implements org.apache.commons.lang3.exception.ExceptionContext.getContextLabels.

Doc from org.apache.commons.lang3.exception.ExceptionContext.getContextLabels.

Gets the full set of labels defined in the contextual data.

Annotations
@Override
getContextValuesback to summary
public List<Object> getContextValues(final String label)

Implements org.apache.commons.lang3.exception.ExceptionContext.getContextValues.

Doc from org.apache.commons.lang3.exception.ExceptionContext.getContextValues.

Gets all the contextual data values associated with the label.

Annotations
@Override
getFirstContextValueback to summary
public Object getFirstContextValue(final String label)

Implements org.apache.commons.lang3.exception.ExceptionContext.getFirstContextValue.

Doc from org.apache.commons.lang3.exception.ExceptionContext.getFirstContextValue.

Gets the first available contextual data value associated with the label.

Annotations
@Override
getFormattedExceptionMessageback to summary
public String getFormattedExceptionMessage(final String baseMessage)

Implements org.apache.commons.lang3.exception.ExceptionContext.getFormattedExceptionMessage.

Builds the message containing the contextual information.

Parameters
baseMessage:String

the base exception message without context information appended

Returns:String

the exception message with context information appended, never null

Annotations
@Override
setContextValueback to summary
public DefaultExceptionContext setContextValue(final String label, final Object value)

Implements org.apache.commons.lang3.exception.ExceptionContext.setContextValue.

Doc from org.apache.commons.lang3.exception.ExceptionContext.setContextValue.

Sets a contextual label-value pair into this context.

The pair will be added normally, but any existing label-value pair with the same label is removed from the context.

Annotations
@Override
streamback to summary
private Stream<Pair<String, Object>> stream()