| Index: corelib/src/implementation/stopwatch_implementation.dart
|
| ===================================================================
|
| --- corelib/src/implementation/stopwatch_implementation.dart (revision 1504)
|
| +++ corelib/src/implementation/stopwatch_implementation.dart (working copy)
|
| @@ -3,17 +3,20 @@
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| /**
|
| - * A simple implementation of the [StopWatch] interface.
|
| + * A simple implementation of the [Stopwatch] interface.
|
| */
|
| -class StopWatchImplementation implements StopWatch {
|
| +class StopwatchImplementation implements Stopwatch {
|
| // The _start and _stop fields capture the time when [start] and [stop]
|
| // are called respectively.
|
| - // If _start is null, then the [StopWatch] has not been started yet.
|
| - // If _stop is null, then the [StopWatch] has not been stopped yet.
|
| + // If _start is null, then the [Stopwatch] has not been started yet.
|
| + // If _stop is null, then the [Stopwatch] has not been stopped yet.
|
| int _start;
|
| int _stop;
|
|
|
| - StopWatchImplementation() : _start = null, _stop = null {}
|
| + StopwatchImplementation() : _start = null, _stop = null {}
|
| + StopwatchImplementation.start() : _start = null, _stop = null {
|
| + start();
|
| + }
|
|
|
| void start() {
|
| if (_start === null) {
|
| @@ -36,6 +39,18 @@
|
| _stop = Clock.now();
|
| }
|
|
|
| + void reset() {
|
| + if (_start === null) return;
|
| + // If [_start] is not null, then the stopwatch had already been started. It
|
| + // may running right now.
|
| + _start = Clock.now();
|
| + if (_stop !== null) {
|
| + // The watch is not running. So simply set the [_stop] to [_start] thus
|
| + // having an elapsed time of 0.
|
| + _stop = _start;
|
| + }
|
| + }
|
| +
|
| int elapsed() {
|
| if (_start === null) {
|
| return 0;
|
|
|