Class FastLongFormatter

java.lang.Object
org.orekit.utils.formatting.FastLongFormatter

public class FastLongFormatter extends Object
Formatter for long integers with low overhead.

This class is intended to be used when formatting large amounts of data with fixed formats like, for example, large ephemeris or measurement files.

Building the formatter is done once, and the formatter appendTo(Appendable, long) or toString(long) methods can be called hundreds of thousands of times, without incurring the overhead that would occur with String.format(). Some tests showed this formatter is about 10 times faster than String.format() with %{width}d format.

Instances of this class are immutable

Since:
13.0.3
Author:
Luc Maisonobe
  • Constructor Details

    • FastLongFormatter

      public FastLongFormatter(int width, boolean zeroPadding)
      Simple constructor.

      This constructor is equivalent to either Formatter integer format %{width}d or %0{width}d

      Parameters:
      width - number of characters to output
      zeroPadding - if true, the result is left padded with '0' until it matches width
  • Method Details

    • getWidth

      public int getWidth()
      Get the width.
      Returns:
      width
    • hasZeroPadding

      public boolean hasZeroPadding()
      Check if left padding uses '0' characters.
      Returns:
      true if left padding uses '0' characters
    • appendTo

      public void appendTo(Appendable appendable, long value) throws IOException
      Append one formatted value to an Appendable.
      Parameters:
      appendable - to append value to
      value - value to format
      Throws:
      IOException - if an I/O error occurs
    • toString

      public String toString(long value)
      Format one value.
      Parameters:
      value - value to format
      Returns:
      formatted string