Class MatrixFormatter


public class MatrixFormatter extends Formatter<MatrixFormatContext>
MatrixFormatter formats a matrix as a String, using the settings of the MatrixFormatContext. The MatrixFormatContext is filled by setting properties of the MatrixFormatContext. Note that there is no guarantee that the format can always be honored. As an example, when the required width is too small to fit the answer, the output will show the correct result, but violate the width setting.

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
  • Constructor Details

    • MatrixFormatter

      MatrixFormatter(Matrix<?,?,?,?,?> matrix, MatrixFormatContext ctx)
      Parameters:
      matrix - the matrix to format
      ctx - the format context
  • Method Details

    • matrix

      Matrix<?,?,?,?,?> matrix()
      Return the value as a matrix (or matrix).
      Returns:
      the value as a matrix (or matrix)
    • format

      public static String format(Matrix<?,?,?,?,?> matrix, MatrixFormat matrixFormat)
      Format a matrix according to a number of MatrixFormat settings. Note that this method might not be thread-safe for setting the default Locale. If another thread changes the Locale while formatting, outcomes could vary.
      Parameters:
      matrix - the matrix to format
      matrixFormat - the format to apply to the matrix
      Returns:
      a String with a formatted matrix, matching the MatrixFormat settings as closely as possible
    • format

      public static String format(AbsMatrix<?,?,?,?,?> absMatrix, MatrixFormat matrixFormat)
      Format an absolute matrix according to a number of MatrixFormat settings. Note that this method might not be thread-safe for setting the default Locale. If another thread changes the Locale while formatting, outcomes could vary.
      Parameters:
      absMatrix - the absolute matrix to format
      matrixFormat - the format to apply to the matrix
      Returns:
      a String with a formatted matrix, matching the MatrixFormat settings as closely as possible
    • format

      String format()
      Return the matrix, formatted according to the context settings.
      Specified by:
      format in class Formatter<MatrixFormatContext>
      Returns:
      the formatted matrix