Enum InstantNumberFormatter

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<InstantNumberFormatter>, InstantFormatter

    public enum InstantNumberFormatter
    extends java.lang.Enum<InstantNumberFormatter>
    implements InstantFormatter
    Formats an Instant numerically; e.g., formats its epoch1 seconds.

    1 Epoch is a fixed instant on 1970-01-01Z.

    Internal usage only!

    This class is intended only for internal Log4j usage. Log4j users should not use this class! This class is not subject to any backward compatibility concerns.

    Since:
    2.25.0
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      EPOCH_MILLIS
      Formats milliseconds since epoch, including the nanosecond fraction; e.g., 1581082727982.123456.
      EPOCH_MILLIS_NANOS
      Formats the nanosecond fraction of milliseconds since epoch; e.g., 123456.
      EPOCH_MILLIS_ROUNDED
      Formats milliseconds since epoch, excluding the nanosecond fraction; e.g., 1581082727982.
      EPOCH_NANOS
      Formats nanoseconds since epoch; e.g., 1581082727982123456.
      EPOCH_SECONDS
      Formats seconds since epoch, including the nanosecond fraction; e.g., 1581082727.982123456.
      EPOCH_SECONDS_NANOS
      Formats the nanosecond fraction of seconds since epoch; e.g., 982123456.
      EPOCH_SECONDS_ROUNDED
      Formats seconds since epoch, excluding the nanosecond fraction; e.g., 1581082727.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.function.BiConsumer<Instant,​java.lang.StringBuilder> formatter  
      private java.time.temporal.ChronoUnit precision  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private InstantNumberFormatter​(java.time.temporal.ChronoUnit precision, java.util.function.BiConsumer<Instant,​java.lang.StringBuilder> formatter)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static long epochNanos​(Instant instant)  
      void formatTo​(java.lang.StringBuilder buffer, Instant instant)  
      java.time.temporal.ChronoUnit getPrecision()  
      static InstantNumberFormatter valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static InstantNumberFormatter[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • EPOCH_NANOS

        public static final InstantNumberFormatter EPOCH_NANOS
        Formats nanoseconds since epoch; e.g., 1581082727982123456.
      • EPOCH_MILLIS

        public static final InstantNumberFormatter EPOCH_MILLIS
        Formats milliseconds since epoch, including the nanosecond fraction; e.g., 1581082727982.123456. The nanosecond fraction will be skipped if it is zero.
      • EPOCH_MILLIS_ROUNDED

        public static final InstantNumberFormatter EPOCH_MILLIS_ROUNDED
        Formats milliseconds since epoch, excluding the nanosecond fraction; e.g., 1581082727982.
      • EPOCH_MILLIS_NANOS

        public static final InstantNumberFormatter EPOCH_MILLIS_NANOS
        Formats the nanosecond fraction of milliseconds since epoch; e.g., 123456.
      • EPOCH_SECONDS

        public static final InstantNumberFormatter EPOCH_SECONDS
        Formats seconds since epoch, including the nanosecond fraction; e.g., 1581082727.982123456. The nanosecond fraction will be skipped if it is zero.
      • EPOCH_SECONDS_ROUNDED

        public static final InstantNumberFormatter EPOCH_SECONDS_ROUNDED
        Formats seconds since epoch, excluding the nanosecond fraction; e.g., 1581082727. The nanosecond fraction will be skipped if it is zero.
      • EPOCH_SECONDS_NANOS

        public static final InstantNumberFormatter EPOCH_SECONDS_NANOS
        Formats the nanosecond fraction of seconds since epoch; e.g., 982123456.
    • Field Detail

      • precision

        private final java.time.temporal.ChronoUnit precision
      • formatter

        private final java.util.function.BiConsumer<Instant,​java.lang.StringBuilder> formatter
    • Constructor Detail

      • InstantNumberFormatter

        private InstantNumberFormatter​(java.time.temporal.ChronoUnit precision,
                                       java.util.function.BiConsumer<Instant,​java.lang.StringBuilder> formatter)
    • Method Detail

      • values

        public static InstantNumberFormatter[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (InstantNumberFormatter c : InstantNumberFormatter.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static InstantNumberFormatter valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • epochNanos

        private static long epochNanos​(Instant instant)
      • getPrecision

        public java.time.temporal.ChronoUnit getPrecision()
        Specified by:
        getPrecision in interface InstantFormatter
        Returns:
        the time precision of the formatted output