Package org.apache.sis.feature
Class FeatureFormat
- All Implemented Interfaces:
Serializable
,Cloneable
,Localized
Formats features or feature types in a tabular format.
This format assumes a monospaced font and an encoding supporting drawing box characters (e.g. UTF-8).
Example: a feature named “City” and containing 3 properties (“name”, “population” and
“twin town”) may be formatted like below. The two first properties are attributes
while the last property is an association to another feature.
Limitations
- The current implementation can only format features — parsing is not yet implemented.
FeatureFormat
, like mostjava.text.Format
subclasses, is not thread-safe.
- Since:
- 0.5
- Version:
- 1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Identifies the columns to include in the table formatted byFeatureFormat
.Nested classes/interfaces inherited from class java.text.Format
Format.Field
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final EnumSet<FeatureFormat.Column>
The columns to include in the table formatted by thisFeatureFormat
.private final Locale
The locale for international strings.private int
The bit patterns of the lastFloat.NaN
value for whichMathFunctions.toNanOrdinal(float)
could not get the ordinal value.private static final AtomicReference<FeatureFormat>
An instance created when first needed and potentially shared.private static final int
Maximal length of attribute values, in number of characters.private static final String
The separator to use in comma-separated lists.private static final long
For cross-version compatibility.Fields inherited from class org.apache.sis.io.TabularFormat
beforeFill, columnSeparator, fillCharacter, lineSeparator, omitTrailingNulls
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new formatter for the default locale and timezone.FeatureFormat
(Locale locale, TimeZone timezone) Creates a new formatter for the given locale and timezone. -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
appendSuperscript
(int n, Appendable toAppendTo) Appends the given number as an superscript if possible, or as an ordinary number otherwise.clone()
Returns a clone of this format.void
format
(Object object, Appendable toAppendTo) Formats the given object to the given stream of buffer.private int
formatValue
(Object value, TableAppender table, int length) Appends the given attribute value, in a truncated form if it exceed the maximal value length.Returns all columns that may be shown in the tables to format.getLocale
(Locale.Category category) Returns the locale for the given category.Returns the type of objects formatted by this class.private void
nextColumn
(TableAppender table) Invoked when the formatter needs to move to the next column.parse
(CharSequence text, ParsePosition pos) Not yet supported.void
setAllowedColumns
(Set<FeatureFormat.Column> inclusion) Sets all columns that may be shown in the tables to format.(package private) static String
sharedFormat
(Object object) Formats the given object using a shared instance ofParameterFormat
.private String
toString
(org.opengis.util.GenericName name) Returns the display name for the givenGenericName
.Methods inherited from class org.apache.sis.io.TabularFormat
getColumnSeparatorMatcher, getColumnSeparatorPattern, getLineSeparator, setColumnSeparatorPattern, setLineSeparator
Methods inherited from class org.apache.sis.io.CompoundFormat
createFormat, format, getFormat, getLocale, getTimeZone, parseObject, parseObject
Methods inherited from class java.text.Format
format, formatToCharacterIterator
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
SEPARATOR
The separator to use in comma-separated lists.- See Also:
-
INSTANCE
An instance created when first needed and potentially shared. -
displayLocale
The locale for international strings. -
columns
The columns to include in the table formatted by thisFeatureFormat
. By default, all columns having at least one value are included. -
MAXIMAL_VALUE_LENGTH
private static final int MAXIMAL_VALUE_LENGTHMaximal length of attribute values, in number of characters. If a value is longer than this length, it will be truncated.This is defined as a static final variable for now because its value is approximate: it is a number of characters instead of a number of code points, and that length may be exceeded by a few characters if the overflow happen while appending the list separator.
- See Also:
-
illegalNaN
private transient int illegalNaNThe bit patterns of the lastFloat.NaN
value for whichMathFunctions.toNanOrdinal(float)
could not get the ordinal value. We use this information for avoiding flooding the logger with the same message.
-
-
Constructor Details
-
FeatureFormat
public FeatureFormat()Creates a new formatter for the default locale and timezone. -
FeatureFormat
Creates a new formatter for the given locale and timezone.- Parameters:
locale
- the locale, ornull
forLocale.ROOT
.timezone
- the timezone, ornull
for UTC.
-
-
Method Details
-
getValueType
Returns the type of objects formatted by this class. This method has to returnObject.class
since it is the only common parent toFeature
andFeatureType
.- Specified by:
getValueType
in classCompoundFormat<Object>
- Returns:
Object.class
-
getLocale
Returns the locale for the given category.Locale.Category.FORMAT
specifies the locale to use for values.Locale.Category.DISPLAY
specifies the locale to use for labels.
- Overrides:
getLocale
in classCompoundFormat<Object>
- Parameters:
category
- the category for which a locale is desired.- Returns:
- the locale for the given category (never
null
).
-
getAllowedColumns
Returns all columns that may be shown in the tables to format. The columns included in the set may be shown, but not necessarily; some columns will still be omitted if they are completely empty. However, columns not included in the set are guaranteed to be omitted.- Returns:
- all columns that may be shown in the tables to format.
- Since:
- 0.8
-
setAllowedColumns
Sets all columns that may be shown in the tables to format. Note that the columns specified to this method are not guaranteed to be shown; some columns will still be omitted if they are completely empty.- Parameters:
inclusion
- all columns that may be shown in the tables to format.- Since:
- 0.8
-
nextColumn
Invoked when the formatter needs to move to the next column. -
format
Formats the given object to the given stream of buffer. The object may be an instance of any of the following types:Feature
FeatureType
- Specified by:
format
in classCompoundFormat<Object>
- Parameters:
object
- the object to format.toAppendTo
- where to format the object.- Throws:
IOException
- if an error occurred while writing to the given appendable.
-
toString
Returns the display name for the givenGenericName
. -
formatValue
Appends the given attribute value, in a truncated form if it exceed the maximal value length.- Parameters:
value
- the value to append.table
- where to append the value.length
- number of characters appended before this method call in the current table cell.- Returns:
- number of characters appended after this method call in the current table cell, or -1 if the length exceed the maximal length (in which case the caller should break iteration).
-
appendSuperscript
Appends the given number as an superscript if possible, or as an ordinary number otherwise.- Throws:
IOException
-
parse
Not yet supported.- Specified by:
parse
in classCompoundFormat<Object>
- Parameters:
text
- the character sequence for the object to parse.pos
- the position where to start the parsing. On return, the position where the parsing stopped or where an error occurred.- Returns:
- currently never return.
- Throws:
ParseException
- currently always thrown.
-
clone
Returns a clone of this format.- Overrides:
clone
in classTabularFormat<Object>
- Returns:
- a clone of this format.
-