Class ScoredValue<V>

  • Type Parameters:
    V - Value type.
    All Implemented Interfaces:
    Serializable

    public class ScoredValue<V>
    extends Value<V>
    A scored-value extension to Value.
    Author:
    Will Glozer, Mark Paluch
    See Also:
    Serialized Form
    • Constructor Detail

      • ScoredValue

        protected ScoredValue()
        Serializable constructor.
    • Method Detail

      • from

        public static <T extends V,​V> Value<V> from​(double score,
                                                          Optional<T> optional)
        Creates a Value from a key and an Optional. The resulting value contains the value from the Optional if a value is present. Value is empty if the Optional is empty.
        Parameters:
        score - the score.
        optional - the optional. May be empty but never null.
        Returns:
        the Value.
      • fromNullable

        public static <T extends V,​V> Value<V> fromNullable​(double score,
                                                                  T value)
        Creates a Value from a score and value. The resulting value contains the value if the value is not null.
        Parameters:
        score - the score.
        value - the value. May be null.
        Returns:
        the Value.
      • empty

        public static <V> ScoredValue<V> empty()
        Returns an empty ScoredValue instance. No value is present for this instance.
        Returns:
        the ScoredValue
      • just

        public static <T extends V,​V> ScoredValue<V> just​(double score,
                                                                T value)
        Creates a ScoredValue from a key and value. The resulting value contains the value.
        Parameters:
        score - the score.
        value - the value. Must not be null.
        Returns:
        the ScoredValue.
      • getScore

        public double getScore()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Value<V>
      • map

        public <R> ScoredValue<R> map​(Function<? super V,​? extends R> mapper)
        Returns a ScoredValue consisting of the results of applying the given function to the value of this element. Mapping is performed only if a value is present.
        Overrides:
        map in class Value<V>
        Type Parameters:
        R - element type of the new ScoredValue.
        Parameters:
        mapper - a stateless function to apply to each element.
        Returns:
        the new ScoredValue.
      • mapScore

        public ScoredValue<V> mapScore​(Function<? super Number,​? extends Number> mapper)
        Returns a ScoredValue consisting of the results of applying the given function to the score of this element. Mapping is performed only if a value is present.
        Parameters:
        mapper - a stateless function to apply to each element.
        Returns:
        the new ScoredValue .