Package net.obvj.confectory.util
Class TypeFactory
- java.lang.Object
-
- net.obvj.confectory.util.TypeFactory
-
public class TypeFactory extends Object
A class that contains built-in parsers from string into common object types, typically for Reflection purposes.It supports all of the primitive types (including their wrappers) as well as enumerations and following object types:
From the
java.timepackage:java.time.Durationsuch as"PT15M"(15 minutes)java.time.Instantsuch as"2007-12-03T13:15:30Z"java.time.LocalDatesuch as"2007-12-03"java.time.LocalTimesuch as"10:15"or"10:15:30"java.time.LocalDateTimesuch as"2007-12-03T10:15:30"java.time.OffsetDateTimesuch as"2007-12-03T10:15:30-03:00"java.time.OffsetTimesuch as"10:15:30+01:00"java.time.ZonedDateTimesuch as"2007-12-03T10:15:30-03:00[America/Sao_Paulo]"java.time.ZoneIdsuch as"Europe/Paris"or"+01:00"java.time.ZoneOffsetsuch as"+01","+0100"or"+01:00"
From the
java.sqlpackage:java.sql.Datesuch as"2007-12-03"java.sql.Timesuch as"23:13:33"java.sql.Timestampsuch as"2007-12-03 10:15:30.998"
From the
java.utilpackage:java.util.Currencyfrom ISO 4217 codes, such as:"BRL"(Brazilian Real)java.util.Datesuch as"2007-12-03T10:15:30+01:00"(accepting valid date-time representations in RFC 3339 formats)java.util.TimeZonesuch as:"America/Sao_Paulo"or"GMT-03:00"java.util.UUIDfrom universally-unique identifier strings in RFC 4122 format
From the
java.iopackage:java.io.File
From the
java.niopackage:java.nio.charset.Charsetjava.nio.file.Path
From the
java.langpackage:java.lang.Class
From the
java.mathpackage:java.math.BigDecimaljava.math.BigInteger
From the
java.netpackage:java.net.InetAddressfrom strings representing an IP addressjava.net.URIsuch as:"example.com/docs"java.net.URLsuch as:"http://www.example.com/resource1.html"
Enum elements can also be retrieved based on their constant names (and performs case-insensitive matching). For example:
ParseFactory.parse(Month.class, "january"); // returns Month.JANUARYParseFactory.parse(DayOfWeek.class, "friday"); // returns DayOfWeek.FRIDAY- Since:
- 2.5.0
- Author:
- oswaldo.bapvic.jr (Oswaldo Junior)
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tparse(Class<T> type, String string)Parses the contents of a string into the specified type.
-
-
-
Method Detail
-
parse
public static <T> T parse(Class<T> type, String string) throws ParseException
Parses the contents of a string into the specified type.- Type Parameters:
T- the target type- Parameters:
type- the target typestring- the string to be parsed- Returns:
- an object containing the result of the parsing of the specified string into the specified type
- Throws:
UnsupportedOperationException- if the specified type is not supportedParseException- if an error is encountered while parsing
-
-