Add ThreadUtils.sleepQuietly(Duration)

Remove new ThreadUtils.sleepQuietly(long)
This commit is contained in:
Gary Gregory 2022-08-21 15:17:44 -04:00
parent e92dafdc3b
commit f8df864f4c
3 changed files with 10 additions and 10 deletions

View File

@ -110,7 +110,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="add" dev="ggregory" due-to="Gary Gregory">Add and use ArrayUtils.newInstance(Class&gt;T>, int).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add and use null-safe Streams.of(T...).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add ClassUtils.comparator().</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add and use ThreadUtils.sleepQuietly(long).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add and use ThreadUtils.sleepQuietly(Duration).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add and use ArrayUtils.setAll(T[], IntFunction).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add and use ArrayUtils.setAll(T[], Supplier).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add BooleanConsumer.</action>

View File

@ -554,17 +554,17 @@ public class ThreadUtils {
}
/**
* Sleeps for the given amount of milliseconds while ignoring {@link InterruptedException}.
* Sleeps for the given duration while ignoring {@link InterruptedException}.
* <p>
* The sleep duration may be shorter than {@code millis} if we catch a {@link InterruptedException}.
* The sleep duration may be shorter than duration if we catch a {@link InterruptedException}.
* </p>
*
* @param millis the length of time to sleep in milliseconds
* @param duration the length of time to sleep.
* @since 3.13.0
*/
public static void sleepQuietly(final long millis) {
public static void sleepQuietly(final Duration duration) {
try {
sleep(Duration.ofMillis(millis));
sleep(duration);
} catch (final InterruptedException e) {
// be quiet.
}

View File

@ -32,14 +32,14 @@ import org.apache.commons.lang3.reflect.FieldUtils;
import org.junit.jupiter.api.Test;
/**
* TestCase for StopWatch.
* Tests {@link StopWatch}.
*/
public class StopWatchTest extends AbstractLangTest {
private static final Duration MILLIS_200 = Duration.ofMillis(200);
private static final Duration MILLIS_550 = Duration.ofMillis(550);
private static final String MESSAGE = "Baking cookies";
private static final int MIN_SLEEP_MILLISECONDS = 20;
private static final Duration MIN_SLEEP = Duration.ofMillis(20);
private static final String ZERO_HOURS_PREFIX = "00:";
private static final String ZERO_TIME_ELAPSED = "00:00:00.000";
@ -144,7 +144,7 @@ public class StopWatchTest extends AbstractLangTest {
@Test
public void testFormatSplitTime() {
final StopWatch watch = StopWatch.createStarted();
ThreadUtils.sleepQuietly(MIN_SLEEP_MILLISECONDS);
ThreadUtils.sleepQuietly(MIN_SLEEP);
watch.split();
final String formatSplitTime = watch.formatSplitTime();
assertNotEquals(ZERO_TIME_ELAPSED, formatSplitTime);
@ -155,7 +155,7 @@ public class StopWatchTest extends AbstractLangTest {
public void testFormatSplitTimeWithMessage() {
final StopWatch watch = new StopWatch(MESSAGE);
watch.start();
ThreadUtils.sleepQuietly(MIN_SLEEP_MILLISECONDS);
ThreadUtils.sleepQuietly(MIN_SLEEP);
watch.split();
final String formatSplitTime = watch.formatSplitTime();
assertFalse(formatSplitTime.startsWith(MESSAGE), formatSplitTime);