org.python.core.stringlib

## Class IntegerFormatter

- java.lang.Object
- - org.python.core.stringlib.InternalFormat.Formatter
  - - org.python.core.stringlib.IntegerFormatter

All Implemented Interfaces:
  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
`static class` `IntegerFormatter.Traditional` A minor variation on `IntegerFormatter` to handle "traditional" %-formatting.

### Field Summary

Fields
`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 and Description
`IntegerFormatter(InternalFormat.Spec spec)` Construct the formatter from a specification, allocating a buffer internally for the result.
`IntegerFormatter(StringBuilder result, InternalFormat.Spec spec)` Construct the formatter from a client-supplied buffer, to which the result will be appended, and a specification.

### Method Summary

Methods
`IntegerFormatter` `append(char c)`
`IntegerFormatter` `append(CharSequence csq)`
`IntegerFormatter` `append(CharSequence csq, int start, int end)`
`static PyString` `bin(PyObject number)` Convert the object to binary according to the conventions of Python built-in `bin()`.
`IntegerFormatter` `format(BigInteger value)` Format a `BigInteger`, which is the implementation type of Jython `long`, according to the specification represented by this `IntegerFormatter`.
`IntegerFormatter` `format(int value)` Format an integer according to the specification represented by this `IntegerFormatter`.
`static PyString` `formatNumber(PyObject number, InternalFormat.Spec spec)` Convert the object according to the conventions of Python built-in `hex()`, or `oct()`.

### 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`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### 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(StringBuilder result,
                    InternalFormat.Spec spec)

Construct the formatter from a client-supplied buffer, to which the result will be appended, and a specification. Sets `InternalFormat.Formatter.mark` to the end of the buffer.

Parameters:
  `result` - destination buffer
  `spec` - 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 interface `Appendable`
Overrides:
  `append` in class `InternalFormat.Formatter`

#### append

    public IntegerFormatter append(CharSequence csq)

Specified by:
  `append` in interface `Appendable`
Overrides:
  `append` in class `InternalFormat.Formatter`

#### append

    public IntegerFormatter append(CharSequence csq,
                          int start,
                          int end)
                            throws IndexOutOfBoundsException

Specified by:
  `append` in interface `Appendable`
Overrides:
  `append` in class `InternalFormat.Formatter`
Throws:
  `IndexOutOfBoundsException`

#### format

    public IntegerFormatter format(BigInteger value)

Format a `BigInteger`, which is the implementation type of Jython `long`, according to the specification represented by this `IntegerFormatter`. The conversion type, and flags for grouping or base prefix are dealt with here. At the point this is used, we know the `InternalFormat.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 this `IntegerFormatter`. The conversion type, and flags for grouping or base prefix are dealt with here. At the point this is used, we know the `InternalFormat.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-in `bin()`. The object's __index__ method is called, and is responsible for raising the appropriate error (which the base `PyObject.__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-in `hex()`, or `oct()`. The object's `__index__` method is called, and is responsible for raising the appropriate error (which the base `PyObject.__index__()` does).

Parameters:
  `number` - to convert
Returns:
  PyString converted result