Package org.python.core.stringlib
Class IntegerFormatter
- java.lang.Object
-
- org.python.core.stringlib.InternalFormat.Formatter
-
- org.python.core.stringlib.IntegerFormatter
-
- All Implemented Interfaces:
java.lang.Appendable
- Direct Known Subclasses:
IntegerFormatter.Traditional
public class IntegerFormatter extends InternalFormat.Formatter
A class that provides the implementation of integer formatting. In a limited way, it acts like a StringBuilder to which text and one or more numbers may be appended, formatted according to the format specifier supplied at construction. These are ephemeral objects that are not, on their own, thread safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IntegerFormatter.Traditional
A minor variation onIntegerFormatter
to handle "traditional" %-formatting.
-
Field Summary
Fields Modifier and Type Field Description static InternalFormat.Spec
BIN
Format specification used by bin().static InternalFormat.Spec
HEX
Format specification used by hex().static InternalFormat.Spec
OCT
Format specification used by oct().
-
Constructor Summary
Constructors Constructor Description IntegerFormatter(java.lang.StringBuilder result, InternalFormat.Spec spec)
Construct the formatter from a client-supplied buffer, to which the result will be appended, and a specification.IntegerFormatter(InternalFormat.Spec spec)
Construct the formatter from a specification, allocating a buffer internally for the result.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description IntegerFormatter
append(char c)
IntegerFormatter
append(java.lang.CharSequence csq)
IntegerFormatter
append(java.lang.CharSequence csq, int start, int end)
static PyString
bin(PyObject number)
Convert the object to binary according to the conventions of Python built-inbin()
.IntegerFormatter
format(int value)
Format an integer according to the specification represented by thisIntegerFormatter
.IntegerFormatter
format(java.math.BigInteger value)
Format aBigInteger
, which is the implementation type of Jythonlong
, according to the specification represented by thisIntegerFormatter
.static PyString
formatNumber(PyObject number, InternalFormat.Spec spec)
Convert the object according to the conventions of Python built-inhex()
, oroct()
.-
Methods inherited from class org.python.core.stringlib.InternalFormat.Formatter
alignmentNotAllowed, alternateFormNotAllowed, alternateFormNotAllowed, getPyResult, getResult, isBytes, notAllowed, notAllowed, pad, precisionNotAllowed, precisionTooLarge, setBytes, setStart, signNotAllowed, toString, unknownFormat, zeroPaddingNotAllowed
-
-
-
-
Field Detail
-
BIN
public static final InternalFormat.Spec BIN
Format specification used by bin().
-
OCT
public static final InternalFormat.Spec OCT
Format specification used by oct().
-
HEX
public static final InternalFormat.Spec HEX
Format specification used by hex().
-
-
Constructor Detail
-
IntegerFormatter
public IntegerFormatter(java.lang.StringBuilder result, InternalFormat.Spec spec)
Construct the formatter from a client-supplied buffer, to which the result will be appended, and a specification. SetsInternalFormat.Formatter.mark
to the end of the buffer.- Parameters:
result
- destination bufferspec
- parsed conversion specification
-
IntegerFormatter
public IntegerFormatter(InternalFormat.Spec spec)
Construct the formatter from a specification, allocating a buffer internally for the result.- Parameters:
spec
- parsed conversion specification
-
-
Method Detail
-
append
public IntegerFormatter append(char c)
- Specified by:
append
in interfacejava.lang.Appendable
- Overrides:
append
in classInternalFormat.Formatter
-
append
public IntegerFormatter append(java.lang.CharSequence csq)
- Specified by:
append
in interfacejava.lang.Appendable
- Overrides:
append
in classInternalFormat.Formatter
-
append
public IntegerFormatter append(java.lang.CharSequence csq, int start, int end) throws java.lang.IndexOutOfBoundsException
- Specified by:
append
in interfacejava.lang.Appendable
- Overrides:
append
in classInternalFormat.Formatter
- Throws:
java.lang.IndexOutOfBoundsException
-
format
public IntegerFormatter format(java.math.BigInteger value)
Format aBigInteger
, which is the implementation type of Jythonlong
, according to the specification represented by thisIntegerFormatter
. The conversion type, and flags for grouping or base prefix are dealt with here. At the point this is used, we know theInternalFormat.Formatter.spec
is one of the integer types.- Parameters:
value
- to convert- Returns:
- this object
-
format
public IntegerFormatter format(int value)
Format an integer according to the specification represented by thisIntegerFormatter
. The conversion type, and flags for grouping or base prefix are dealt with here. At the point this is used, we know theInternalFormat.Formatter.spec
is one of the integer types.- Parameters:
value
- to convert- Returns:
- this object
-
bin
public static PyString bin(PyObject number)
Convert the object to binary according to the conventions of Python built-inbin()
. The object's __index__ method is called, and is responsible for raising the appropriate error (which the basePyObject.__index__()
does).- Parameters:
number
- to convert- Returns:
- PyString converted result
-
formatNumber
public static PyString formatNumber(PyObject number, InternalFormat.Spec spec)
Convert the object according to the conventions of Python built-inhex()
, oroct()
. The object's__index__
method is called, and is responsible for raising the appropriate error (which the basePyObject.__index__()
does).- Parameters:
number
- to convert- Returns:
- PyString converted result
-
-