Package org.bytemechanics.commons.string
Enum GenericTextParser
- java.lang.Object
-
- java.lang.Enum<GenericTextParser>
-
- org.bytemechanics.commons.string.GenericTextParser
-
- All Implemented Interfaces:
Serializable
,Comparable<GenericTextParser>
public enum GenericTextParser extends Enum<GenericTextParser>
Generic type text parser and formatter- Since:
- 1.1.0, 1.3.0
- Author:
- afarre
-
-
Enum Constant Summary
Enum Constants Enum Constant Description BIGDECIMAL
Default format: #,##0.0#BOOLEAN
CHAR
DOUBLE
Default format: #0.0ENUM
FLOAT
Default format: #0.0INTEGER
Default format: #0LOCALDATE
Default format: DateTimeFormatter.ISO_DATELOCALDATETIME
Default format: DateTimeFormatter.ISO_DATE_TIMELOCALTIME
Default format: DateTimeFormatter.ISO_TIMELONG
Default format: #0PATH
SHORT
Default format: #0STRING
UNSENSITIVE_ENUM
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Optional<GenericTextParser>
find(Class _class)
Try to return an available parser for the given classstatic Optional<GenericTextParser>
find(Object _object)
Try to convert the given object to string usign default formatOptional<String>
format(Object _object)
Convert the given object to string with default formatOptional<String>
format(Object _object, String _format)
Convert the given object to string with the given format if not null, otherwise uses default format<T> Optional<T>
parse(Class<T> _class, String _string)
Convert the given string to the intended _class usign default format<T> Optional<T>
parse(Class<T> _class, String _string, String _format)
Convert the given string to the intended _class usign the given format if not null, otherwise uses default formatOptional<Object>
parse(String _string)
Convert the given string to enum target usign default formatOptional<Object>
parse(String _string, String _format)
Convert the given string to enum target usign the given format if not null, otherwise uses default formatstatic Optional<String>
toFormattedString(Object _object)
Try to convert the given object to string usign default formatstatic Optional<String>
toFormattedString(Object _object, String _format)
Try to convert the given object to string usign the given format if not null, otherwise uses default formatString
toString()
static <T> Optional<T>
toValue(Class<T> _class, String _string)
Try to convert the given string to the intended _class usign default formatstatic <T> Optional<T>
toValue(Class<T> _class, String _string, String _format)
Try to convert the given string to the intended _class usign the given format if not null, otherwise uses default formatstatic GenericTextParser
valueOf(String name)
Returns the enum constant of this type with the specified name.static GenericTextParser[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
BOOLEAN
public static final GenericTextParser BOOLEAN
-
CHAR
public static final GenericTextParser CHAR
-
SHORT
public static final GenericTextParser SHORT
Default format: #0- See Also:
DecimalFormat
-
INTEGER
public static final GenericTextParser INTEGER
Default format: #0- See Also:
DecimalFormat
-
LONG
public static final GenericTextParser LONG
Default format: #0- See Also:
DecimalFormat
-
FLOAT
public static final GenericTextParser FLOAT
Default format: #0.0- See Also:
DecimalFormat
-
DOUBLE
public static final GenericTextParser DOUBLE
Default format: #0.0- See Also:
DecimalFormat
-
BIGDECIMAL
public static final GenericTextParser BIGDECIMAL
Default format: #,##0.0#- See Also:
DecimalFormat
-
STRING
public static final GenericTextParser STRING
-
LOCALTIME
public static final GenericTextParser LOCALTIME
Default format: DateTimeFormatter.ISO_TIME- See Also:
DateTimeFormatter
-
LOCALDATE
public static final GenericTextParser LOCALDATE
Default format: DateTimeFormatter.ISO_DATE- See Also:
DateTimeFormatter
-
LOCALDATETIME
public static final GenericTextParser LOCALDATETIME
Default format: DateTimeFormatter.ISO_DATE_TIME- See Also:
DateTimeFormatter
-
ENUM
public static final GenericTextParser ENUM
-
UNSENSITIVE_ENUM
public static final GenericTextParser UNSENSITIVE_ENUM
-
PATH
public static final GenericTextParser PATH
-
-
Method Detail
-
values
public static GenericTextParser[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (GenericTextParser c : GenericTextParser.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static GenericTextParser valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
format
public Optional<String> format(Object _object)
Convert the given object to string with default format- Parameters:
_object
- object to format- Returns:
- an optional of the object converted to string (if the given object can not be converted, its not the correct type, throws an exception)
-
format
public Optional<String> format(Object _object, String _format)
Convert the given object to string with the given format if not null, otherwise uses default format- Parameters:
_object
- object to format_format
- format to use to convert object to string (can be null)- Returns:
- an optional of the object converted to string (if the given object can not be converted, its not the correct type, throws an exception)
-
parse
public <T> Optional<T> parse(Class<T> _class, String _string)
Convert the given string to the intended _class usign default format- Type Parameters:
T
- type of the class- Parameters:
_class
- Class which we want once converted_string
- String to convert- Returns:
- an optional of the string converted to object (if the given string can not be converted or enum target or its not castable to _class, throws an exception)
- Throws:
ClassCastException
- if the enum target its not castable to the given _classDateTimeParseException
- if is parsing a date/time or datetimeNumberFormatException
- if is parsing a non parseable numeric
-
parse
public Optional<Object> parse(String _string)
Convert the given string to enum target usign default format- Parameters:
_string
- String to convert- Returns:
- an optional of the string converted to enum target (if the given string can not be converted, throws an exception)
- Throws:
DateTimeParseException
- if is parsing a date/time or datetimeNumberFormatException
- if is parsing a non parseable numeric
-
parse
public <T> Optional<T> parse(Class<T> _class, String _string, String _format)
Convert the given string to the intended _class usign the given format if not null, otherwise uses default format- Type Parameters:
T
- type of the class- Parameters:
_class
- Class which we want once converted_string
- String to convert_format
- format to use to convert object to string (can be null)- Returns:
- an optional of the string converted to _class (if the given string can not be converted or enum target its not castable to _class, throws an exception)
- Throws:
ClassCastException
- if the enum target its not castable to the given _classDateTimeParseException
- if is parsing a date/time or datetimeNumberFormatException
- if is parsing a non parseable numeric
-
parse
public Optional<Object> parse(String _string, String _format)
Convert the given string to enum target usign the given format if not null, otherwise uses default format- Parameters:
_string
- String to convert_format
- format to use to convert object to string (can be null)- Returns:
- an optional of the string converted to enum target (if the given string can not be converted, throws an exception)
- Throws:
DateTimeParseException
- if is parsing a date/time or datetimeNumberFormatException
- if is parsing a non parseable numeric
-
find
public static Optional<GenericTextParser> find(Object _object)
Try to convert the given object to string usign default format- Parameters:
_object
- object to format- Returns:
- an optional of the object converted to string (if the given object can not be converted, its not the correct type, throws an exception)
- Since:
- 1.2.0
-
find
public static Optional<GenericTextParser> find(Class _class)
Try to return an available parser for the given class- Parameters:
_class
- class to parse- Returns:
- an optional of the appropiate converter or an empty optional
- Since:
- 1.2.0
-
toFormattedString
public static final Optional<String> toFormattedString(Object _object)
Try to convert the given object to string usign default format- Parameters:
_object
- object to format- Returns:
- an optional of the object converted to string (if the given object can not be converted, its not the correct type, throws an exception)
-
toFormattedString
public static final Optional<String> toFormattedString(Object _object, String _format)
Try to convert the given object to string usign the given format if not null, otherwise uses default format- Parameters:
_object
- object to format_format
- format to use to convert object to string (can be null)- Returns:
- an optional of the object converted to string (if the given object can not be converted, its not the correct type, throws an exception)
-
toValue
public static final <T> Optional<T> toValue(Class<T> _class, String _string)
Try to convert the given string to the intended _class usign default format- Type Parameters:
T
- type of the class- Parameters:
_class
- Class which we want once converted_string
- String to convert- Returns:
- an optional of the string converted to _class if any suitable converter found for the given _class
- Throws:
DateTimeParseException
- if is parsing a date/time or datetimeNumberFormatException
- if is parsing a non parseable numeric
-
toValue
public static final <T> Optional<T> toValue(Class<T> _class, String _string, String _format)
Try to convert the given string to the intended _class usign the given format if not null, otherwise uses default format- Type Parameters:
T
- type of the class- Parameters:
_class
- Class which we want once converted_string
- String to convert_format
- format to use to convert object to string (can be null)- Returns:
- an optional of the string converted to _class if any suitable converter found for the given _class
- Throws:
DateTimeParseException
- if is parsing a date/time or datetimeNumberFormatException
- if is parsing a non parseable numeric
-
toString
public String toString()
- Overrides:
toString
in classEnum<GenericTextParser>
-
-