class KeyValue<K, V> extends Value<V> {

    private final K key;

    /**
     * Serializable constructor.
     */
    protected KeyValue() {
        super(null);
        this.key = null;
    }

    private KeyValue(K key, V value) {

        super(value);

        LettuceAssert.notNull(key, "Key must not be null");
        this.key = key;
    }

    /**
     * Creates a {@link KeyValue} from a {@code key} and an {@link Optional}. The resulting value contains the value from the
     * {@link Optional} if a value is present. Value is empty if the {@link Optional} is empty.
     *
     * @param key the key, must not be {@code null}.
     * @param optional the optional. May be empty but never {@code null}.
     * @return the {@link KeyValue}
     */
    public static <K, T extends V, V> KeyValue<K, V> from(K key, Optional<T> optional) {<FILL_FUNCTION_BODY>}

    /**
     * Creates a {@link KeyValue} from a {@code key} and{@code value}. The resulting value contains the value if the
     * {@code value} is not null.
     *
     * @param key the key, must not be {@code null}.
     * @param value the value. May be {@code null}.
     * @return the {@link KeyValue}
     */
    public static <K, T extends V, V> KeyValue<K, V> fromNullable(K key, T value) {

        if (value == null) {
            return empty(key);
        }

        return new KeyValue<K, V>(key, value);
    }

    /**
     * Returns an empty {@code KeyValue} instance with the {@code key} set. No value is present for this instance.
     *
     * @param key the key, must not be {@code null}.
     * @return the {@link KeyValue}
     */
    public static <K, V> KeyValue<K, V> empty(K key) {
        return new KeyValue<K, V>(key, null);
    }

    /**
     * Creates a {@link KeyValue} from a {@code key} and {@code value}. The resulting value contains the value.
     *
     * @param key the key. Must not be {@code null}.
     * @param value the value. Must not be {@code null}.
     * @return the {@link KeyValue}
     */
    public static <K, T extends V, V> KeyValue<K, V> just(K key, T value) {

        LettuceAssert.notNull(value, "Value must not be null");

        return new KeyValue<K, V>(key, value);
    }

    @Override
    public boolean equals(Object o) {

        if (this == o)
            return true;
        if (!(o instanceof KeyValue))
            return false;

        if (!super.equals(o))
            return false;

        KeyValue<?, ?> keyValue = (KeyValue<?, ?>) o;

        return key.equals(keyValue.key);
    }

    @Override
    public int hashCode() {
        int result = key.hashCode();
        result = 31 * result + (hasValue() ? getValue().hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return hasValue() ? String.format("KeyValue[%s, %s]", key, getValue()) : String.format("KeyValue[%s].empty", key);
    }

    /**
     *
     * @return the key
     */
    public K getKey() {
        return key;
    }

    /**
     * Returns a {@link KeyValue} consisting of the results of applying the given function to the value of this element. Mapping
     * is performed only if a {@link #hasValue() value is present}.
     *
     * @param <R> The element type of the new {@link KeyValue}
     * @param mapper a stateless function to apply to each element
     * @return the new {@link KeyValue}
     */
    @SuppressWarnings("unchecked")
    @Override
    public <R> KeyValue<K, R> map(Function<? super V, ? extends R> mapper) {

        LettuceAssert.notNull(mapper, "Mapper function must not be null");

        if (hasValue()) {
            return new KeyValue<>(getKey(), mapper.apply(getValue()));
        }

        return (KeyValue<K, R>) this;
    }

}


        LettuceAssert.notNull(optional, "Optional must not be null");

        if (optional.isPresent()) {
            return new KeyValue<K, V>(key, optional.get());
        }

        return empty(key);
    
<methods>public static Value<V> empty() ,public boolean equals(java.lang.Object) ,public static Value<V> from(Optional<T>) ,public static Value<V> fromNullable(T) ,public V getValue() ,public V getValueOrElse(V) ,public V getValueOrElseGet(Supplier<V>) ,public V getValueOrElseThrow(Supplier<? extends X>) throws X,public boolean hasValue() ,public int hashCode() ,public void ifEmpty(java.lang.Runnable) ,public void ifHasValue(Consumer<? super V>) ,public void ifHasValueOrElse(Consumer<? super V>, java.lang.Runnable) ,public boolean isEmpty() ,public static Value<V> just(T) ,public Value<R> map(Function<? super V,? extends R>) ,public Optional<V> optional() ,public Stream<V> stream() ,public java.lang.String toString() <variables>private static final Value<java.lang.Object> EMPTY,private final non-sealed V value