Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2009-2011 Alexander Kerner. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 
 package net.sf.kerner.utils.time;

A stop watch to time a process.

Example:

 TODO example
 

Author(s):
Alexander Kerner
Version:
2011-08-02
 
 public class StopWatch {

An Exception to indicate that a StopWatch is already running and cannot be started.

Example:

 TODO example
 

Author(s):
Alexander Kerner
Version:
2011-08-02
 
 	public class AlreadyRunningException extends RuntimeException {
 
 		private static final long serialVersionUID = -8543832250156761882L;
 
 		}
 
 		public AlreadyRunningException(String arg0Throwable arg1) {
 			super(arg0arg1);
 		}
 
 		public AlreadyRunningException(String arg0) {
 			super(arg0);
 		}
 
 			super(arg0);
 		}
 
 	}

An Exception to indicate that a StopWatch is not running and cannot be stoped.

Example:

 TODO example
 

Author(s):
Alexander Kerner
Version:
2011-08-02
	public class NotRunningException extends RuntimeException {
		private static final long serialVersionUID = 2016104424322122373L;
		}
		public NotRunningException(String messageThrowable cause) {
			super(messagecause);
		}
		public NotRunningException(String message) {
			super(message);
		}
		public NotRunningException(Throwable cause) {
			super(cause);
		}
	}

	private long time = -1;

Start this StopWatch.

Throws:
StopWatch.AlreadyRunningException if this this StopWatch is already running
	public synchronized void start() throws AlreadyRunningException {
		if ( > 0)
		 = System.currentTimeMillis();
	}

Retrieve time that has passed since starting this StopWatch.

Returns:
time time that has passed since starting this StopWatch
Throws:
StopWatch.NotRunningException if this StopWatch is not running
	public synchronized TimePeriod round() throws NotRunningException {
		if ( < 0)
			throw new NotRunningException();
		return new TimePeriod(, System.currentTimeMillis());
	}

Stop this StopWatch.

Returns:
time that has passed since starting this StopWatch
Throws:
StopWatch.NotRunningException if this StopWatch is not running
	public synchronized TimePeriod stop() throws NotRunningException {
		final long result = ;
		if (result < 0)
			throw new NotRunningException();
		// reset
		 = -1;
		return new TimePeriod(result, System.currentTimeMillis());
	}
New to GrepCode? Check out our FAQ X