Interface PartialParser<R>

Type Parameters:
R - the type to produce

public interface PartialParser<R>
A functional interface to parse part of a String and obtain a R instance as a result. This is a functional interface whose functional method is parse(String, int, int)
  • Field Details

  • Method Details

    • parse

      R parse(String text, int start, int end)
      Creates or obtains an R object by parsing a section of text starting at start (inclusive) and ending at end (exclusive) in text.
      Parameters:
      text - a String containing a section that will be parsed
      start - the first character index to parse in text, inclusive
      end - the last character index to parse in text, exclusive
      Returns:
      a (typically new) R object loaded from the given section of text
    • enumParser

      static <E extends Enum<?>> PartialParser<E> enumParser(com.github.tommyettinger.function.ObjToObjFunction<String,E> valueOfMethod)
      Given an enum type's valueOf as a method reference, this creates a PartialParser that tries to obtain an enum of the given type using that valueOf on a substring of the parsed text. This should be useful with the EnhancedCollection.addLegible(String, String, PartialParser) method and any putLegible methods in Enum-keyed maps.
      Note that this allocates a short-lived string using String.substring(int, int), though it may be interned because it is the name of an enum constant (if it produces a result at all).
      An example of using this exists for OrderType: PartialParser<Enum<?>> DEFAULT_ORDER_TYPE = enumParser(OrderType::valueOf);
    • objectListParser

      static <T> PartialParser<ObjectList<T>> objectListParser(PartialParser<T> innerParser, String delimiter, boolean brackets)
      Creates a PartialParser that can parse a section of text with multiple T items separated by delimiter using innerParser to read each item, creates an ObjectList, populates it with EnhancedCollection.addLegible(String, String, PartialParser, int, int), and returns the new collection.
      Type Parameters:
      T - the type of items in the ObjectList this parses
      Parameters:
      innerParser - a PartialParser to read in each T item in the ObjectList this parses
      delimiter - the String that separates items in the expected text
      brackets - if true, the text will be expected to be surrounded by one bracket char on each side, which will be ignored
      Returns:
      a (typically new) ObjectList of T loaded from the given text
    • collectionParser

      static <T, C extends EnhancedCollection<T>> PartialParser<C> collectionParser(com.github.tommyettinger.function.ObjSupplier<C> supplier, PartialParser<T> innerParser, String delimiter, boolean brackets)
      Creates a PartialParser that can parse a section of text with multiple T items separated by delimiter using innerParser to read each item, creates a C EnhancedCollection with the given supplier, populates it with EnhancedCollection.addLegible(String, String, PartialParser, int, int), and returns the new collection.
      Type Parameters:
      T - the type of items in the EnhancedCollection this parses
      C - the type of EnhancedCollection of T, such as ObjectDeque or ObjectOrderedSet
      Parameters:
      supplier - typically a constructor reference to C, which can be stored for better Android performance
      innerParser - a PartialParser to read in each T item in the C this parses
      delimiter - the String that separates items in the expected text
      brackets - if true, the text will be expected to be surrounded by one bracket char on each side, which will be ignored
      Returns:
      a C (or EnhancedCollection of T) loaded from the given text
    • intCollectionParser

      static <C extends PrimitiveCollection.OfInt> PartialParser<C> intCollectionParser(com.github.tommyettinger.function.ObjSupplier<C> supplier, String delimiter, boolean brackets)
      Creates a PartialParser that can parse a section of text with multiple int items separated by delimiter, creates a PrimitiveCollection using the given supplier, populates it with PrimitiveCollection.OfInt.addLegible(String, String, int, int), and returns the new collection.
      Type Parameters:
      C - a PrimitiveCollection.OfInt type such as IntList
      Parameters:
      supplier - typically a constructor reference, which can be stored for better Android performance
      delimiter - the String that separates items in the expected text
      brackets - if true, the text will be expected to be surrounded by one bracket char on each side, which will be ignored
      Returns:
      a (typically new) PrimitiveCollection loaded from the given text
    • longCollectionParser

      static <C extends PrimitiveCollection.OfLong> PartialParser<C> longCollectionParser(com.github.tommyettinger.function.ObjSupplier<C> supplier, String delimiter, boolean brackets)
      Creates a PartialParser that can parse a section of text with multiple long items separated by delimiter, creates a PrimitiveCollection using the given supplier, populates it with PrimitiveCollection.OfLong.addLegible(String, String, int, int), and returns the new collection.
      Type Parameters:
      C - a PrimitiveCollection.OfLong type such as LongList
      Parameters:
      supplier - typically a constructor reference, which can be stored for better Android performance
      delimiter - the String that separates items in the expected text
      brackets - if true, the text will be expected to be surrounded by one bracket char on each side, which will be ignored
      Returns:
      a (typically new) PrimitiveCollection loaded from the given text
    • floatCollectionParser

      static <C extends PrimitiveCollection.OfFloat> PartialParser<C> floatCollectionParser(com.github.tommyettinger.function.ObjSupplier<C> supplier, String delimiter, boolean brackets)
      Creates a PartialParser that can parse a section of text with multiple float items separated by delimiter, creates a PrimitiveCollection using the given supplier, populates it with PrimitiveCollection.OfFloat.addLegible(String, String, int, int), and returns the new collection.
      Type Parameters:
      C - a PrimitiveCollection.OfFloat type such as FloatList
      Parameters:
      supplier - typically a constructor reference, which can be stored for better Android performance
      delimiter - the String that separates items in the expected text
      brackets - if true, the text will be expected to be surrounded by one bracket char on each side, which will be ignored
      Returns:
      a (typically new) PrimitiveCollection loaded from the given text
    • doubleCollectionParser

      static <C extends PrimitiveCollection.OfDouble> PartialParser<C> doubleCollectionParser(com.github.tommyettinger.function.ObjSupplier<C> supplier, String delimiter, boolean brackets)
      Creates a PartialParser that can parse a section of text with multiple double items separated by delimiter, creates a PrimitiveCollection using the given supplier, populates it with PrimitiveCollection.OfDouble.addLegible(String, String, int, int), and returns the new collection.
      Type Parameters:
      C - a PrimitiveCollection.OfDouble type such as DoubleList
      Parameters:
      supplier - typically a constructor reference, which can be stored for better Android performance
      delimiter - the String that separates items in the expected text
      brackets - if true, the text will be expected to be surrounded by one bracket char on each side, which will be ignored
      Returns:
      a (typically new) PrimitiveCollection loaded from the given text
    • shortCollectionParser

      static <C extends PrimitiveCollection.OfShort> PartialParser<C> shortCollectionParser(com.github.tommyettinger.function.ObjSupplier<C> supplier, String delimiter, boolean brackets)
      Creates a PartialParser that can parse a section of text with multiple short items separated by delimiter, creates a PrimitiveCollection using the given supplier, populates it with PrimitiveCollection.OfShort.addLegible(String, String, int, int), and returns the new collection.
      Type Parameters:
      C - a PrimitiveCollection.OfShort type such as ShortList
      Parameters:
      supplier - typically a constructor reference, which can be stored for better Android performance
      delimiter - the String that separates items in the expected text
      brackets - if true, the text will be expected to be surrounded by one bracket char on each side, which will be ignored
      Returns:
      a (typically new) PrimitiveCollection loaded from the given text
    • byteCollectionParser

      static <C extends PrimitiveCollection.OfByte> PartialParser<C> byteCollectionParser(com.github.tommyettinger.function.ObjSupplier<C> supplier, String delimiter, boolean brackets)
      Creates a PartialParser that can parse a section of text with multiple byte items separated by delimiter, creates a PrimitiveCollection using the given supplier, populates it with PrimitiveCollection.OfByte.addLegible(String, String, int, int), and returns the new collection.
      Type Parameters:
      C - a PrimitiveCollection.OfByte type such as ByteList
      Parameters:
      supplier - typically a constructor reference, which can be stored for better Android performance
      delimiter - the String that separates items in the expected text
      brackets - if true, the text will be expected to be surrounded by one bracket char on each side, which will be ignored
      Returns:
      a (typically new) PrimitiveCollection loaded from the given text
    • charCollectionParser

      static <C extends PrimitiveCollection.OfChar> PartialParser<C> charCollectionParser(com.github.tommyettinger.function.ObjSupplier<C> supplier, String delimiter, boolean brackets)
      Creates a PartialParser that can parse a section of text with multiple char items separated by delimiter, creates a PrimitiveCollection using the given supplier, populates it with PrimitiveCollection.OfChar.addLegible(String, String, int, int), and returns the new collection.
      Type Parameters:
      C - a PrimitiveCollection.OfChar type such as CharList
      Parameters:
      supplier - typically a constructor reference, which can be stored for better Android performance
      delimiter - the String that separates items in the expected text
      brackets - if true, the text will be expected to be surrounded by one bracket char on each side, which will be ignored
      Returns:
      a (typically new) PrimitiveCollection loaded from the given text
    • booleanCollectionParser

      static <C extends PrimitiveCollection.OfBoolean> PartialParser<C> booleanCollectionParser(com.github.tommyettinger.function.ObjSupplier<C> supplier, String delimiter, boolean brackets)
      Creates a PartialParser that can parse a section of text with multiple boolean items separated by delimiter, creates a PrimitiveCollection using the given supplier, populates it with PrimitiveCollection.OfBoolean.addLegible(String, String, int, int), and returns the new collection.
      Type Parameters:
      C - a PrimitiveCollection.OfBoolean type such as BooleanList
      Parameters:
      supplier - typically a constructor reference, which can be stored for better Android performance
      delimiter - the String that separates items in the expected text
      brackets - if true, the text will be expected to be surrounded by one bracket char on each side, which will be ignored
      Returns:
      a (typically new) PrimitiveCollection loaded from the given text