us.zuercher.gpx2map.util
Class PrintStreamProgressMeter

java.lang.Object
  extended by us.zuercher.gpx2map.util.PrintStreamProgressMeter
All Implemented Interfaces:
ProgressMeter

public class PrintStreamProgressMeter
extends Object
implements ProgressMeter

PrintStreamProgressMeter implements ProgressMeter to write progress information to a given PrintStream. PrintStreamProgressMeter prints a single period for each percent of completion until it reaches a percentage that is an even multiple of 10%, at which point it outputs the percentage. At 50%, it starts a new line.

Author:
Stephan Zuercher

Field Summary
private static String BIG_INDENT
          Double indent, used when taskName is not null.
private  int count
          Task completion point.
private  boolean firstUpdate
          True until the completion of the first progress update, even if that update does not cause any output of percentage markers.
private static String INDENT
          Basic indent, used when taskName is null.
private  int lastPercent
          Percentage completed as of last update.
private  PrintStream out
          The output PrintStream.
private  String taskName
          The current task name.
 
Constructor Summary
PrintStreamProgressMeter(String name, PrintStream out)
          Constructs a new PrintStreamProgressMeter with the given name and using the given PrintStream for output.
 
Method Summary
 void reset()
          Resets the progress meter for a new task name.
 void setCount(int count)
          Sets the number of work items for this progress meter.
 void setTaskName(String taskName)
          Configures a task name.
 void updateProgress(int count)
          Updates the progress meter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INDENT

private static final String INDENT
Basic indent, used when taskName is null.

See Also:
Constant Field Values

BIG_INDENT

private static final String BIG_INDENT
Double indent, used when taskName is not null.

See Also:
Constant Field Values

out

private final PrintStream out
The output PrintStream.


taskName

private String taskName
The current task name. If null, task name is not used.


firstUpdate

private boolean firstUpdate
True until the completion of the first progress update, even if that update does not cause any output of percentage markers.


count

private int count
Task completion point.


lastPercent

private int lastPercent
Percentage completed as of last update.

Constructor Detail

PrintStreamProgressMeter

public PrintStreamProgressMeter(String name,
                                PrintStream out)
Constructs a new PrintStreamProgressMeter with the given name and using the given PrintStream for output.

Parameters:
name - overall name -- not a task name
out - the output PrintStream
Method Detail

setTaskName

public void setTaskName(String taskName)
Configures a task name.

Specified by:
setTaskName in interface ProgressMeter
Parameters:
taskName - the name of the current task within this progress meter.
Throws:
IllegalStateException - if the count has already been set.
See Also:
ProgressMeter.setTaskName(String)

setCount

public void setCount(int count)
Sets the number of work items for this progress meter.

Specified by:
setCount in interface ProgressMeter
Parameters:
count - the number of work items
See Also:
ProgressMeter.setCount(int)

reset

public void reset()
Resets the progress meter for a new task name.

Specified by:
reset in interface ProgressMeter
See Also:
ProgressMeter.reset()

updateProgress

public void updateProgress(int count)
Updates the progress meter.

Specified by:
updateProgress in interface ProgressMeter
Parameters:
count - the number of work items completed
See Also:
ProgressMeter.updateProgress(int)