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.
  • Field Details

  • Constructor Details

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

    • 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