Class MutableInstant
- java.lang.Object
-
- org.apache.logging.log4j.core.time.MutableInstant
-
- All Implemented Interfaces:
java.io.Serializable,java.time.temporal.TemporalAccessor,Instant,StringBuilderFormattable
public class MutableInstant extends java.lang.Object implements Instant, java.io.Serializable, java.time.temporal.TemporalAccessor
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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private longepochSecondprivate static intMILLIS_PER_SECONDprivate intnanoOfSecondprivate static intNANOS_PER_MILLIprivate static intNANOS_PER_SECOND
-
Constructor Summary
Constructors Constructor Description MutableInstant()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object object)voidformatTo(java.lang.StringBuilder buffer)Writes a text representation of this object into the specifiedStringBuilder, ideally without allocating temporary objects.intget(java.time.temporal.TemporalField field)longgetEpochMillisecond()Gets the number of milliseconds from the Java epoch of 1970-01-01T00:00:00Z.longgetEpochSecond()Gets the number of seconds from the Java epoch of 1970-01-01T00:00:00Z.longgetLong(java.time.temporal.TemporalField field)intgetNanoOfMillisecond()Gets the number of nanoseconds, later along the time-line, from the start of the millisecond.intgetNanoOfSecond()Gets the number of nanoseconds, later along the time-line, from the start of the second.inthashCode()voidinitFrom(Instant other)voidinitFrom(Clock clock)voidinitFromEpochMilli(long epochMilli, int nanoOfMillisecond)Updates the fields of thisMutableInstantfrom the specified epoch millis.voidinitFromEpochSecond(long epochSecond, int nano)Updates the fields of thisMutableInstantfrom the specified instant components.static voidinstantToMillisAndNanos(long epochSecond, int nano, long[] result)Updates the elements of the specifiedlong[]result array from the specified instant components.booleanisSupported(java.time.temporal.TemporalField field)<R> Rquery(java.time.temporal.TemporalQuery<R> query)java.time.temporal.ValueRangerange(java.time.temporal.TemporalField field)java.lang.StringtoString()private voidvalidateNanoOfMillisecond(int nanoOfMillisecond)private voidvalidateNanoOfSecond(int nano)
-
-
-
Field Detail
-
MILLIS_PER_SECOND
private static final int MILLIS_PER_SECOND
- See Also:
- Constant Field Values
-
NANOS_PER_MILLI
private static final int NANOS_PER_MILLI
- See Also:
- Constant Field Values
-
NANOS_PER_SECOND
private static final int NANOS_PER_SECOND
- See Also:
- Constant Field Values
-
epochSecond
private long epochSecond
-
nanoOfSecond
private int nanoOfSecond
-
-
Method Detail
-
getEpochSecond
public long getEpochSecond()
Description copied from interface:InstantGets 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:
getEpochSecondin interfaceInstant- Returns:
- the seconds from the epoch of 1970-01-01T00:00:00Z
-
getNanoOfSecond
public int getNanoOfSecond()
Description copied from interface:InstantGets 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:
getNanoOfSecondin interfaceInstant- Returns:
- the nanoseconds within the second, always positive, never exceeds
999,999,999
-
getEpochMillisecond
public long getEpochMillisecond()
Description copied from interface:InstantGets 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:
getEpochMillisecondin interfaceInstant- Returns:
- the milliseconds from the epoch of 1970-01-01T00:00:00Z
-
getNanoOfMillisecond
public int getNanoOfMillisecond()
Description copied from interface:InstantGets 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:
getNanoOfMillisecondin interfaceInstant- Returns:
- the nanoseconds within the millisecond, always positive, never exceeds
999,999
-
initFrom
public void initFrom(Instant other)
-
initFromEpochMilli
public void initFromEpochMilli(long epochMilli, int nanoOfMillisecond)Updates the fields of thisMutableInstantfrom 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
-
validateNanoOfMillisecond
private void validateNanoOfMillisecond(int nanoOfMillisecond)
-
initFrom
public void initFrom(Clock clock)
-
initFromEpochSecond
public void initFromEpochSecond(long epochSecond, int nano)Updates the fields of thisMutableInstantfrom 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
-
validateNanoOfSecond
private void validateNanoOfSecond(int nano)
-
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
public boolean isSupported(java.time.temporal.TemporalField field)
- Specified by:
isSupportedin interfacejava.time.temporal.TemporalAccessor
-
getLong
public long getLong(java.time.temporal.TemporalField field)
- Specified by:
getLongin interfacejava.time.temporal.TemporalAccessor
-
range
public java.time.temporal.ValueRange range(java.time.temporal.TemporalField field)
- Specified by:
rangein interfacejava.time.temporal.TemporalAccessor
-
get
public int get(java.time.temporal.TemporalField field)
- Specified by:
getin interfacejava.time.temporal.TemporalAccessor
-
query
public <R> R query(java.time.temporal.TemporalQuery<R> query)
- Specified by:
queryin interfacejava.time.temporal.TemporalAccessor
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
formatTo
public void formatTo(java.lang.StringBuilder buffer)
Description copied from interface:StringBuilderFormattableWrites a text representation of this object into the specifiedStringBuilder, ideally without allocating temporary objects.- Specified by:
formatToin interfaceStringBuilderFormattable- Parameters:
buffer- the StringBuilder to write into
-
-