|
10 | 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
11 | 11 | * specific language governing permissions and limitations under the License.
|
12 | 12 | */
|
13 |
| - |
14 | 13 | package com.ibm.watson.developer_cloud.util;
|
15 | 14 |
|
16 | 15 | import java.util.concurrent.TimeUnit;
|
|
21 | 20 | */
|
22 | 21 |
|
23 | 22 | public class WaitFor {
|
24 |
| - /** |
25 |
| - * Static method used to wait for a specific condition to be satisfied. |
26 |
| - * |
27 |
| - * @param condition |
28 |
| - * The condition to check |
29 |
| - * @param time |
30 |
| - * The maximum time to wait for the condition to become true |
31 |
| - * @param unit |
32 |
| - * The time unit of the {@code time} argument |
33 |
| - * @param sleepMs |
34 |
| - * The time to wait between checks |
35 |
| - * |
36 |
| - * @return true if the condition was true before the timeout, false if it wasn't. |
37 |
| - */ |
38 |
| - public static boolean waitFor(Condition condition, long time, TimeUnit unit, long sleepMs) { |
39 |
| - long waitMs = unit.toMillis(time); |
40 |
| - long startMs = System.currentTimeMillis(); |
41 |
| - while (System.currentTimeMillis() - startMs < waitMs) { |
42 |
| - if (condition.isSatisfied()) { |
43 |
| - return true; |
44 |
| - } |
45 |
| - try { |
46 |
| - Thread.sleep(sleepMs); |
47 |
| - } catch (InterruptedException e) { |
48 |
| - throw new RuntimeException("WaitFor aborted", e); |
49 |
| - } |
50 |
| - } |
51 |
| - return false; |
| 23 | + |
| 24 | + private WaitFor() {} |
| 25 | + |
| 26 | + /** |
| 27 | + * Static method used to wait for a specific condition to be satisfied. |
| 28 | + * |
| 29 | + * @param condition The condition to check |
| 30 | + * @param time The maximum time to wait for the condition to become true |
| 31 | + * @param unit The time unit of the {@code time} argument |
| 32 | + * @param sleepMs The time to wait between checks |
| 33 | + * |
| 34 | + * @return true if the condition was true before the timeout, false if it wasn't. |
| 35 | + */ |
| 36 | + public static boolean waitFor(Condition condition, long time, TimeUnit unit, long sleepMs) { |
| 37 | + long waitMs = unit.toMillis(time); |
| 38 | + long startMs = System.currentTimeMillis(); |
| 39 | + while (System.currentTimeMillis() - startMs < waitMs) { |
| 40 | + if (condition.isSatisfied()) { |
| 41 | + return true; |
| 42 | + } |
| 43 | + try { |
| 44 | + Thread.sleep(sleepMs); |
| 45 | + } catch (InterruptedException e) { |
| 46 | + throw new RuntimeException("WaitFor aborted", e); |
| 47 | + } |
52 | 48 | }
|
| 49 | + return false; |
| 50 | + } |
53 | 51 |
|
| 52 | + /** |
| 53 | + * The Interface Condition. |
| 54 | + */ |
| 55 | + public interface Condition { |
54 | 56 | /**
|
55 |
| - * The Interface Condition. |
| 57 | + * @return true/false indicating whether or not the condition has been met. |
56 | 58 | */
|
57 |
| - public interface Condition { |
58 |
| - /** |
59 |
| - * @return true/false indicating whether or not the condition has been met. |
60 |
| - */ |
61 |
| - boolean isSatisfied(); |
62 |
| - } |
| 59 | + boolean isSatisfied(); |
| 60 | + } |
63 | 61 | }
|
0 commit comments