Class MutableInstant
java.lang.Object
org.apache.logging.log4j.core.time.MutableInstant
- All Implemented Interfaces:
Serializable
,TemporalAccessor
,Instant
,StringBuilderFormattable
An instantaneous point on the time line, used for high-precision log event timestamps.
Modeled on java.time.Instant,
except that this version is mutable to prevent allocating temporary objects that need to be garbage-collected later.
Instances of this class are not thread-safe and should not be shared between threads.
- Since:
- 2.11
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
void
formatTo
(StringBuilder buffer) int
get
(TemporalField field) long
Gets the number of milliseconds from the Java epoch of 1970-01-01T00:00:00Z.long
Gets the number of seconds from the Java epoch of 1970-01-01T00:00:00Z.long
getLong
(TemporalField field) int
Gets the number of nanoseconds, later along the time-line, from the start of the millisecond.int
Gets the number of nanoseconds, later along the time-line, from the start of the second.int
hashCode()
void
void
void
initFromEpochMilli
(long epochMilli, int nanoOfMillisecond) Updates the fields of thisMutableInstant
from the specified epoch millis.void
initFromEpochSecond
(long epochSecond, int nano) Updates the fields of thisMutableInstant
from the specified instant components.static void
instantToMillisAndNanos
(long epochSecond, int nano, long[] result) Updates the elements of the specifiedlong[]
result array from the specified instant components.boolean
isSupported
(TemporalField field) <R> R
query
(TemporalQuery<R> query) range
(TemporalField field) toString()
-
Constructor Details
-
MutableInstant
public MutableInstant()
-
-
Method Details
-
getEpochSecond
public long getEpochSecond()Description copied from interface:Instant
Gets the number of seconds from the Java epoch of 1970-01-01T00:00:00Z.The epoch second count is a simple incrementing count of seconds where second 0 is 1970-01-01T00:00:00Z. The nanosecond part of the day is returned by
Instant.getNanoOfSecond()
.- Specified by:
getEpochSecond
in interfaceInstant
- Returns:
- the seconds from the epoch of 1970-01-01T00:00:00Z
-
getNanoOfSecond
public int getNanoOfSecond()Description copied from interface:Instant
Gets the number of nanoseconds, later along the time-line, from the start of the second.The nanosecond-of-second value measures the total number of nanoseconds from the second returned by
Instant.getEpochSecond()
.- Specified by:
getNanoOfSecond
in interfaceInstant
- Returns:
- the nanoseconds within the second, always positive, never exceeds
999,999,999
-
getEpochMillisecond
public long getEpochMillisecond()Description copied from interface:Instant
Gets the number of milliseconds from the Java epoch of 1970-01-01T00:00:00Z.The epoch millisecond count is a simple incrementing count of milliseconds where millisecond 0 is 1970-01-01T00:00:00Z. The nanosecond part of the day is returned by
Instant.getNanoOfMillisecond()
.- Specified by:
getEpochMillisecond
in interfaceInstant
- Returns:
- the milliseconds from the epoch of 1970-01-01T00:00:00Z
-
getNanoOfMillisecond
public int getNanoOfMillisecond()Description copied from interface:Instant
Gets the number of nanoseconds, later along the time-line, from the start of the millisecond.The nanosecond-of-millisecond value measures the total number of nanoseconds from the millisecond returned by
Instant.getEpochMillisecond()
.- Specified by:
getNanoOfMillisecond
in interfaceInstant
- Returns:
- the nanoseconds within the millisecond, always positive, never exceeds
999,999
-
initFrom
-
initFromEpochMilli
public void initFromEpochMilli(long epochMilli, int nanoOfMillisecond) Updates the fields of thisMutableInstant
from the specified epoch millis.- Parameters:
epochMilli
- the number of milliseconds from the Java epoch of 1970-01-01T00:00:00ZnanoOfMillisecond
- the number of nanoseconds, later along the time-line, from the start of the millisecond
-
initFrom
-
initFromEpochSecond
public void initFromEpochSecond(long epochSecond, int nano) Updates the fields of thisMutableInstant
from the specified instant components.- Parameters:
epochSecond
- the number of seconds from the Java epoch of 1970-01-01T00:00:00Znano
- the number of nanoseconds, later along the time-line, from the start of the second
-
instantToMillisAndNanos
public static void instantToMillisAndNanos(long epochSecond, int nano, long[] result) Updates the elements of the specifiedlong[]
result array from the specified instant components.- Parameters:
epochSecond
- (input) the number of seconds from the Java epoch of 1970-01-01T00:00:00Znano
- (input) the number of nanoseconds, later along the time-line, from the start of the secondresult
- (output) a two-element array to store the result: the first element is the number of milliseconds from the Java epoch of 1970-01-01T00:00:00Z, the second element is the number of nanoseconds, later along the time-line, from the start of the millisecond
-
isSupported
- Specified by:
isSupported
in interfaceTemporalAccessor
-
getLong
- Specified by:
getLong
in interfaceTemporalAccessor
-
range
- Specified by:
range
in interfaceTemporalAccessor
-
get
- Specified by:
get
in interfaceTemporalAccessor
-
query
- Specified by:
query
in interfaceTemporalAccessor
-
equals
-
hashCode
public int hashCode() -
toString
-
formatTo
- Specified by:
formatTo
in interfaceStringBuilderFormattable
-