Package org.apache.sis.coverage
Class SampleRangeFormat
java.lang.Object
java.text.Format
org.apache.sis.measure.RangeFormat
org.apache.sis.coverage.SampleRangeFormat
- All Implemented Interfaces:
Serializable
,Cloneable
,Localized
Formats the range of a category. This is used for
SampleDimension.toString()
implementation.- Since:
- 1.0
- Version:
- 1.1
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sis.measure.RangeFormat
RangeFormat.Field
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
Index of the current sample dimension being formatted.private boolean
Whether at least one category of any type has been found in at least one sample dimension.private boolean
true
if the range of sample values is different than the range of real values, or if there is qualitative categories with non NaN values.private boolean
Whetherprepare(SampleDimension[])
found at least one quantitative category.private static final int
Maximum value fornumFractionDigits
.private int[]
Number of significant digits used for formatting real values.private final Vocabulary
The localize resources for table header.Fields inherited from class org.apache.sis.measure.RangeFormat
elementFormat, elementType, unitFormat
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate String
formatMeasure
(Range<?> range) Formats a range of measurements.private String
formatSample
(Object value) Formats a sample value or a range of sample value.private String
getName
(SampleDimension dim) Returns the localized name for the given dimension, or "unnamed" if none.private void
prepare
(SampleDimension[] dimensions) Computes the smallest number of fraction digits necessary to resolve all quantitative values.private static int
replace
(StringBuilder buffer, int i, char search, char replace, char stop) Replaces characters in the given buffer until a sentinel value, which must exist.(package private) String
write
(SampleDimension[] dimensions) Formats a string representation of the given list of categories.Methods inherited from class org.apache.sis.measure.RangeFormat
clone, format, formatToCharacterIterator, getElementPattern, getLocale, isAlternateForm, parse, parse, parseObject, parseObject, setAlternateForm, setElementPattern
-
Field Details
-
MAX_DIGITS
private static final int MAX_DIGITSMaximum value fornumFractionDigits
. This is the number of significant digits to allow when formatting real values.- See Also:
-
numFractionDigits
private int[] numFractionDigitsNumber of significant digits used for formatting real values. -
hasPackedValues
private boolean hasPackedValuestrue
if the range of sample values is different than the range of real values, or if there is qualitative categories with non NaN values. Iffalse
, then we can omit the "Samples" column. -
hasQuantitative
private boolean hasQuantitativeWhetherprepare(SampleDimension[])
found at least one quantitative category. Iffalse
, then we can omit the "Measures" column. -
hasCategory
private boolean hasCategoryWhether at least one category of any type has been found in at least one sample dimension. -
words
The localize resources for table header. Words will be "Values", "Measures" and "Name". -
currentIndex
private int currentIndexIndex of the current sample dimension being formatted.
-
-
Constructor Details
-
SampleRangeFormat
SampleRangeFormat(Locale locale) Creates a new format for the given locale.- Parameters:
locale
- the locale for table header, category names and number format.
-
-
Method Details
-
prepare
Computes the smallest number of fraction digits necessary to resolve all quantitative values. This method assumes that real values in the rangeCategory.converse.range
are stored as integer sample values in the rangeCategory.range
. -
formatSample
Formats a sample value or a range of sample value. The value should have been fetched byCategory.getRangeLabel()
. This method applies the following rules:- If the value is a number, check if we should use scientific notation.
- If the value is a range, discard the unit of measurement if any. We do that because the range may be repeated in the "Measure" column with units.
-
formatMeasure
Formats a range of measurements. There is usually only zero or one range of measurement perSampleDimension
, butSampleRangeFormat
is not restricted to that limit. The number of fraction digits to use should have been computed byprepare(SampleDimension[])
before to call this method.- Returns:
- the range to write, or
null
if the givenrange
argument was null.
-
write
Formats a string representation of the given list of categories. This method formats a table like below:- Parameters:
dimensions
- the list of sample dimensions to format.
-
getName
Returns the localized name for the given dimension, or "unnamed" if none. -
replace
Replaces characters in the given buffer until a sentinel value, which must exist.- Parameters:
buffer
- the buffer where to perform the replacements.i
- index of the first character to check.search
- character to search for replacement.replace
- character to use as a replacement.stop
- sentinel value for stopping the search.- Returns:
- index after the sentinel value.
-