Interface StringSplitter

All Superinterfaces:
Function<String,List<String>>
All Known Subinterfaces:
StringSplitter.Async
All Known Implementing Classes:
StringSplitter.Shell

public interface StringSplitter extends Function<String,List<String>>
A function that splits a string into multiple components.
Since:
1.0
Version:
1.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    A splitter that is capable of processing the split in an asynchronous manner.
    static interface 
    An iterator over the elements split by a splitter.
    static class 
    A splitter that uses a shell-like splitting algorithm, where components are separated by spaces, with the option of one or more components being delimited by quotes (single or double) to allow for the inclusion of spaces.
  • Method Summary

    Modifier and Type
    Method
    Description
    default List<String>
     
    Obtains a string that can be used to delimit two elements according to this splitter.
    Creates an empty iterator for this splitter.
    Creates a smart iterator that iterates over the components obtained by splitting the given raw string.
    Splits the given string into components.

    Methods inherited from interface java.util.function.Function

    andThen, compose
  • Method Details

    • split

      Splits the given string into components.
      Parameters:
      raw - The string to split.
      Returns:
      The split components.
    • delimiter

      @Pure String delimiter()
      Obtains a string that can be used to delimit two elements according to this splitter.

      Note that there is no guarantee that the value returned by this method is the only delimiter supported by this splitter, only that it is a valid delimiter.

      In other words, the guarantee offered by this method is that, given some string str and splitter spl, and l = spl.split(str), then spl.split(String.join(spl.delimiter(), l)).equals(l) is true.

      This implies that, for any sequence of strings s1, s2, s3, ..., then spl.split(String.join(spl.delimiter(), s1, s2, s3, ...)) gives the same result as concatenating spl.split(s1), spl.split(s2), spl.split(s3), ...

      Returns:
      The delimiter.
      API Note:
      This method
    • apply

      default List<String> apply(String raw)
      Specified by:
      apply in interface Function<String,List<String>>
    • iterate

      Creates a smart iterator that iterates over the components obtained by splitting the given raw string. The returned iterator is functionally equivalent to calling SmartIterator.from(List) on the result of split(String), but may (depending on implementation) split components lazily on demand.
      Parameters:
      raw - The string to split.
      Returns:
      A smart iterator over the split components.
      Implementation Requirements:
      The default implementation delegates to split(String) and SmartIterator.from(List).
    • emptyIterator

      @SideEffectFree default StringSplitter.Iterator emptyIterator()
      Creates an empty iterator for this splitter.
      Returns:
      The iterator.