public class LoggedFormat<T> extends Format
Format
object in order to either parse fully a string, or log a warning. This
class provides a parse(java.lang.String)
method which performs the following tasks:
parseObject(String)
behavior which check only if the
begining of the string was parsed and ignore any remaining characters.
Format.Field
Modifier | Constructor and Description |
---|---|
protected |
LoggedFormat(Format format,
Class<T> type)
Creates a new format wrapping the specified one.
|
Modifier and Type | Method and Description |
---|---|
StringBuffer |
format(Object value,
StringBuffer toAppendTo,
FieldPosition position)
Formats the specified object.
|
AttributedCharacterIterator |
formatToCharacterIterator(Object value)
Formats the specified object.
|
static String |
formatUnparsable(String text,
int index,
int errorIndex,
Locale locale)
Formats an error message for an unparsable string.
|
static LogRecord |
formatUnparsable(String text,
int index,
int errorIndex,
Locale locale,
Level level)
Formats a log record for an unparsable string.
|
static <T> LoggedFormat<T> |
getInstance(Format format,
Class<T> type)
Creates a new format wrapping the specified one.
|
protected Locale |
getWarningLocale()
Returns the locale to use for formatting warnings.
|
protected void |
logWarning(LogRecord warning)
Logs a warning.
|
T |
parse(String text)
Parses the specified string.
|
Object |
parseObject(String text)
Parses text from a string to produce an object.
|
Object |
parseObject(String text,
ParsePosition position)
Parses text from a string to produce an object.
|
void |
setCaller(Class<?> caller,
String method)
Sets the source class name and source method name for the warnings eventually emitted by the
parse(java.lang.String) method. |
void |
setLevel(Level level)
Sets the logger level for the warnings eventually emitted by the
parse(java.lang.String) method. |
void |
setLogger(String logger)
Sets the logger where to send the warnings eventually emitted by the
parse(java.lang.String) method. |
String |
toString()
Returns a string representation for debugging purpose.
|
public static <T> LoggedFormat<T> getInstance(Format format, Class<T> type)
format
- The format to use for parsing and formatting.type
- The expected type of parsed values.public void setLogger(String logger)
parse(java.lang.String)
method.logger
- The logger where to log warnings, or null
if none.public void setLevel(Level level)
parse(java.lang.String)
method. The
default value is Level.WARNING
.level
- The new logging level.public void setCaller(Class<?> caller, String method)
parse(java.lang.String)
method.caller
- The class to declare as the warning emitter, or null
if none.method
- The method to declare as the warning emitter, or null
if none.public T parse(String text)
null
. If it can be parsed at least partially and is of the kind specified at construction
time, then it is returned. If the string has not been fully parsed, then a log record is prepared and logged.text
- The text to parse, or null
.null
if text
was null or can't be parsed.public Object parseObject(String text) throws ParseException
parseObject
in class Format
text
- The text to parse.ParseException
- if parsing failed.public Object parseObject(String text, ParsePosition position)
parseObject
in class Format
text
- The text to parse.position
- Index and error index information.null
in case of error.public StringBuffer format(Object value, StringBuffer toAppendTo, FieldPosition position)
public AttributedCharacterIterator formatToCharacterIterator(Object value)
formatToCharacterIterator
in class Format
value
- The object to format.protected void logWarning(LogRecord warning)
parse
method when
a text can't be fully parsed. The default implementation logs the warning to the logger
specified by the last call to the setLogger
method. Subclasses may
override this method if they want to change the log record before the logging.warning
- The warning to log.protected Locale getWarningLocale()
public static String formatUnparsable(String text, int index, int errorIndex, Locale locale)
formatUnparsable(..., Level)
,
except that the result is returned as a String
rather than a LogRecord
. This
is provided as a convenience method for creating the message to give to an exception constructor.text
- The unparsable string.index
- The parse position. This is usually ParsePosition.getIndex()
.errorIndex
- The index where the error occured. This is usually ParsePosition.getErrorIndex()
.locale
- The locale for the message, or null
for the default one.public static LogRecord formatUnparsable(String text, int index, int errorIndex, Locale locale, Level level)
parse
method for formatting the log record to be given to the logWarning(java.util.logging.LogRecord)
method. It
is made public as a convenience for implementors who wish to manage loggings outside this
LoggedFormat
class.text
- The unparsable string.index
- The parse position. This is usually ParsePosition.getIndex()
.errorIndex
- The index where the error occured. This is usually ParsePosition.getErrorIndex()
.locale
- The locale for the log message, or null
for the default one.level
- The log record level.Copyright © 1996–2019 Geotools. All rights reserved.