Interface Value<E>

Type Parameters:
E - The type of element wrapped by this value
All Known Subinterfaces:
CollectionValue<E,C>, CollectionValue.Immutable<E,C,I,M>, CollectionValue.Mutable<E,C,M,I>, ListValue<E>, ListValue.Immutable<E>, ListValue.Mutable<E>, MapValue<K,V>, MapValue.Immutable<K,V>, MapValue.Mutable<K,V>, SetValue<E>, SetValue.Immutable<E>, SetValue.Mutable<E>, Value.Immutable<E>, Value.Mutable<E>, WeightedCollectionValue<E>, WeightedCollectionValue.Immutable<E>, WeightedCollectionValue.Mutable<E>

public interface Value<E>
The abstract base interface for all of the "Value API". In short, a Value is a "wrapper" around an actual value from a ValueContainer. The actual value may come from various sources of the ValueContainer, but usually it's a generic dynamic system for being able to fetch values from object fields without having to know the type of Class of the ValueContainer, the getters and setters for that particular value. The driving force behind this is that instead of having a traditional hierarchical structure of data that is possible to be retrieved from an Entity, Living, etc., all that is required is
container.supports(Keys.HEALTH) ?
 container.get(Keys.HEALTH).get() : 0 
where the container is simply a ValueContainer, nothing more, nothing less.

