Class ThreadLocalValue<T>

  • Type Parameters:
    T - the value type
    All Implemented Interfaces:
    Value<T>

    public final class ThreadLocalValue<T>
    extends java.lang.Object
    implements Value<T>
    A thread-local value. Used to pass values in special situations.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.ThreadLocal<Value<? extends T>> threadLocal  
    • Constructor Summary

      Constructors 
      Constructor Description
      ThreadLocalValue()
      Construct a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Value<? extends T> getAndSetValue​(Value<? extends T> newValue)
      Get and set the value.
      T getValue()
      Get the actual value.
      void setValue​(Value<? extends T> newValue)
      Set this value, replacing any current value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • threadLocal

        private final java.lang.ThreadLocal<Value<? extends T>> threadLocal
    • Constructor Detail

      • ThreadLocalValue

        public ThreadLocalValue()
        Construct a new instance.
    • Method Detail

      • getValue

        public T getValue()
        Get the actual value.
        Specified by:
        getValue in interface Value<T>
        Returns:
        the actual value
      • setValue

        public void setValue​(Value<? extends T> newValue)
        Set this value, replacing any current value.
        Parameters:
        newValue - the new value to set
      • getAndSetValue

        public Value<? extends T> getAndSetValue​(Value<? extends T> newValue)
        Get and set the value. Returns the old value so it can be restored later on (typically in a finally block).
        Parameters:
        newValue - the new value
        Returns:
        the old value