FileDocCategorySizeDatePackage
ProcessEstimationExample.javaAPI DocExample2050Wed May 18 09:39:02 BST 2005com.discursive.jccook.math.timeestimate

ProcessEstimationExample

public class ProcessEstimationExample extends Object

Fields Summary
private ProcessEstimator
estimate
Constructors Summary
Methods Summary
public voidbegin()

		estimate = new ProcessEstimator( 10000, 100 );
		estimate.start();
		
		for( int i = 0; i < 10000; i++ ) {
			// Print status every 1000 items
			printStatus(i);
		
			performLengthyProcess();
			
			estimate.unitCompleted();
		}
		
		estimate.stop();
		
		System.out.println( "Completed " + estimate.getUnits() + " in " + 
									   Math.round( estimate.getTimeSpent() / 1000 ) + " seconds." );
	
public static voidmain(java.lang.String[] args)

		ProcessEstimationExample example = new ProcessEstimationExample();
		example.begin();
	
private voidperformLengthyProcess()

		try {
			Thread.sleep(RandomUtils.nextInt(10));
		} catch( Exception e ) {}
	
private voidprintStatus(int i)

		if( i % 1000 == 0 ) {
			System.out.println( "Completed: " + estimate.getCompleted() + " of " + estimate.getUnits() );
			
			System.out.println( "\tTime Spent: " + Math.round( estimate.getTimeSpent() / 1000) + " sec" +
											", Time Remaining: " + Math.round( estimate.projectedTimeRemaining() / 1000) + " sec" );
		}