The advantage of this is that now, these various known and unknown Value.Mutables can be retrieved by simple java generics: ValueContainer.getValue(Key). While having a Value.Mutable for something so primitive as the current health of a Living entity, the power is wielded when a Value.Mutable can be offered up to multiple ValueContainers without worrying about whether it's supported or not, or getting the right cast information.

  • Method Details

    • mutableOf

      static <E> Value.Mutable<E> mutableOf(Key<? extends Value<E>> key, E element)
      Constructs a mutable Value of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed mutable value
    • mutableOf

      static <E> Value.Mutable<E> mutableOf(Supplier<? extends Key<? extends Value<E>>> key, E element)
      Constructs a mutable Value of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed mutable value
    • immutableOf

      static <E> Value.Immutable<E> immutableOf(Key<? extends Value<E>> key, E element)
      Constructs an immutable Value of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed immutable value
    • immutableOf

      static <E> Value.Immutable<E> immutableOf(Supplier<? extends Key<? extends Value<E>>> key, E element)
      Constructs an immutable Value of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed immutable value
    • mutableOf

      static <E> ListValue.Mutable<E> mutableOf(Key<? extends ListValue<E>> key, List<E> element)
      Constructs a mutable ListValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed mutable value
    • mutableOf

      static <E> ListValue.Mutable<E> mutableOf(Supplier<? extends Key<? extends ListValue<E>>> key, List<E> element)
      Constructs a mutable ListValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed mutable value
    • immutableOf

      static <E> ListValue.Immutable<E> immutableOf(Key<? extends ListValue<E>> key, List<E> element)
      Constructs an immutable ListValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed immutable value
    • immutableOf

      static <E> ListValue.Immutable<E> immutableOf(Supplier<? extends Key<? extends ListValue<E>>> key, List<E> element)
      Constructs an immutable ListValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed immutable value
    • mutableOf

      static <E> SetValue.Mutable<E> mutableOf(Key<? extends SetValue<E>> key, Set<E> element)
      Constructs a mutable SetValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed mutable value
    • mutableOf

      static <E> SetValue.Mutable<E> mutableOf(Supplier<? extends Key<? extends SetValue<E>>> key, Set<E> element)
      Constructs a mutable SetValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed mutable value
    • immutableOf

      static <E> SetValue.Immutable<E> immutableOf(Key<? extends SetValue<E>> key, Set<E> element)
      Constructs an immutable SetValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed immutable value
    • immutableOf

      static <E> SetValue.Immutable<E> immutableOf(Supplier<? extends Key<? extends SetValue<E>>> key, Set<E> element)
      Constructs an immutable SetValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed immutable value
    • mutableOf

      static <K, V> MapValue.Mutable<K,V> mutableOf(Key<? extends MapValue<K,V>> key, Map<K,V> element)
      Constructs a mutable MapValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      K - The map key type
      V - The map value type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed mutable value
    • mutableOf

      static <K, V> MapValue.Mutable<K,V> mutableOf(Supplier<? extends Key<? extends MapValue<K,V>>> key, Map<K,V> element)
      Constructs a mutable MapValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      K - The map key type
      V - The map value type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed mutable value
    • immutableOf

      static <K, V> MapValue.Immutable<K,V> immutableOf(Key<? extends MapValue<K,V>> key, Map<K,V> element)
      Constructs an immutable MapValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      K - The map key type
      V - The map value type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed immutable value
    • immutableOf

      static <K, V> MapValue.Immutable<K,V> immutableOf(Supplier<? extends Key<? extends MapValue<K,V>>> key, Map<K,V> element)
      Constructs an immutable MapValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      K - The map key type
      V - The map value type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed immutable value
    • mutableOf

      static <E> WeightedCollectionValue.Mutable<E> mutableOf(Key<? extends WeightedCollectionValue<E>> key, WeightedTable<E> element)
      Constructs a mutable WeightedCollectionValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed mutable value
    • mutableOf

      static <E> WeightedCollectionValue.Mutable<E> mutableOf(Supplier<? extends Key<? extends WeightedCollectionValue<E>>> key, WeightedTable<E> element)
      Constructs a mutable WeightedCollectionValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed mutable value
    • immutableOf

      static <E> WeightedCollectionValue.Immutable<E> immutableOf(Key<? extends WeightedCollectionValue<E>> key, WeightedTable<E> element)
      Constructs an immutable WeightedCollectionValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed immutable value
    • immutableOf

      static <E> WeightedCollectionValue.Immutable<E> immutableOf(Supplier<? extends Key<? extends WeightedCollectionValue<E>>> key, WeightedTable<E> element)
      Constructs an immutable WeightedCollectionValue of the appropriate type based on the given Key and the element.
      Type Parameters:
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed immutable value
    • genericMutableOf

      static <V extends Value<E>, E> V genericMutableOf(Key<V> key, E element)
      Constructs a Value of the appropriate type based on the given Key and the element. The returned Value is guaranteed Value.Mutable, this means that calling asMutable() will return itself.
      Type Parameters:
      V - The value type
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed mutable value
    • genericImmutableOf

      static <V extends Value<E>, E> V genericImmutableOf(Key<V> key, E element)
      Constructs a Value of the appropriate type based on the given Key and the element. The returned Value is guaranteed Value.Immutable, this means that calling asImmutable() will return itself.
      Type Parameters:
      V - The value type
      E - The element type
      Parameters:
      key - The key
      element - The element
      Returns:
      The constructed immutable value
    • get

      E get()
      Gets the held value.
      Returns:
      The held value
    • key

      Key<? extends Value<E>> key()
      Gets the key for this Value.
      Returns:
      The key for this value
    • asMutable

      Value.Mutable<E> asMutable()
      Retrieves a mutable form of this value. Due to the vague nature of the value itself, some cases can already provide a Value.Mutable instance where this would simply return itself. In other cases, where the retrieved value is an Value.Immutable instance, a new mutable value is created with the same key and values.
      Returns:
      A mutable value
    • asMutableCopy

      Value.Mutable<E> asMutableCopy()
      Retrieves a copy in the mutable form of this value. The new is created with the same key and values.
      Returns:
      A mutable value
    • asImmutable

      Value.Immutable<E> asImmutable()
      Retrieves an immutable form of this value. Due to the vague nature of the value itself, some cases can already provide a Value.Immutable instance where this would simply return itself. In other cases, where the retrieved value is a Value.Mutable instance, a new immutable value is created with the same key and values.
      Returns:
      An immutable value