Package org.pkl.core
Class Duration
- java.lang.Object
-
- org.pkl.core.Duration
-
- All Implemented Interfaces:
java.io.Serializable,Value
public final class Duration extends java.lang.Object implements Value
Java representation of apkl.base#Durationvalue.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Duration(double value, DurationUnit unit)Constructs a new duration with the given value and unit.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(ValueConverter<T> converter)Invokes the given converters's convert method for thisValue.voidaccept(ValueVisitor visitor)Invokes the given visitor's visit method for thisValue.DurationconvertTo(DurationUnit other)Returns a new duration with the given unit and this value converted to the given unit.doubleconvertValueTo(DurationUnit other)Returns the value of this duration converted to the given unit.booleanequals(@Nullable java.lang.Object obj)PClassInfo<?>getClassInfo()Returns information about the Pkl class associated with thisValue.DurationUnitgetUnit()Returns the unit of this duration.doublegetValue()Returns the value of this duration.inthashCode()doubleinDays()Returns the value of this duration measured inDurationUnit.DAYS.doubleinHours()Returns the value of this duration measured inDurationUnit.HOURS.doubleinMicros()Returns the value of this duration measured inDurationUnit.MICROS.doubleinMillis()Returns the value of this duration measured inDurationUnit.MILLIS.doubleinMinutes()Returns the value of this duration measured inDurationUnit.MINUTES.doubleinNanos()Returns the value of this duration measured inDurationUnit.NANOS.doubleinSeconds()Returns the value of this duration measured inDurationUnit.SECONDS.longinWholeDays()Returns the value of this duration measured in wholeDurationUnit.DAYS.longinWholeHours()Returns the value of this duration measured in wholeDurationUnit.HOURS.longinWholeMicros()Returns the value of this duration measured in wholeDurationUnit.MICROS.longinWholeMillis()Returns the value of this duration measured in wholeDurationUnit.MILLIS.longinWholeMinutes()Returns the value of this duration measured in wholeDurationUnit.MINUTES.longinWholeNanos()Returns the value of this duration measured in wholeDurationUnit.NANOS.longinWholeSeconds()Returns the value of this duration measured in wholeDurationUnit.SECONDS.static DurationofDays(double value)Constructs a new duration with the given value and unitDurationUnit.DAYS.static DurationofHours(double value)Constructs a new duration with the given value and unitDurationUnit.HOURS.static DurationofMicros(double value)Constructs a new duration with the given value and unitDurationUnit.MICROS.static DurationofMillis(double value)Constructs a new duration with the given value and unitDurationUnit.MILLIS.static DurationofMinutes(double value)Constructs a new duration with the given value and unitDurationUnit.MINUTES.static DurationofNanos(double value)Constructs a new duration with the given value and unitDurationUnit.NANOS.static DurationofSeconds(double value)Constructs a new duration with the given value and unitDurationUnit.SECONDS.java.lang.StringtoIsoString()Returns an ISO 8601 representation of this duration.java.time.DurationtoJavaDuration()Converts this duration to aDuration.java.lang.StringtoString()
-
-
-
Constructor Detail
-
Duration
public Duration(double value, DurationUnit unit)Constructs a new duration with the given value and unit.
-
-
Method Detail
-
ofNanos
public static Duration ofNanos(double value)
Constructs a new duration with the given value and unitDurationUnit.NANOS.
-
ofMicros
public static Duration ofMicros(double value)
Constructs a new duration with the given value and unitDurationUnit.MICROS.
-
ofMillis
public static Duration ofMillis(double value)
Constructs a new duration with the given value and unitDurationUnit.MILLIS.
-
ofSeconds
public static Duration ofSeconds(double value)
Constructs a new duration with the given value and unitDurationUnit.SECONDS.
-
ofMinutes
public static Duration ofMinutes(double value)
Constructs a new duration with the given value and unitDurationUnit.MINUTES.
-
ofHours
public static Duration ofHours(double value)
Constructs a new duration with the given value and unitDurationUnit.HOURS.
-
ofDays
public static Duration ofDays(double value)
Constructs a new duration with the given value and unitDurationUnit.DAYS.
-
getValue
public double getValue()
Returns the value of this duration. The value is relative to the unit and may be negative.
-
toIsoString
public java.lang.String toIsoString()
Returns an ISO 8601 representation of this duration.
-
getUnit
public DurationUnit getUnit()
Returns the unit of this duration.
-
inNanos
public double inNanos()
Returns the value of this duration measured inDurationUnit.NANOS.
-
inMicros
public double inMicros()
Returns the value of this duration measured inDurationUnit.MICROS.
-
inMillis
public double inMillis()
Returns the value of this duration measured inDurationUnit.MILLIS.
-
inSeconds
public double inSeconds()
Returns the value of this duration measured inDurationUnit.SECONDS.
-
inMinutes
public double inMinutes()
Returns the value of this duration measured inDurationUnit.MINUTES.
-
inHours
public double inHours()
Returns the value of this duration measured inDurationUnit.HOURS.
-
inDays
public double inDays()
Returns the value of this duration measured inDurationUnit.DAYS.
-
inWholeNanos
public long inWholeNanos()
Returns the value of this duration measured in wholeDurationUnit.NANOS.
-
inWholeMicros
public long inWholeMicros()
Returns the value of this duration measured in wholeDurationUnit.MICROS.
-
inWholeMillis
public long inWholeMillis()
Returns the value of this duration measured in wholeDurationUnit.MILLIS.
-
inWholeSeconds
public long inWholeSeconds()
Returns the value of this duration measured in wholeDurationUnit.SECONDS.
-
inWholeMinutes
public long inWholeMinutes()
Returns the value of this duration measured in wholeDurationUnit.MINUTES.
-
inWholeHours
public long inWholeHours()
Returns the value of this duration measured in wholeDurationUnit.HOURS.
-
inWholeDays
public long inWholeDays()
Returns the value of this duration measured in wholeDurationUnit.DAYS.
-
toJavaDuration
public java.time.Duration toJavaDuration()
Converts this duration to aDuration. IfgetValue()is NaN, +/-Infinity or too large to fit intoDuration,ArithmeticExceptionis thrown.
-
convertTo
public Duration convertTo(DurationUnit other)
Returns a new duration with the given unit and this value converted to the given unit.
-
convertValueTo
public double convertValueTo(DurationUnit other)
Returns the value of this duration converted to the given unit.
-
accept
public void accept(ValueVisitor visitor)
Invokes the given visitor's visit method for thisValue.
-
accept
public <T> T accept(ValueConverter<T> converter)
Invokes the given converters's convert method for thisValue.
-
getClassInfo
public PClassInfo<?> getClassInfo()
Returns information about the Pkl class associated with thisValue.- Specified by:
getClassInfoin interfaceValue
-
equals
public boolean equals(@Nullable java.lang.Object obj)
- 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
-
-