Class Format<F extends Format<F,C>,C extends FormatContext>

java.lang.Object
org.djunits.formatter.Format<F,C>
Type Parameters:
F - the Format type
C - the FormatContext type
Direct Known Subclasses:
MatrixFormat, QuantityFormat, TableFormat, VectorFormat

abstract class Format<F extends Format<F,C>,C extends FormatContext> extends Object
Format is the abstract base class for the settings the format. It contains generic methods to influence the format of Quantity, AbsQuantity, Vector, AbsVector, Matrix, AbsMatrix, QuantityTable and AbsQuantityTable. The main methods to set the format in this class are about the way to format the number, the unit, and the locale. Specific setter methods for quantities, vectors, matrices and tables can be found in the extensions of this class, such as QuantityFormat.

Copyright (c) 2026-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djunits.org. The DJUNITS project is distributed under a three-clause BSD-style license.

Author:
Alexander Verbraeck
  • Field Details

    • ctx

      protected final C extends FormatContext ctx
      The format context.
  • Constructor Details

    • Format

      Format(C ctx)
      Construct a Format object with a given context. Note that the context can be an existing context that is being modified or a default context.
      Parameters:
      ctx - the format context to use
  • Method Details

    • self

      public F self()
      Return the object for fluent design.
      Returns:
      the object for fluent design
    • setVariableLength

      public F setVariableLength()
      Apply variable length notation. Ignore width and decimals restrictions.
      Returns:
      the the object instance for fluent design
    • setFixedFloat

      public F setFixedFloat()
      Apply fixed length float-only notation.
      Returns:
      the the object instance for fluent design
    • setScientific

      public F setScientific()
      Apply scientific notation.
      Returns:
      the the object instance for fluent design
    • setFixedWithSciFallback

      public F setFixedWithSciFallback()
      Apply fixed length float-only notation with scientific notation as a fallback.
      Returns:
      the the object instance for fluent design
    • setFixedWithEngFallback

      public F setFixedWithEngFallback()
      Apply fixed length float-only notation with engineering notation as a fallback. Engineering notation uses an e formatter with exponents that are multiples of 3.
      Returns:
      the the object instance for fluent design
    • setEngineering

      public F setEngineering()
      Apply engineering notation. Engineering notation uses an e formatter with exponents that are multiples of 3.
      Returns:
      the the object instance for fluent design
    • setWidth

      public F setWidth(int width)
      Set the width of the numerical output.
      Parameters:
      width - the width of the numerical output
      Returns:
      the the object instance for fluent design
    • setDecimals

      public F setDecimals(int decimals)
      Set the number of decimal digits of the numerical output.
      Parameters:
      decimals - the number of decimal digits of the numerical output
      Returns:
      the the object instance for fluent design
    • setUpperE

      public F setUpperE(boolean upper)
      Set the scientific exponential character to E or e.
      Parameters:
      upper - results in E when true, and in e when false
      Returns:
      the the object instance for fluent design
    • setGroupingSeparator

      public F setGroupingSeparator(boolean on)
      Set the grouping separator (e.g., 1000s separator) or or off.
      Parameters:
      on - indicates whether the grouping separator is on or not
      Returns:
      the the object instance for fluent design
    • setFormatString

      public F setFormatString(String formatString)
      Set the format string to use.
      Parameters:
      formatString - the format string to use
      Returns:
      the the object instance for fluent design
    • setUnitPrefix

      public F setUnitPrefix(String prefix)
      Set the prefix separator between value and unit.
      Parameters:
      prefix - separator string between the value and the unit
      Returns:
      the object instance for fluent design
    • setUnitPostfix

      public F setUnitPostfix(String postfix)
      Set the postfix separator after the unit.
      Parameters:
      postfix - string after the unit
      Returns:
      the object instance for fluent design
    • setDisplayUnit

      public F setDisplayUnit(Unit<?,?> unit)
      Set the display unit to use.
      Parameters:
      unit - the display unit to use
      Returns:
      the object instance for fluent design
    • setDisplayUnit

      public F setDisplayUnit(String unit)
      Set the display unit to use, based on a String representation.
      Parameters:
      unit - the String representation of the display unit to use
      Returns:
      the object instance for fluent design
    • setTextual

      public F setTextual()
      Set textual mode.
      Returns:
      the object instance for fluent design
    • setDisplay

      public F setDisplay()
      Set display mode.
      Returns:
      the object instance for fluent design
    • setTextual

      public F setTextual(boolean on)
      Set textual mode on or off.
      Parameters:
      on - whether to turn textual mode on or off
      Returns:
      the object instance for fluent design
    • setSiUnits

      public F setSiUnits()
      Set SI unit mode.
      Returns:
      the object instance for fluent design
    • setDivider

      public F setDivider(boolean on)
      Set whether the divider symbol is used. This setting only works when siUnits has been switched on.
      Parameters:
      on - true when the divider symbol is used, false when not
      Returns:
      the object instance for fluent design
    • setPowerPrefix

      public F setPowerPrefix(String symbol)
      Set the symbol to use as the prefix for a power to the given String. This setting only works when siUnits has been switched on.
      Parameters:
      symbol - the string to use for the power prefix
      Returns:
      the object instance for fluent design
    • setPowerPostfix

      public F setPowerPostfix(String symbol)
      Set the symbol to use as the postfix for a power to the given String. This setting only works when siUnits has been switched on.
      Parameters:
      symbol - the string to use for the power postfix
      Returns:
      the object instance for fluent design
    • setDotSeparator

      public F setDotSeparator(String symbol)
      Set the dot separator symbol to the given String. This setting only works when siUnits has been switched on.
      Parameters:
      symbol - the string to use for the dot separator symbol
      Returns:
      the object instance for fluent design
    • setLocale

      public F setLocale(Locale locale)
      Apply locale to formatting.
      Parameters:
      locale - the locale to use
      Returns:
      the object instance for fluent design
    • setPrintReference

      public F setPrintReference()
      Print the reference.
      Returns:
      the object instance for fluent design
    • setNoReference

      public F setNoReference()
      Do not print the reference.
      Returns:
      the object instance for fluent design
    • setPrintReference

      public F setPrintReference(boolean on)
      Indicate whether to print the reference or not.
      Parameters:
      on - boolean that indicates whether to print the reference or not
      Returns:
      the object instance for fluent design
    • setReferencePrefix

      public F setReferencePrefix(String prefix)
      Set the prefix for the reference, e.g., "(relative to ".
      Parameters:
      prefix - the prefix for the reference
      Returns:
      the object instance for fluent design
    • setReferencePostfix

      public F setReferencePostfix(String postfix)
      Set the postfix for the reference, e.g., ")".
      Parameters:
      postfix - the postfix for the reference
      Returns:
      the object instance for fluent design