Interface ValueContainer

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      <E> java.util.Optional<E> get​(Key<? extends Value<E>> key)
      Attempts to get the underlying value backed by a Value linked to the provided Key.
      default java.util.OptionalDouble getDouble​(Key<? extends Value<java.lang.Double>> key)
      Attempts to get the underlying double value backed by a Value linked to the provided Key.
      default java.util.OptionalInt getInt​(Key<? extends Value<java.lang.Integer>> key)
      Attempts to get the underlying int value backed by a Value linked to the provided Key.
      java.util.Set<Key<?>> getKeys()
      Gets all applicable Keys for this ValueContainer.
      default java.util.OptionalLong getLong​(Key<? extends Value<java.lang.Long>> key)
      Attempts to get the underlying long value backed by a Value linked to the provided Key.
      default <E> E getOrElse​(Key<? extends Value<E>> key, E defaultValue)
      Attempts to get the underlying value if available.
      default <E> @Nullable E getOrNull​(Key<? extends Value<E>> key)
      Attempts to get the underlying value if available and supported.
      <E,​V extends Value<E>>
      java.util.Optional<V>
      getValue​(Key<V> key)
      Gets the Value for the given Key.
      java.util.Set<Value.Immutable<?>> getValues()
      Gets all applicable Values associated with this ValueContainer.
      default <E> E require​(Key<? extends Value<E>> key)
      Attempts to get the underlying value backed by a Value linked to the provided Key.
      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.
      boolean supports​(Key<?> key)
      Checks if the given Key is supported by this ValueContainer.
      default boolean supports​(Value<?> value)
      Checks if the provided Value is supported.
    • Method Detail

      • get

        <E> java.util.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
      • getInt

        default java.util.OptionalInt getInt​(Key<? extends Value<java.lang.Integer>> key)
        Attempts to get the underlying int 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).
        Parameters:
        key - The key to retrieve the value for
        Returns:
        The value, if available
      • getDouble

        default java.util.OptionalDouble getDouble​(Key<? extends Value<java.lang.Double>> key)
        Attempts to get the underlying double 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).
        Parameters:
        key - The key to retrieve the value for
        Returns:
        The value, if available
      • getLong

        default java.util.OptionalLong getLong​(Key<? extends Value<java.lang.Long>> key)
        Attempts to get the underlying long 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).
        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:
        java.util.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>> java.util.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:
        java.util.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

        java.util.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