Package com.mongodb

Interface RequestContext

    • Method Detail

      • get

        default <T> T get​(Class<T> key)
        Resolve a value given a type key within the RequestContext.
        Type Parameters:
        T - an unchecked casted generic for fluent typing convenience
        Parameters:
        key - a type key to resolve the value within the context
        Returns:
        the value resolved for this type key (throws if key not found)
        Throws:
        NoSuchElementException - when the given type key is not present
        See Also:
        getOrDefault(Object, Object), getOrEmpty(Object)
      • getOrDefault

        @Nullable
        default <T> T getOrDefault​(Object key,
                                   @Nullable
                                   T defaultValue)
        Resolve a value given a key within the RequestContext. If unresolved return the passed default value.
        Type Parameters:
        T - an unchecked casted generic for fluent typing convenience
        Parameters:
        key - a lookup key to resolve the value within the context
        defaultValue - a fallback value if key doesn't resolve
        Returns:
        the value resolved for this key, or the given default if not present
      • getOrEmpty

        default <T> Optional<T> getOrEmpty​(Object key)
        Resolve a value given a key within the RequestContext.
        Type Parameters:
        T - an unchecked casted generic for fluent typing convenience
        Parameters:
        key - a lookup key to resolve the value within the context
        Returns:
        an Optional of the value for that key.
      • hasKey

        boolean hasKey​(Object key)
        Return true if a particular key resolves to a value within the RequestContext.
        Parameters:
        key - a lookup key to test for
        Returns:
        true if this context contains the given key
      • put

        void put​(Object key,
                 Object value)
        Modifies this instance with the given key and value. If that key existed in the current RequestContext, its associated value is replaced.
        Parameters:
        key - the key to add/update
        value - the value to associate to the key
        Throws:
        NullPointerException - if either the key or value are null
      • putNonNull

        default void putNonNull​(Object key,
                                @Nullable
                                Object valueOrNull)
        Modifies this instance with the given key and value only if the value is not null. If that key existed in the current Context, its associated value is replaced in the resulting RequestContext.
        Parameters:
        key - the key to add/update
        valueOrNull - the value to associate to the key, null to ignore the operation
        Throws:
        NullPointerException - if the key is null
      • delete

        void delete​(Object key)
        Delete the given key and its associated value from the RequestContext.
        Parameters:
        key - the key to remove.
      • size

        int size()
        Return the size of this RequestContext, the number of key/value pairs stored inside it.
        Returns:
        the size of the RequestContext
      • stream

        Stream<Map.Entry<Object,​Object>> stream()
        Stream key/value pairs from this RequestContext

        It is not specified whether modification of a Map.Entry instance in the Stream results in a modification of the state of the RequestContext, or whether the Map.Entry instances are modifiable. That is considered an implementation detail, so users of this method should not rely on the behavior one way or the other unless the implementing class has documented it.

        Returns:
        a Stream of key/value pairs held by this context