114 * <p>
115 * The duration is measured in "seconds", but these are not necessarily identical to
116 * the scientific "SI second" definition based on atomic clocks.
117 * This difference only impacts durations measured near a leap-second and should not affect
118 * most applications.
119 * See {@link Instant} for a discussion as to the meaning of the second and time-scales.
120 * <p>
121 * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
122 * class; programmers should treat instances that are
123 * {@linkplain #equals(Object) equal} as interchangeable and should not
124 * use instances for synchronization, or unpredictable behavior may
125 * occur. For example, in a future release, synchronization may fail.
126 * The {@code equals} method should be used for comparisons.
127 *
128 * @implSpec
129 * This class is immutable and thread-safe.
130 *
131 * @since 1.8
132 */
133 @jdk.internal.ValueBased
134 public final class Duration
135 implements TemporalAmount, Comparable<Duration>, Serializable {
136
137 /**
138 * Constant for a duration of zero.
139 */
140 public static final Duration ZERO = new Duration(0, 0);
141 /**
142 * Serialization version.
143 */
144 @java.io.Serial
145 private static final long serialVersionUID = 3078945930695997490L;
146 /**
147 * Constant for nanos per second.
148 */
149 private static final BigInteger BI_NANOS_PER_SECOND = BigInteger.valueOf(NANOS_PER_SECOND);
150 /**
151 * The pattern for parsing.
152 */
153 private static class Lazy {
|
114 * <p>
115 * The duration is measured in "seconds", but these are not necessarily identical to
116 * the scientific "SI second" definition based on atomic clocks.
117 * This difference only impacts durations measured near a leap-second and should not affect
118 * most applications.
119 * See {@link Instant} for a discussion as to the meaning of the second and time-scales.
120 * <p>
121 * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
122 * class; programmers should treat instances that are
123 * {@linkplain #equals(Object) equal} as interchangeable and should not
124 * use instances for synchronization, or unpredictable behavior may
125 * occur. For example, in a future release, synchronization may fail.
126 * The {@code equals} method should be used for comparisons.
127 *
128 * @implSpec
129 * This class is immutable and thread-safe.
130 *
131 * @since 1.8
132 */
133 @jdk.internal.ValueBased
134 @jdk.internal.MigratedValueClass
135 public final class Duration
136 implements TemporalAmount, Comparable<Duration>, Serializable {
137
138 /**
139 * Constant for a duration of zero.
140 */
141 public static final Duration ZERO = new Duration(0, 0);
142 /**
143 * Serialization version.
144 */
145 @java.io.Serial
146 private static final long serialVersionUID = 3078945930695997490L;
147 /**
148 * Constant for nanos per second.
149 */
150 private static final BigInteger BI_NANOS_PER_SECOND = BigInteger.valueOf(NANOS_PER_SECOND);
151 /**
152 * The pattern for parsing.
153 */
154 private static class Lazy {
|