Class EventContext


  • @DoNotStore
    public final class EventContext
    extends Object
    Provides context for an event outside of the direct chain of causes present in the event's Cause.
    • Method Detail

      • empty

        public static EventContext empty()
        Gets an empty context.
        Returns:
        The empty context
      • get

        public <T> Optional<T> get​(EventContextKey<T> key)
        Gets the value corresponding to the given key from the context.
        Type Parameters:
        T - The type of the value stored with the key
        Parameters:
        key - The key
        Returns:
        The context value, if found
      • get

        public <T> Optional<T> get​(Supplier<EventContextKey<T>> key)
        Gets the value corresponding to the given key from the context.
        Type Parameters:
        T - The type of the value stored with the key
        Parameters:
        key - The key
        Returns:
        The context value, if found
      • require

        public <T> T require​(EventContextKey<T> key)
        Gets the value corresponding to the given key from the context.

        If the key is not available, NoSuchElementException will be thrown.

        Type Parameters:
        T - The type of the value stored with the key
        Parameters:
        key - The key
        Returns:
        The context value, if found
      • require

        public <T> T require​(Supplier<EventContextKey<T>> key)
        Gets the value corresponding to the given key from the context.

        If the key is not available, NoSuchElementException will be thrown.

        Type Parameters:
        T - The type of the value stored with the key
        Parameters:
        key - The key
        Returns:
        The context value, if found
      • containsKey

        public boolean containsKey​(EventContextKey<?> key)
        Gets whether the provided EventContextKey is included in this context.
        Parameters:
        key - The context key to check
        Returns:
        True if the key is used and there is an entry for it
      • containsKey

        public boolean containsKey​(Supplier<? extends EventContextKey<?>> key)
        Gets whether the provided EventContextKey is included in this context.
        Parameters:
        key - The context key to check
        Returns:
        True if the key is used and there is an entry for it
      • asMap

        public Map<EventContextKey<?>,​Object> asMap()
        Gets this event context as a Map of EventContextKeys to Objects.
        Returns:
        A map view of this context
      • equals

        public boolean equals​(@Nullable Object object)
        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object