Package org.orekit.utils.formatting
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)
ortoString(long)
methods can be called hundreds of thousands of times, without incurring the overhead that would occur withString.format()
. Some tests showed this formatter is about 10 times faster thanString.format()
with%{width}d
format.Instances of this class are immutable
- Since:
- 13.0.3
- Author:
- Luc Maisonobe
-
-
Constructor Summary
Constructors Constructor Description FastLongFormatter(int width, boolean zeroPadding)
Simple constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendTo(Appendable appendable, long value)
Append one formatted value to anAppendable
.int
getWidth()
Get the width.boolean
hasZeroPadding()
Check if left padding uses '0' characters.String
toString(long value)
Format one value.
-
-
-
Constructor Detail
-
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 outputzeroPadding
- if true, the result is left padded with '0' until it matches width
-
-
Method Detail
-
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 anAppendable
.- Parameters:
appendable
- to append value tovalue
- 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
-
-