Repository: commons-lang Updated Branches: refs/heads/master 421db380d -> 17a6d163c
Adding a createStarted() method per request in LANG-1138 Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/17a6d163 Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/17a6d163 Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/17a6d163 Branch: refs/heads/master Commit: 17a6d163c62d7bbfc9e19c11e0d52ae06b5160b1 Parents: 421db38 Author: Henri Yandell <bay...@apache.org> Authored: Sun Jul 19 09:23:45 2015 -0700 Committer: Henri Yandell <bay...@apache.org> Committed: Sun Jul 19 09:23:45 2015 -0700 ---------------------------------------------------------------------- .../org/apache/commons/lang3/time/StopWatch.java | 16 +++++++++++++++- .../apache/commons/lang3/time/StopWatchTest.java | 6 ++++++ 2 files changed, 21 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-lang/blob/17a6d163/src/main/java/org/apache/commons/lang3/time/StopWatch.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/lang3/time/StopWatch.java b/src/main/java/org/apache/commons/lang3/time/StopWatch.java index 239bc51..a5f53a3 100644 --- a/src/main/java/org/apache/commons/lang3/time/StopWatch.java +++ b/src/main/java/org/apache/commons/lang3/time/StopWatch.java @@ -23,7 +23,7 @@ package org.apache.commons.lang3.time; * </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> * <ul> * <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 { 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. http://git-wip-us.apache.org/repos/asf/commons-lang/blob/17a6d163/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java index f4ec347..80a4242 100644 --- a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java +++ b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java @@ -45,6 +45,12 @@ public class StopWatchTest { watch.reset(); assertEquals(0, watch.getTime()); } + + @Test + public void testStopWatchStatic() { + final StopWatch watch = StopWatch.createStarted(); + assertTrue(watch.isStarted()); + } @Test public void testStopWatchSimpleGet(){