Class EnumValueSource<K,SV extends Enum<SV>>

java.lang.Object
io.github.projectunified.valuevenue.common.EnumValueSource<K,SV>
Type Parameters:
K - type of the key
SV - enum type of the source value
All Implemented Interfaces:
ValueSource<K,SV>, Function<K,List<SV>>

public class EnumValueSource<K,SV extends Enum<SV>> extends Object implements ValueSource<K,SV>
A ValueSource whose source values are all constants of an enum, exposed as a single variable.

The variable is DEFAULT_KEY unless another key is given to the constructor. Override ValueSource.replace(String, Object) to add more variables, calling the default for the rest.

  • Field Details

  • Constructor Details

    • EnumValueSource

      public EnumValueSource(Class<SV> enumType)
      Creates the source with DEFAULT_KEY.
      Parameters:
      enumType - enum whose constants are the source values
    • EnumValueSource

      public EnumValueSource(String key, Class<SV> enumType)
      Creates the source.
      Parameters:
      key - name of the variable holding the constant itself
      enumType - enum whose constants are the source values
  • Method Details

    • getSourceValueStream

      public Stream<SV> getSourceValueStream()
      Description copied from interface: ValueSource
      All source values that do not depend on a key.

      Empty by default: a source that only knows its values through ValueSource.getSourceValueStream(Object) needs no override.

      Specified by:
      getSourceValueStream in interface ValueSource<K,SV extends Enum<SV>>
      Returns:
      stream of every key-independent source value
    • replace

      public Object replace(String input, SV value)
      Description copied from interface: ValueSource
      Resolves a variable of the source value.
      Specified by:
      replace in interface ValueSource<K,SV extends Enum<SV>>
      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