Package org.djunits.formatter
Class Formatter<C extends FormatContext>
java.lang.Object
org.djunits.formatter.Formatter<C>
- Type Parameters:
C- the specificFormatContextthat is used
- Direct Known Subclasses:
MatrixFormatter,QuantityFormatter,TableFormatter,VectorFormatter
Formatter of quantities, vectors, matrices and tables according to the format options that are stored in the
FormatContext or one of its extensions.
Copyright (c) 2025-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, Peter Knoppers
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final Cthe format context.(package private) Unit<?,?> the unit to express the value in.(package private) Stringthe formatted unit.(package private) booleanusing SI value or valueInUnit for the calculated unit.(package private) final Value<?,?> the value (quantity, vector, matrix) with a display unit. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) booleanApply the display unit if present.(package private) booleanCheck if SI formatting needs to be applied.(package private) booleanApply the unit string if present.(package private) abstract Stringformat()Format the value(s) and unit and return the String representation.(package private) StringformatEngineering(double val) Format a value using engineering notation with a fixed length and a given number of decimals.(package private) StringformatFixedEngFallback(double val) Format a value using fixed length, but when it does not fit, fall back to engineering notation.(package private) StringformatFixedFloat(double val) Format a value with a fixed floating point length and a given number of decimals.(package private) StringformatFixedSciFallback(double val) Format a value using fixed length, but when it does not fit, fall back to scientific notation.(package private) static StringformatReference(FormatContext ctx, Reference<?, ?, ?> reference) Format the reference of an absolute value according to the context settings.(package private) StringformatScientific(double val) Format a value using scientific notation with a fixed length and a given number of decimals.(package private) voidFormat the unit according to the context settings.(package private) StringformatValue(double val) Format a value according to the context settings.(package private) StringformatVariableLength(double val) Format a value with variable length.(package private) static StringPad a string with spaces.(package private) static voidrestoreLocale(Locale oldLocale) Restore the locale to the old locale.(package private) static LocalesaveLocale(Locale newLocale) Save the current locale, and change the locale.
-
Field Details
-
Constructor Details
-
Formatter
- Parameters:
value- the value to formatctx- the format context
-
-
Method Details
-
format
Format the value(s) and unit and return the String representation.- Returns:
- the formatted value and unit
-
checkSiUnits
boolean checkSiUnits()Check if SI formatting needs to be applied.- Returns:
- whether SI formatting was applied
-
checkUnitString
boolean checkUnitString()Apply the unit string if present.- Returns:
- whether unit string formatting was applied
-
checkDisplayUnit
boolean checkDisplayUnit()Apply the display unit if present.- Returns:
- whether display unit formatting was applied
-
formatUnit
void formatUnit()Format the unit according to the context settings. -
formatReference
Format the reference of an absolute value according to the context settings.- Parameters:
ctx- the format context with the settings for formatting a referencereference- the reference to format- Returns:
- the formatted reference, or an empty string when it is not displayed
-
formatValue
Format a value according to the context settings.- Parameters:
val- the value to format- Returns:
- the formatted value according to the context settings
-
formatVariableLength
Format a value with variable length.- Parameters:
val- the value to format- Returns:
- a formatted value with variable length
-
formatFixedFloat
Format a value with a fixed floating point length and a given number of decimals.- Parameters:
val- the value to format- Returns:
- a formatted value with a fixed floating point length and a given number of decimals
-
formatScientific
Format a value using scientific notation with a fixed length and a given number of decimals.- Parameters:
val- the value to format- Returns:
- a formatted value using scientific notation with a fixed length and a given number of decimals
-
formatEngineering
Format a value using engineering notation with a fixed length and a given number of decimals.- Parameters:
val- the value to format- Returns:
- a formatted value using engineering notation with a fixed length and a given number of decimals
-
formatFixedSciFallback
Format a value using fixed length, but when it does not fit, fall back to scientific notation.- Parameters:
val- the value to format- Returns:
- a formatted value using fixed length, but when it does not fit, fall back to scientific notation.
-
formatFixedEngFallback
Format a value using fixed length, but when it does not fit, fall back to engineering notation.- Parameters:
val- the value to format- Returns:
- a formatted value using fixed length, but when it does not fit, fall back to engineering notation.
-
pad
Pad a string with spaces.- Parameters:
s- the string to padwidth- the width- Returns:
- a padded string
-
saveLocale
Save the current locale, and change the locale.- Parameters:
newLocale- the new locale (can be null if the locale does not change)- Returns:
- the old locale, or null when the locale was not changed
-
restoreLocale
Restore the locale to the old locale.- Parameters:
oldLocale- the old locale (can be null if the locale was not changed earlier)
-