Interface PerThreadValue<T>

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default T compute​(java.util.function.Function<? super T,​? extends T> fn)
      Computes a new value with the help of the current one, which is returned.
      default T computeIfAbsent​(java.util.function.Supplier<? extends T> fn)
      If no value is currently stored (checked by exists()), the value provided by the supplier function is set and return.
      default T computeIfPresent​(java.util.function.Function<? super T,​? extends T> fn)
      If a value is currently stored (checked by exists()), this value is used to compute a new one with the given mapping function.
      boolean exists()
      Is a value stored (even null)?
      T get()
      Reads the current per-thread value, or returns null if no value has been stored.
      T get​(T defaultValue)
      Gets the current per-thread value if it exists (even if null), or the defaultValue if no value has been stored.
      default void ifSet​(java.util.function.Consumer<? super T> action)
      If a value is set, performs the given action with it, otherwise it does nothing.
      T set​(T newValue)
      Sets the current per-thread value, then returns that value.
    • Method Detail

      • exists

        boolean exists()
        Is a value stored (even null)?
      • get

        T get()
        Reads the current per-thread value, or returns null if no value has been stored.
      • get

        T get​(T defaultValue)
        Gets the current per-thread value if it exists (even if null), or the defaultValue if no value has been stored.
      • set

        T set​(T newValue)
        Sets the current per-thread value, then returns that value.
      • computeIfAbsent

        default T computeIfAbsent​(java.util.function.Supplier<? extends T> fn)
        If no value is currently stored (checked by exists()), the value provided by the supplier function is set and return. Otherwise, the current value is returned.
        Parameters:
        fn - the value supplier function
        Returns:
        The current (existing or computed) value
        Throws:
        java.lang.NullPointerException - if the supplier function is null
        Since:
        5.8.3
      • computeIfPresent

        default T computeIfPresent​(java.util.function.Function<? super T,​? extends T> fn)
        If a value is currently stored (checked by exists()), this value is used to compute a new one with the given mapping function. Otherwise, null is returned.
        Parameters:
        fn - the mapping function to compute the new value
        Returns:
        The new computed value, or null if none was present
        Throws:
        java.lang.NullPointerException - if the mapping function is null
        Since:
        5.8.3
      • compute

        default T compute​(java.util.function.Function<? super T,​? extends T> fn)
        Computes a new value with the help of the current one, which is returned.
        Parameters:
        fn - the mapping function to compute the new value
        Returns:
        The new computed value
        Throws:
        java.lang.NullPointerException - if the mapping function is null
        Since:
        5.8.3
      • ifSet

        default void ifSet​(java.util.function.Consumer<? super T> action)
        If a value is set, performs the given action with it, otherwise it does nothing.
        Parameters:
        action - performed action if a value is set
        Throws:
        java.lang.NullPointerException - if the action is null
        Since:
        5.8.3