Class ContextLocals


  • public class ContextLocals
    extends Object
    Utilities to access Vert.x Context locals.
    • Method Detail

      • get

        public static <T> Optional<T> get​(String key)
        Gets the value from the context local associated with the given key.
        Type Parameters:
        T - the expected type of the associated value
        Parameters:
        key - the key, must not be null
        Returns:
        an optional containing the associated value if any, empty otherwise.
      • get

        public static <T> T get​(String key,
                                T def)
        Gets the value from the context local associated with the given key. If there is no associated value, it returns the given default.
        Type Parameters:
        T - the expected type of the associated value
        Parameters:
        key - the key, must not be null
        def - the default value returned if there is no associated value with the given key. Can be null
        Returns:
        the associated value if any, the given default otherwise.
      • put

        public static <T> void put​(String key,
                                   T value)
        Stores the given key/value in the context local. This method overwrite the existing value if any.
        Type Parameters:
        T - the expected type of the associated value
        Parameters:
        key - the key, must not be null
        value - the value, must not be null
      • remove

        public static boolean remove​(String key)
        Removes the value associated with the given key from the context locals.
        Parameters:
        key - the key, must not be null
        Returns:
        true if there were a value associated with the given key. false otherwise.