Package org.apache.sis.io
Class DefaultFormat
java.lang.Object
java.text.Format
org.apache.sis.io.DefaultFormat
- All Implemented Interfaces:
Serializable
,Cloneable
Created by
CompoundFormat
for parsing and formatting unlocalized numbers.
This implementation use toString()
and valueOf(…)
methods instead
than the java.text
package because the former provide the best guarantees
to format all significant digits.
Thread safety
The same instance can be safely used by many threads without synchronization on the part of the caller. Note that this is specific toDefaultFormat
and generally not true
for arbitrary Format
classes.- Since:
- 0.3
- Version:
- 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from class java.text.Format
Format.Field
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
DefaultFormat
(Class<?> type) Creates a new instance for parsing and formatting objects of the given type. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Unconditionally returnsthis
since this format does not contain any modifiable field.format
(Object obj, StringBuffer toAppendTo, FieldPosition pos) Formats the given number using itsObject.toString()
method.(package private) static Format
getInstance
(Class<?> type) Gets an instance of the given type, ornull
if the given type is not supported.parseObject
(String source) Parses the given string as a number of the type given at construction time.parseObject
(String source, ParsePosition pos) Parses the given string as a number of the type given at construction time.private Object
Resolves to the singleton instance on deserialization.private Object
Parses the given string.Methods inherited from class java.text.Format
format, formatToCharacterIterator
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
INSTANCES
The array for storing singleton instances for typesbyte
todouble
. The value at index 0 is reserved for the genericNumber
type. -
type
The type of the objects to parse.
-
-
Constructor Details
-
DefaultFormat
Creates a new instance for parsing and formatting objects of the given type.
-
-
Method Details
-
getInstance
Gets an instance of the given type, ornull
if the given type is not supported. -
format
Formats the given number using itsObject.toString()
method. -
valueOf
Parses the given string. Callers shall catch theNumberFormatException
and handle the error according the caller's method contract.- Throws:
NumberFormatException
- if the parsing failed.
-
parseObject
Parses the given string as a number of the type given at construction time.- Overrides:
parseObject
in classFormat
- Throws:
ParseException
-
parseObject
Parses the given string as a number of the type given at construction time.- Specified by:
parseObject
in classFormat
-
clone
Unconditionally returnsthis
since this format does not contain any modifiable field. The sameDefaultFormat
instances can be shared. -
readResolve
Resolves to the singleton instance on deserialization.- Throws:
ObjectStreamException
-