Adding a createStarted() method per request in LANG-1138

This commit is contained in:
Henri Yandell 2015-07-19 09:23:45 -07:00
parent 421db380d0
commit 17a6d163c6
2 changed files with 21 additions and 1 deletions

View File

@ -23,7 +23,7 @@ package org.apache.commons.lang3.time;
* </p> * </p>
* *
* <p> * <p>
* To start the watch, call {@link #start()}. At this point you can: * To start the watch, call {@link #start()} or {@link StopWatch.createStarted()}. At this point you can:
* </p> * </p>
* <ul> * <ul>
* <li>{@link #split()} the watch to get the time whilst the watch continues in the background. {@link #unsplit()} will * <li>{@link #split()} the watch to get the time whilst the watch continues in the background. {@link #unsplit()} will
@ -57,6 +57,20 @@ package org.apache.commons.lang3.time;
public class StopWatch { public class StopWatch {
private static final long NANO_2_MILLIS = 1000000L; private static final long NANO_2_MILLIS = 1000000L;
/**
* Provides a started stopwatch for convenience.
*
* @return StopWatch a stopwatch that's already been started.
*
* @since 3.5
*/
public static StopWatch createStarted() {
StopWatch sw = new StopWatch();
sw.start();
return sw;
}
/** /**
* Enumeration type which indicates the status of stopwatch. * Enumeration type which indicates the status of stopwatch.

View File

@ -45,6 +45,12 @@ public class StopWatchTest {
watch.reset(); watch.reset();
assertEquals(0, watch.getTime()); assertEquals(0, watch.getTime());
} }
@Test
public void testStopWatchStatic() {
final StopWatch watch = StopWatch.createStarted();
assertTrue(watch.isStarted());
}
@Test @Test
public void testStopWatchSimpleGet(){ public void testStopWatchSimpleGet(){