Interface ValueContainer

    • Method Detail

      • get

        <E> Optional<E> get​(Key<? extends Value<E>> key)
        Attempts to get the underlying value backed by a Value linked to the provided Key. If the Key is not supported, Optional.empty() is returned. It is important to check for support of a Key by either calling supports(Value) or supports(Key).
        Type Parameters:
        E - The type of value
        Parameters:
        key - The key to retrieve the value for
        Returns:
        The value, if available
      • require

        default <E> E require​(Key<? extends Value<E>> key)
        Attempts to get the underlying value backed by a Value linked to the provided Key.

        If the Key is not supported or available, NoSuchElementException will be thrown.

        Type Parameters:
        E - The type of value
        Parameters:
        key - The key
        Returns:
        The value
        Throws:
        NoSuchElementException - If the value is not supported or present
      • getOrNull

        default <E> @Nullable E getOrNull​(Key<? extends Value<E>> key)
        Attempts to get the underlying value if available and supported. If the Value is not supported whatsoever by this ValueContainer, an exception is thrown.
        Type Parameters:
        E - The type of value
        Parameters:
        key - The Key backing the Value
        Returns:
        The value, or null if not set
      • getOrElse

        default <E> E getOrElse​(Key<? extends Value<E>> key,
                                E defaultValue)
        Attempts to get the underlying value if available. If the value is not set, the given defaultValue is returned, if the Value is even supported.
        Type Parameters:
        E - The type of value
        Parameters:
        key - The key backing the Value
        defaultValue - The value to default to if not set
        Returns:
        The value, or default if not set
      • getValue

        <E,​V extends Value<E>> Optional<V> getValue​(Key<V> key)
        Gets the Value for the given Key.
        Type Parameters:
        E - The type of the return type
        V - The type of value
        Parameters:
        key - The key linked to the Value
        Returns:
        The value, if available
      • requireValue

        default <E,​V extends Value<E>> V requireValue​(Key<V> key)
        Attempts to get the underlying value backed by a Value linked to the provided Key.

        If the Key is not supported or available, NoSuchElementException will be thrown.

        Type Parameters:
        E - The type of element wrapped by the value
        V - The type of value
        Parameters:
        key - The key
        Returns:
        The value
        Throws:
        NoSuchElementException - If the value is not supported or present
      • supports

        boolean supports​(Key<?> key)
        Checks if the given Key is supported by this ValueContainer.
        Parameters:
        key - The key to check
        Returns:
        True if the key and value backed by the key is supported
      • supports

        default boolean supports​(Value<?> value)
        Checks if the provided Value is supported.
        Parameters:
        value - The base value to check
        Returns:
        True if the base value is supported
      • getValues

        Set<Value.Immutable<?>> getValues()
        Gets all applicable Values associated with this ValueContainer. As the data backed by the values are copied, any modifications to the Values will not be reflected onto this ValueContainer.
        Returns:
        An immutable set of copied values