Package org.openstreetmap.josm.tools
Class GenericParser<U>
java.lang.Object
org.openstreetmap.josm.tools.GenericParser<U>
- Type Parameters:
U- the type of the objects to parse
- Direct Known Subclasses:
StringParser
Utility class to parse various types from other values.
- Since:
- 16184
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates an emptyGenericParserprotectedGenericParser(Map<Class<?>, Function<U, ?>> parsers) Creates a newGenericParserwith the same parsers as the specified mapGenericParser(GenericParser<U> parser) Creates a newGenericParserby deeply copyingparser -
Method Summary
Modifier and TypeMethodDescription<T> TParses the givenvalueastypeand returns the result<T> GenericParser<U>registerParser(Class<T> type, Function<U, T> value) booleanDetermines whethertypecan be parsed<T> Optional<T>Tries to parse the givenvalueastypeand returns the result.
-
Field Details
-
parsers
-
-
Constructor Details
-
GenericParser
public GenericParser()Creates an emptyGenericParser -
GenericParser
Creates a newGenericParserby deeply copyingparser- Parameters:
parser- the parser to copy
-
GenericParser
Creates a newGenericParserwith the same parsers as the specified map- Parameters:
parsers- the parsers
-
-
Method Details
-
registerParser
-
supports
Determines whethertypecan be parsed- Parameters:
type- the type- Returns:
- true if
typecan be parsed
-
parse
Parses the givenvalueastypeand returns the result- Type Parameters:
T- the type- Parameters:
type- the type classvalue- the value to parse- Returns:
- the parsed value for
stringas typetype - Throws:
UnsupportedOperationException- iftypeis not supportedUncheckedParseException- when the parsing fails
-
tryParse
Tries to parse the givenvalueastypeand returns the result.- Type Parameters:
T- the type- Parameters:
type- the type classvalue- the value to parse- Returns:
- the parsed value for
valueas typetype, orOptional.empty()(if parsing fails, or the type is not supported)
-