Class 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.
    • 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. 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​(java.lang.CharSequence csq,
                                       int start,
                                       int end)
                                throws java.lang.IndexOutOfBoundsException
        Specified by:
        append in interface java.lang.Appendable
        Overrides:
        append in class InternalFormat.Formatter
        Throws:
        java.lang.IndexOutOfBoundsException
      • format

        public IntegerFormatter format​(java.math.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