org.testifyproject.fasterxml.jackson.databind.cfg.ContextAttributes Maven / Gradle / Ivy
package org.testifyproject.testifyproject.fasterxml.jackson.databind.cfg;
import java.util.*;
/**
* Helper class used for storing and accessing per-call attributes.
* Storage is two-layered: at higher precedence, we have actual per-call
* attributes; and at lower precedence, default attributes that may be
* defined for Object readers and writers.
*
* Note that the way mutability is implemented differs between kinds
* of attributes, to account for thread-safety: per-call attributes
* are handled assuming that instances are never shared, whereas
* changes to per-reader/per-writer attributes are made assuming
* sharing, by creating new copies instead of modifying state.
* This allows sharing of default values without per-call copying, but
* requires two-level lookup on access.
*
* @since 2.3
*/
public abstract class ContextAttributes
{
public static ContextAttributes getEmpty() {
return Impl.getEmpty();
}
/*
/**********************************************************
/* Per-reader/writer access
/**********************************************************
*/
public abstract ContextAttributes withSharedAttribute(Object key, Object value);
public abstract ContextAttributes withSharedAttributes(Map,?> attributes);
public abstract ContextAttributes withoutSharedAttribute(Object key);
/*
/**********************************************************
/* Per-operation (serialize/deserialize) access
/**********************************************************
*/
/**
* Accessor for value of specified attribute
*/
public abstract Object getAttribute(Object key);
/**
* Mutator used during call (via context) to set value of "non-shared"
* part of attribute set.
*/
public abstract ContextAttributes withPerCallAttribute(Object key, Object value);
/*
/**********************************************************
/* Default implementation
/**********************************************************
*/
public static class Impl extends ContextAttributes
implements java.io.Serializable // just so ObjectReader/ObjectWriter can retain configs
{
private static final long serialVersionUID = 1L;
protected final static Impl EMPTY = new Impl(Collections.emptyMap());
protected final static Object NULL_SURROGATE = new Object();
/**
* Shared attributes that we can not modify in-place.
*/
protected final Map,?> _shared;
/**
* Per-call attributes that we can directly modify, since they are not
* shared between threads.
*
* NOTE: typed as Object-to-Object, unlike {@link #_shared}, because
* we need to be able to modify contents, and wildcard type would
* org.testifyproject.testifyprojectplicate that access.
*/
protected transient Map