Class DynamicNumberValueSource<K,N extends Number>

java.lang.Object
io.github.projectunified.valuevenue.number.DynamicNumberValueSource<K,N>
Type Parameters:
K - type of the key
N - type of the number
All Implemented Interfaces:
ValueSource<K,N>, Function<K,List<N>>
Direct Known Subclasses:
NumberValueSource

public abstract class DynamicNumberValueSource<K,N extends Number> extends Object implements ValueSource<K,N>
A ValueSource whose values are a range of numbers, with the start, the end and the step of the range selected for each key.

The variable is DEFAULT_KEY unless another key is given to the constructor, and resolves to the plain text of the number.

  • Field Details

  • Constructor Details

    • DynamicNumberValueSource

      protected DynamicNumberValueSource(NumberType<N> type)
      Creates the source with DEFAULT_KEY, including the end.
      Parameters:
      type - the number type of the values
    • DynamicNumberValueSource

      protected DynamicNumberValueSource(NumberType<N> type, String key, boolean maxInclusive, Direction direction)
      Creates the source.
      Parameters:
      type - the number type of the values
      key - name of the variable holding the number itself
      maxInclusive - whether the end is a value of the range
      direction - the direction the values step in
  • Method Details

    • getStart

      protected abstract Number getStart(K key)
      The first value of the range of the key.
      Parameters:
      key - the key
      Returns:
      the first value
    • getEnd

      protected abstract Number getEnd(K key)
      The last value of the range of the key, or its bound when the end is not included.
      Parameters:
      key - the key
      Returns:
      the last value
    • getStep

      protected abstract Number getStep(K key)
      The distance between two values of the range of the key, positive.
      Parameters:
      key - the key
      Returns:
      the step
    • getSourceValueStream

      public Stream<N> getSourceValueStream(K key)
      Description copied from interface: ValueSource
      Source values to expose for the given key. Defaults to ValueSource.getSourceValueStream().
      Specified by:
      getSourceValueStream in interface ValueSource<K,N extends Number>
      Parameters:
      key - key whose source values are requested
      Returns:
      stream of source values for the key
    • replace

      public Object replace(String input, N value)
      Description copied from interface: ValueSource
      Resolves a variable of the source value.
      Specified by:
      replace in interface ValueSource<K,N extends Number>
      Parameters:
      input - name of the variable, without its markers
      value - source value the variable is resolved for
      Returns:
      the replacement, or null if the variable is not known