Class DateTimePrintContext


  • final class DateTimePrintContext
    extends java.lang.Object
    Context object used during date and time printing.

    This class provides a single wrapper to items used in the print.

    Specification for implementors

    This class is a mutable context intended for use from a single thread. Usage of the class is thread-safe within standard printing as the framework creates a new instance of the class for each print and printing is single-threaded.
    • Field Detail

      • locale

        private java.util.Locale locale
        The locale, not null.
      • symbols

        private DecimalStyle symbols
        The symbols, not null.
      • optional

        private int optional
        Whether the current formatter is optional.
    • Constructor Detail

      • DateTimePrintContext

        DateTimePrintContext​(TemporalAccessor temporal,
                             DateTimeFormatter formatter)
        Creates a new instance of the context.
        Parameters:
        temporal - the temporal object being output, not null
        formatter - the formatter controlling the print, not null
    • Method Detail

      • getTemporal

        TemporalAccessor getTemporal()
        Gets the temporal object being output.
        Returns:
        the temporal object, not null
      • getLocale

        java.util.Locale getLocale()
        Gets the locale.

        This locale is used to control localization in the print output except where localization is controlled by the symbols.

        Returns:
        the locale, not null
      • getSymbols

        DecimalStyle getSymbols()
        Gets the formatting symbols.

        The symbols control the localization of numeric output.

        Returns:
        the formatting symbols, not null
      • startOptional

        void startOptional()
        Starts the printing of an optional segment of the input.
      • endOptional

        void endOptional()
        Ends the printing of an optional segment of the input.
      • getValue

        <R> R getValue​(TemporalQuery<R> query)
        Gets a value using a query.
        Parameters:
        query - the query to use, not null
        Returns:
        the result, null if not found and optional is true
        Throws:
        DateTimeException - if the type is not available and the section is not optional
      • getValue

        java.lang.Long getValue​(TemporalField field)
        Gets the value of the specified field.

        This will return the value for the specified field.

        Parameters:
        field - the field to find, not null
        Returns:
        the value, null if not found and optional is true
        Throws:
        DateTimeException - if the field is not available and the section is not optional
      • toString

        public java.lang.String toString()
        Returns a string version of the context for debugging.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of the context, not null
      • setDateTime

        void setDateTime​(TemporalAccessor temporal)
        Sets the date-time being output.
        Parameters:
        temporal - the date-time object, not null
      • setLocale

        void setLocale​(java.util.Locale locale)
        Sets the locale.

        This locale is used to control localization in the print output except where localization is controlled by the symbols.

        Parameters:
        locale - the locale, not null