jdk/src/java.base/share/classes/java/util/concurrent/TimeUnit.java
author sla
Thu, 05 Feb 2015 12:59:01 +0100
changeset 28777 01aad659d989
parent 25859 3317bb8137f4
child 32991 b27c76b82713
permissions -rw-r--r--
8072456: @since tags missing from TimeUnit Reviewed-by: alanb, martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * This file is available under and governed by the GNU General Public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * License version 2 only, as published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * However, the following notice accompanied the original version of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Written by Doug Lea with assistance from members of JCP JSR-166
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Expert Group and released to the public domain, as explained at
9242
ef138d47df58 7034657: Update Creative Commons license URL in legal notices
dl
parents: 7518
diff changeset
    33
 * http://creativecommons.org/publicdomain/zero/1.0/
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
package java.util.concurrent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
    39
 * A {@code TimeUnit} represents time durations at a given unit of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * granularity and provides utility methods to convert across units,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * and to perform timing and delay operations in these units.  A
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
    42
 * {@code TimeUnit} does not maintain time information, but only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * helps organize and use time representations that may be maintained
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * separately across various contexts.  A nanosecond is defined as one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * thousandth of a microsecond, a microsecond as one thousandth of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * millisecond, a millisecond as one thousandth of a second, a minute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * as sixty seconds, an hour as sixty minutes, and a day as twenty four
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * hours.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
    50
 * <p>A {@code TimeUnit} is mainly used to inform time-based methods
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * how a given timing parameter should be interpreted. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * the following code will timeout in 50 milliseconds if the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * java.util.concurrent.locks.Lock lock} is not available:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
14325
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9242
diff changeset
    55
 *  <pre> {@code
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9242
diff changeset
    56
 * Lock lock = ...;
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9242
diff changeset
    57
 * if (lock.tryLock(50L, TimeUnit.MILLISECONDS)) ...}</pre>
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9242
diff changeset
    58
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * while this code will timeout in 50 seconds:
14325
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9242
diff changeset
    60
 *  <pre> {@code
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9242
diff changeset
    61
 * Lock lock = ...;
622c473a21aa 8001575: Minor/sync/cleanup j.u.c with Dougs CVS - Oct 2012
dl
parents: 9242
diff changeset
    62
 * if (lock.tryLock(50L, TimeUnit.SECONDS)) ...}</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Note however, that there is no guarantee that a particular timeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * implementation will be able to notice the passage of time at the
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
    66
 * same granularity as the given {@code TimeUnit}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @author Doug Lea
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
public enum TimeUnit {
19048
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
    72
    /**
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
    73
     * Time unit representing one thousandth of a microsecond
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
    74
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    NANOSECONDS {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        public long toNanos(long d)   { return d; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        public long toMicros(long d)  { return d/(C1/C0); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        public long toMillis(long d)  { return d/(C2/C0); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        public long toSeconds(long d) { return d/(C3/C0); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        public long toMinutes(long d) { return d/(C4/C0); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        public long toHours(long d)   { return d/(C5/C0); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        public long toDays(long d)    { return d/(C6/C0); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        public long convert(long d, TimeUnit u) { return u.toNanos(d); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        int excessNanos(long d, long m) { return (int)(d - (m*C2)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    },
19048
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
    86
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
    87
    /**
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
    88
     * Time unit representing one thousandth of a millisecond
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
    89
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    MICROSECONDS {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        public long toNanos(long d)   { return x(d, C1/C0, MAX/(C1/C0)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        public long toMicros(long d)  { return d; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        public long toMillis(long d)  { return d/(C2/C1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        public long toSeconds(long d) { return d/(C3/C1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        public long toMinutes(long d) { return d/(C4/C1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        public long toHours(long d)   { return d/(C5/C1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        public long toDays(long d)    { return d/(C6/C1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        public long convert(long d, TimeUnit u) { return u.toMicros(d); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        int excessNanos(long d, long m) { return (int)((d*C1) - (m*C2)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    },
19048
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   101
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   102
    /**
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   103
     * Time unit representing one thousandth of a second
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   104
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    MILLISECONDS {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        public long toNanos(long d)   { return x(d, C2/C0, MAX/(C2/C0)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        public long toMicros(long d)  { return x(d, C2/C1, MAX/(C2/C1)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        public long toMillis(long d)  { return d; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        public long toSeconds(long d) { return d/(C3/C2); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        public long toMinutes(long d) { return d/(C4/C2); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        public long toHours(long d)   { return d/(C5/C2); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        public long toDays(long d)    { return d/(C6/C2); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        public long convert(long d, TimeUnit u) { return u.toMillis(d); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        int excessNanos(long d, long m) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    },
19048
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   116
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   117
    /**
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   118
     * Time unit representing one second
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   119
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    SECONDS {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        public long toNanos(long d)   { return x(d, C3/C0, MAX/(C3/C0)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        public long toMicros(long d)  { return x(d, C3/C1, MAX/(C3/C1)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        public long toMillis(long d)  { return x(d, C3/C2, MAX/(C3/C2)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        public long toSeconds(long d) { return d; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        public long toMinutes(long d) { return d/(C4/C3); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        public long toHours(long d)   { return d/(C5/C3); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        public long toDays(long d)    { return d/(C6/C3); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        public long convert(long d, TimeUnit u) { return u.toSeconds(d); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        int excessNanos(long d, long m) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    },
19048
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   131
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   132
    /**
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   133
     * Time unit representing sixty seconds
28777
01aad659d989 8072456: @since tags missing from TimeUnit
sla
parents: 25859
diff changeset
   134
     * @since 1.6
19048
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   135
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    MINUTES {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        public long toNanos(long d)   { return x(d, C4/C0, MAX/(C4/C0)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        public long toMicros(long d)  { return x(d, C4/C1, MAX/(C4/C1)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        public long toMillis(long d)  { return x(d, C4/C2, MAX/(C4/C2)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        public long toSeconds(long d) { return x(d, C4/C3, MAX/(C4/C3)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        public long toMinutes(long d) { return d; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        public long toHours(long d)   { return d/(C5/C4); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        public long toDays(long d)    { return d/(C6/C4); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        public long convert(long d, TimeUnit u) { return u.toMinutes(d); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        int excessNanos(long d, long m) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    },
19048
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   147
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   148
    /**
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   149
     * Time unit representing sixty minutes
28777
01aad659d989 8072456: @since tags missing from TimeUnit
sla
parents: 25859
diff changeset
   150
     * @since 1.6
19048
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   151
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    HOURS {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        public long toNanos(long d)   { return x(d, C5/C0, MAX/(C5/C0)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        public long toMicros(long d)  { return x(d, C5/C1, MAX/(C5/C1)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        public long toMillis(long d)  { return x(d, C5/C2, MAX/(C5/C2)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        public long toSeconds(long d) { return x(d, C5/C3, MAX/(C5/C3)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        public long toMinutes(long d) { return x(d, C5/C4, MAX/(C5/C4)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        public long toHours(long d)   { return d; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        public long toDays(long d)    { return d/(C6/C5); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        public long convert(long d, TimeUnit u) { return u.toHours(d); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        int excessNanos(long d, long m) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    },
19048
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   163
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   164
    /**
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   165
     * Time unit representing twenty four hours
28777
01aad659d989 8072456: @since tags missing from TimeUnit
sla
parents: 25859
diff changeset
   166
     * @since 1.6
19048
7d0a94c79779 8021417: Fix doclint issues in java.util.concurrent
chegar
parents: 18768
diff changeset
   167
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    DAYS {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        public long toNanos(long d)   { return x(d, C6/C0, MAX/(C6/C0)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        public long toMicros(long d)  { return x(d, C6/C1, MAX/(C6/C1)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        public long toMillis(long d)  { return x(d, C6/C2, MAX/(C6/C2)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        public long toSeconds(long d) { return x(d, C6/C3, MAX/(C6/C3)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        public long toMinutes(long d) { return x(d, C6/C4, MAX/(C6/C4)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        public long toHours(long d)   { return x(d, C6/C5, MAX/(C6/C5)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        public long toDays(long d)    { return d; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        public long convert(long d, TimeUnit u) { return u.toDays(d); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        int excessNanos(long d, long m) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    // Handy constants for conversion methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    static final long C0 = 1L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    static final long C1 = C0 * 1000L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    static final long C2 = C1 * 1000L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    static final long C3 = C2 * 1000L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    static final long C4 = C3 * 60L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    static final long C5 = C4 * 60L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    static final long C6 = C5 * 24L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    static final long MAX = Long.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Scale d by m, checking for overflow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * This has a short name to make above code more readable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    static long x(long d, long m, long over) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (d >  over) return Long.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (d < -over) return Long.MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return d * m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    // To maintain full signature compatibility with 1.5, and to improve the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    // clarity of the generated javadoc (see 6287639: Abstract methods in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    // enum classes should not be listed as abstract), method convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    // etc. are not declared abstract but otherwise act as abstract methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   207
     * Converts the given time duration in the given unit to this unit.
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   208
     * Conversions from finer to coarser granularities truncate, so
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   209
     * lose precision. For example, converting {@code 999} milliseconds
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   210
     * to seconds results in {@code 0}. Conversions from coarser to
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   211
     * finer granularities with arguments that would numerically
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   212
     * overflow saturate to {@code Long.MIN_VALUE} if negative or
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   213
     * {@code Long.MAX_VALUE} if positive.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * <p>For example, to convert 10 minutes to milliseconds, use:
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   216
     * {@code TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   218
     * @param sourceDuration the time duration in the given {@code sourceUnit}
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   219
     * @param sourceUnit the unit of the {@code sourceDuration} argument
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @return the converted duration in this unit,
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   221
     * or {@code Long.MIN_VALUE} if conversion would negatively
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   222
     * overflow, or {@code Long.MAX_VALUE} if it would positively overflow.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public long convert(long sourceDuration, TimeUnit sourceUnit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        throw new AbstractMethodError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   229
     * Equivalent to
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   230
     * {@link #convert(long, TimeUnit) NANOSECONDS.convert(duration, this)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @param duration the duration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @return the converted duration,
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   233
     * or {@code Long.MIN_VALUE} if conversion would negatively
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   234
     * overflow, or {@code Long.MAX_VALUE} if it would positively overflow.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public long toNanos(long duration) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        throw new AbstractMethodError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   241
     * Equivalent to
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   242
     * {@link #convert(long, TimeUnit) MICROSECONDS.convert(duration, this)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @param duration the duration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @return the converted duration,
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   245
     * or {@code Long.MIN_VALUE} if conversion would negatively
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   246
     * overflow, or {@code Long.MAX_VALUE} if it would positively overflow.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public long toMicros(long duration) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        throw new AbstractMethodError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   253
     * Equivalent to
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   254
     * {@link #convert(long, TimeUnit) MILLISECONDS.convert(duration, this)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @param duration the duration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return the converted duration,
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   257
     * or {@code Long.MIN_VALUE} if conversion would negatively
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   258
     * overflow, or {@code Long.MAX_VALUE} if it would positively overflow.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public long toMillis(long duration) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        throw new AbstractMethodError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   265
     * Equivalent to
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   266
     * {@link #convert(long, TimeUnit) SECONDS.convert(duration, this)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param duration the duration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @return the converted duration,
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   269
     * or {@code Long.MIN_VALUE} if conversion would negatively
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   270
     * overflow, or {@code Long.MAX_VALUE} if it would positively overflow.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public long toSeconds(long duration) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        throw new AbstractMethodError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   277
     * Equivalent to
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   278
     * {@link #convert(long, TimeUnit) MINUTES.convert(duration, this)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param duration the duration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @return the converted duration,
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   281
     * or {@code Long.MIN_VALUE} if conversion would negatively
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   282
     * overflow, or {@code Long.MAX_VALUE} if it would positively overflow.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public long toMinutes(long duration) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        throw new AbstractMethodError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   290
     * Equivalent to
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   291
     * {@link #convert(long, TimeUnit) HOURS.convert(duration, this)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @param duration the duration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @return the converted duration,
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   294
     * or {@code Long.MIN_VALUE} if conversion would negatively
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   295
     * overflow, or {@code Long.MAX_VALUE} if it would positively overflow.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public long toHours(long duration) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        throw new AbstractMethodError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   303
     * Equivalent to
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   304
     * {@link #convert(long, TimeUnit) DAYS.convert(duration, this)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @param duration the duration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @return the converted duration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public long toDays(long duration) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        throw new AbstractMethodError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Utility to compute the excess-nanosecond argument to wait,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * sleep, join.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @param d the duration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @param m the number of milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @return the number of nanoseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    abstract int excessNanos(long d, long m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
7518
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   323
     * Performs a timed {@link Object#wait(long, int) Object.wait}
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   324
     * using this time unit.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * This is a convenience method that converts timeout arguments
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   326
     * into the form required by the {@code Object.wait} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   328
     * <p>For example, you could implement a blocking {@code poll}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * method (see {@link BlockingQueue#poll BlockingQueue.poll})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * using:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
7518
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   332
     *  <pre> {@code
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   333
     * public synchronized Object poll(long timeout, TimeUnit unit)
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   334
     *     throws InterruptedException {
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   335
     *   while (empty) {
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   336
     *     unit.timedWait(this, timeout);
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   337
     *     ...
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   338
     *   }
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   339
     * }}</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @param obj the object to wait on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @param timeout the maximum time to wait. If less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * or equal to zero, do not wait at all.
7518
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   344
     * @throws InterruptedException if interrupted while waiting
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public void timedWait(Object obj, long timeout)
7518
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   347
            throws InterruptedException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (timeout > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            long ms = toMillis(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            int ns = excessNanos(timeout, ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            obj.wait(ms, ns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    /**
7518
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   356
     * Performs a timed {@link Thread#join(long, int) Thread.join}
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   357
     * using this time unit.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * This is a convenience method that converts time arguments into the
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   359
     * form required by the {@code Thread.join} method.
7518
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   360
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @param thread the thread to wait for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @param timeout the maximum time to wait. If less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * or equal to zero, do not wait at all.
7518
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   364
     * @throws InterruptedException if interrupted while waiting
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    public void timedJoin(Thread thread, long timeout)
7518
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   367
            throws InterruptedException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        if (timeout > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            long ms = toMillis(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            int ns = excessNanos(timeout, ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            thread.join(ms, ns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /**
7518
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   376
     * Performs a {@link Thread#sleep(long, int) Thread.sleep} using
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   377
     * this time unit.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * This is a convenience method that converts time arguments into the
18768
f2638f396c41 8019481: Sync misc j.u.c classes from 166 to tl
psandoz
parents: 14325
diff changeset
   379
     * form required by the {@code Thread.sleep} method.
7518
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   380
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @param timeout the minimum time to sleep. If less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * or equal to zero, do not sleep at all.
7518
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   383
     * @throws InterruptedException if interrupted while sleeping
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    public void sleep(long timeout) throws InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (timeout > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            long ms = toMillis(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            int ns = excessNanos(timeout, ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            Thread.sleep(ms, ns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
}