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 Summary
FieldsModifier and TypeFieldDescriptionstatic final PartialParser<CharSequence>static final PartialParser<Junction<String>>static final PartialParser<Enum<?>>An example of usingenumParser(ObjToObjFunction)forOrderType, this is simply the result of passingOrderType::valueOftoPartialParser.enumParser().static final PartialParser<String>WrapsString.substring(int, int). -
Method Summary
Modifier and TypeMethodDescriptionstatic <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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.OfBoolean.addLegible(String, String, int, int), and returns the new collection.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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.OfByte.addLegible(String, String, int, int), and returns the new collection.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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.OfChar.addLegible(String, String, int, int), and returns the new collection.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 multipleTitems separated bydelimiterusinginnerParserto read each item, creates aCEnhancedCollection with the givensupplier, populates it withEnhancedCollection.addLegible(String, String, PartialParser, int, int), and returns the new collection.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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.OfDouble.addLegible(String, String, int, int), and returns the new collection.static <E extends Enum<?>>
PartialParser<E>enumParser(com.github.tommyettinger.function.ObjToObjFunction<String, E> valueOfMethod) Given an enum type'svalueOfas 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.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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.OfFloat.addLegible(String, String, int, int), and returns the new collection.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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.OfInt.addLegible(String, String, int, int), and returns the new collection.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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.OfLong.addLegible(String, String, int, int), and returns the new collection.static <T> PartialParser<ObjectList<T>>objectListParser(PartialParser<T> innerParser, String delimiter, boolean brackets) Creates a PartialParser that can parse a section of text with multipleTitems separated bydelimiterusinginnerParserto read each item, creates an ObjectList, populates it withEnhancedCollection.addLegible(String, String, PartialParser, int, int), and returns the new collection.Creates or obtains anRobject by parsing a section oftextstarting atstart(inclusive) and ending atend(exclusive) in text.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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.OfShort.addLegible(String, String, int, int), and returns the new collection.
-
Field Details
-
DEFAULT_STRING
WrapsString.substring(int, int). -
DEFAULT_CHAR_SEQUENCE
-
DEFAULT_ORDER_TYPE
An example of usingenumParser(ObjToObjFunction)forOrderType, this is simply the result of passingOrderType::valueOftoPartialParser.enumParser(). -
DEFAULT_JUNCTION_STRING
-
-
Method Details
-
parse
Creates or obtains anRobject by parsing a section oftextstarting atstart(inclusive) and ending atend(exclusive) in text.- Parameters:
text- a String containing a section that will be parsedstart- the first character index to parse in text, inclusiveend- the last character index to parse in text, exclusive- Returns:
- a (typically new)
Robject 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'svalueOfas 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 theEnhancedCollection.addLegible(String, String, PartialParser)method and any putLegible methods in Enum-keyed maps.
Note that this allocates a short-lived string usingString.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 forOrderType: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 multipleTitems separated bydelimiterusinginnerParserto read each item, creates an ObjectList, populates it withEnhancedCollection.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 parsesdelimiter- the String that separates items in the expected textbrackets- 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 multipleTitems separated bydelimiterusinginnerParserto read each item, creates aCEnhancedCollection with the givensupplier, populates it withEnhancedCollection.addLegible(String, String, PartialParser, int, int), and returns the new collection.- Type Parameters:
T- the type of items in the EnhancedCollection this parsesC- the type of EnhancedCollection of T, such asObjectDequeorObjectOrderedSet- Parameters:
supplier- typically a constructor reference toC, which can be stored for better Android performanceinnerParser- a PartialParser to read in eachTitem in theCthis parsesdelimiter- the String that separates items in the expected textbrackets- 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 ofT) 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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.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 performancedelimiter- the String that separates items in the expected textbrackets- 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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.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 performancedelimiter- the String that separates items in the expected textbrackets- 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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.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 performancedelimiter- the String that separates items in the expected textbrackets- 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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.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 performancedelimiter- the String that separates items in the expected textbrackets- 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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.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 performancedelimiter- the String that separates items in the expected textbrackets- 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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.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 performancedelimiter- the String that separates items in the expected textbrackets- 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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.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 performancedelimiter- the String that separates items in the expected textbrackets- 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 bydelimiter, creates a PrimitiveCollection using the given supplier, populates it withPrimitiveCollection.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 performancedelimiter- the String that separates items in the expected textbrackets- 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
-