Class InstantFormatter
- java.lang.Object
-
- org.apache.logging.log4j.layout.template.json.util.InstantFormatter
-
public final class InstantFormatter extends java.lang.Object
A compositeInstant
formatter trying to employ eitherFixedDateFormat
,FastDateFormat
, orDateTimeFormatter
in the given order due to performance reasons.Note that
FixedDateFormat
andFastDateFormat
only support millisecond precision. If the pattern asks for a higher precision,DateTimeFormatter
will be employed, which is significantly slower.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
InstantFormatter.Builder
private static interface
InstantFormatter.Formatter
private static interface
InstantFormatter.FormatterFactory
private static class
InstantFormatter.JavaDateTimeFormatter
private static class
InstantFormatter.JavaDateTimeFormatterFactory
private static class
InstantFormatter.Log4jFastFormatter
private static class
InstantFormatter.Log4jFastFormatterFactory
private static class
InstantFormatter.Log4jFixedFormatter
private static class
InstantFormatter.Log4jFixedFormatterFactory
-
Field Summary
Fields Modifier and Type Field Description private InstantFormatter.Formatter
formatter
private static InstantFormatter.FormatterFactory[]
FORMATTER_FACTORIES
The list of formatter factories in decreasing efficiency order.
-
Constructor Summary
Constructors Modifier Constructor Description private
InstantFormatter(InstantFormatter.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
format(Instant instant)
void
format(Instant instant, java.lang.StringBuilder stringBuilder)
java.lang.Class<?>
getInternalImplementationClass()
boolean
isInstantMatching(Instant instant1, Instant instant2)
Checks if the givenInstant
s are equal from the point of view of the employed formatter.static InstantFormatter.Builder
newBuilder()
private static boolean
patternSupported(java.lang.String pattern, java.util.Locale locale, java.util.TimeZone timeZone, InstantFormatter.Formatter formatter)
Checks if the provided formatter output matches with the one generated byDateTimeFormatter
.
-
-
-
Field Detail
-
FORMATTER_FACTORIES
private static final InstantFormatter.FormatterFactory[] FORMATTER_FACTORIES
The list of formatter factories in decreasing efficiency order.
-
formatter
private final InstantFormatter.Formatter formatter
-
-
Constructor Detail
-
InstantFormatter
private InstantFormatter(InstantFormatter.Builder builder)
-
-
Method Detail
-
format
public java.lang.String format(Instant instant)
-
format
public void format(Instant instant, java.lang.StringBuilder stringBuilder)
-
isInstantMatching
public boolean isInstantMatching(Instant instant1, Instant instant2)
Checks if the givenInstant
s are equal from the point of view of the employed formatter.This method should be preferred over
Instant#equals(Object)
. For instance,FixedDateFormat
andFastDateFormat
discard nanoseconds, hence, from their point of view, two differentInstant
s are equal if they match up to millisecond precision.
-
getInternalImplementationClass
public java.lang.Class<?> getInternalImplementationClass()
-
newBuilder
public static InstantFormatter.Builder newBuilder()
-
patternSupported
private static boolean patternSupported(java.lang.String pattern, java.util.Locale locale, java.util.TimeZone timeZone, InstantFormatter.Formatter formatter)
Checks if the provided formatter output matches with the one generated byDateTimeFormatter
.
-
-