Class StringSplitSource<K>

java.lang.Object
io.github.projectunified.valuevenue.common.StringSplitSource<K>
Type Parameters:
K - type of the key
All Implemented Interfaces:
ValueSource<K,String>, Function<K,List<String>>

public class StringSplitSource<K> extends Object implements ValueSource<K,String>
A ValueSource whose values are the pieces of a string, e.g. the lines of a setting.

The string is selected for each key by the source function and cut by the split pattern; a key without a string has no value. The variable is DEFAULT_KEY unless another key is given to the constructor, and resolves to the piece itself.

  • Field Details

    • DEFAULT_KEY

      public static final String DEFAULT_KEY
      The key used when none is given.
      See Also:
    • DEFAULT_SPLIT_PATTERN

      public static final Pattern DEFAULT_SPLIT_PATTERN
      The split pattern used when none is given: one value per line.
  • Constructor Details

    • StringSplitSource

      public StringSplitSource(Function<K,String> sourceFunction)
      Creates the source with DEFAULT_KEY and DEFAULT_SPLIT_PATTERN.
      Parameters:
      sourceFunction - the function selecting the string of a key
    • StringSplitSource

      public StringSplitSource(Function<K,String> sourceFunction, Pattern splitPattern)
      Creates the source with DEFAULT_KEY.
      Parameters:
      sourceFunction - the function selecting the string of a key
      splitPattern - the pattern the string is cut by
    • StringSplitSource

      public StringSplitSource(String key, Function<K,String> sourceFunction)
      Creates the source with DEFAULT_SPLIT_PATTERN.
      Parameters:
      key - name of the variable holding the piece itself
      sourceFunction - the function selecting the string of a key
    • StringSplitSource

      public StringSplitSource(String key, Function<K,String> sourceFunction, Pattern splitPattern)
      Creates the source.
      Parameters:
      key - name of the variable holding the piece itself
      sourceFunction - the function selecting the string of a key
      splitPattern - the pattern the string is cut by
  • Method Details

    • getSourceValueStream

      public Stream<String> 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,String>
      Parameters:
      key - key whose source values are requested
      Returns:
      stream of source values for the key
    • replace

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