Class SampleRangeFormat

java.lang.Object
java.text.Format
org.apache.sis.measure.RangeFormat
org.apache.sis.coverage.SampleRangeFormat
All Implemented Interfaces:
Serializable, Cloneable, Localized

final class SampleRangeFormat extends RangeFormat
Formats the range of a category. This is used for SampleDimension.toString() implementation.
Since:
1.0
Version:
1.1
  • Field Details

    • MAX_DIGITS

      private static final int MAX_DIGITS
      Maximum value for numFractionDigits. This is the number of significant digits to allow when formatting real values.
      See Also:
    • numFractionDigits

      private int[] numFractionDigits
      Number of significant digits used for formatting real values.
    • hasPackedValues

      private boolean hasPackedValues
      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. If false, then we can omit the "Samples" column.
    • hasQuantitative

      private boolean hasQuantitative
      Whether prepare(SampleDimension[]) found at least one quantitative category. If false, then we can omit the "Measures" column.
    • hasCategory

      private boolean hasCategory
      Whether at least one category of any type has been found in at least one sample dimension.
    • words

      private final Vocabulary words
      The localize resources for table header. Words will be "Values", "Measures" and "Name".
    • currentIndex

      private int currentIndex
      Index 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

      private void prepare(SampleDimension[] dimensions)
      Computes the smallest number of fraction digits necessary to resolve all quantitative values. This method assumes that real values in the range Category.converse.range are stored as integer sample values in the range Category.range.
    • formatSample

      private String formatSample(Object value)
      Formats a sample value or a range of sample value. The value should have been fetched by Category.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

      private String formatMeasure(Range<?> range)
      Formats a range of measurements. There is usually only zero or one range of measurement per SampleDimension, but SampleRangeFormat is not restricted to that limit. The number of fraction digits to use should have been computed by prepare(SampleDimension[]) before to call this method.
      Returns:
      the range to write, or null if the given range argument was null.
    • write

      String write(SampleDimension[] dimensions)
      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

      private String getName(SampleDimension dim)
      Returns the localized name for the given dimension, or "unnamed" if none.
    • replace

      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.
      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.