Adding a createStarted() method per request in LANG-1138
This commit is contained in:
parent
421db380d0
commit
17a6d163c6
|
@ -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
|
||||||
|
@ -58,6 +58,20 @@ 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.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -46,6 +46,12 @@ public class StopWatchTest {
|
||||||
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(){
|
||||||
final StopWatch watch = new StopWatch();
|
final StopWatch watch = new StopWatch();
|
||||||
|
|
Loading…
Reference in New Issue