public abstract class AbstractFormatter extends java.lang.Object implements JdtFormatter
JdtFormatter
implementations.
For setting date and time, default formatter parses input String against
specified format. It extracts parts of input string upon patterns
and then each part is converted to a number for a date/time information.
It doesn't ignore any non-number character. If conversion fails,
null
is returned.
Getting date time is also user friendly. Specified format may not only contains patterns but also any text. To remove errors in decoding when text may be recognize as one of patterns, format text may be quoted with the special escape sign. Double quote in the text will be decoded as a single quote, of course.
It is not necessary to have parsers for all patterns.
Modifier and Type | Field and Description |
---|---|
protected char |
escapeChar
Escape character.
|
protected char[][] |
patterns
Available patterns list.
|
Constructor and Description |
---|
AbstractFormatter() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
convert(JDateTime jdt,
java.lang.String format)
Converts date time to a string using specified format.
|
protected abstract java.lang.String |
convertPattern(int patternIndex,
JDateTime jdt)
Creates a date-time string for founded pattern.
|
protected char |
detectSeparatorInPattern(char c)
Checks if given char is a starting char of a pattern.
|
protected int |
findPattern(char[] input,
int i)
Finds the longest pattern in provided format starting from specified position.
|
DateTimeStamp |
parse(java.lang.String value,
java.lang.String format)
Parses string given in specified format and extracts time information.
|
protected abstract void |
parseValue(int patternIndex,
java.lang.String value,
DateTimeStamp destination)
Parses value for matched pattern.
|
protected void |
preparePatterns(java.lang.String[] spat)
Converts String array of patterns to char arrays.
|
protected java.lang.String |
print2(int value)
Prints values 00 - 99.
|
protected java.lang.String |
print3(int value)
Prints values 00 - 999.
|
protected java.lang.String |
printPad4(int value)
Prints 4 digits and optional minus sign.
|
protected char[][] patterns
findPattern(char[], int)
when parsing date time format. Each formatter will have its own set of
patterns, in strictly defined order.protected char escapeChar
protected void preparePatterns(java.lang.String[] spat)
protected int findPattern(char[] input, int i)
patterns
.input
- date time format to examinei
- starting index-1
if pattern not foundprotected char detectSeparatorInPattern(char c)
protected abstract java.lang.String convertPattern(int patternIndex, JDateTime jdt)
patterns
index.patternIndex
- index of founded patternjdt
- date time informationpublic java.lang.String convert(JDateTime jdt, java.lang.String format)
convert
in interface JdtFormatter
jdt
- JDateTime to read fromformat
- formatJdtFormatter.convert(JDateTime, String)
protected abstract void parseValue(int patternIndex, java.lang.String value, DateTimeStamp destination)
patterns
index.
Note that value may represent both integer and decimals.
May throw NumberFormatException
.patternIndex
- index of founded patternvalue
- value to parse, no spaces or tabsdestination
- destination to modifypublic DateTimeStamp parse(java.lang.String value, java.lang.String format)
DateTimeStamp
or null
if error occurs.parse
in interface JdtFormatter
value
- string containing date time valuesformat
- formatJdtFormatter.parse(String, String)
protected java.lang.String print2(int value)
protected java.lang.String print3(int value)
protected java.lang.String printPad4(int value)
Copyright © 2003-2013 Jodd Team