javatools.administrative
Class Announce

java.lang.Object
  extended by javatools.administrative.Announce

public class Announce
extends java.lang.Object

This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). This class can make progress announcements. The announcements are handled by an object, but static methods exist to simplify the calls.
Example:

 Announce.doing("Testing 1");
 Announce.doing("Testing 2");
 Announce.message("Now testing", 3);
 Announce.warning(1,2,3);
 Announce.debug(1,2,3);
 Announce.doing("Testing 3a");
 Announce.doneDoing("Testing 3b");
 Announce.done();
 Announce.progressStart("Testing 3c",5); // 5 steps
 D.waitMS(1000);
 Announce.progressAt(1); // We're at 1 (of 5)
 D.waitMS(3000);
 Announce.progressAt(4); // We're at 4 (of 5)
 D.waitMS(1000);
 Announce.progressDone();
 Announce.done();
 Announce.done();
 Announce.done(); // This is one too much, but it works nevertheless
 -->
 Testing 1...
 Testing 2...
 Now testing 3
 Warning:1 2 3
 Announce.main(243): 1 2 3
 Testing 3a... done
 Testing 3b... done
 Testing 3c...........(4.00 s to go)................................ done (5.00 s)
 done
 done
 
The progress bar always walks to MAXDOTS dots. The data is written to Announce.out (by default System.err). There are different levels of announcements that can be switched on and off.


Nested Class Summary
static class Announce.Level
          Log level
 
Field Summary
static java.lang.String blanks
          Blanks
static int MAXDOTS
          Maximal number of dots
 
Constructor Summary
Announce()
           
 
Method Summary
static java.lang.String blanks(int n)
          Returns blanks
static void close()
          Closes the writer
static boolean debug(java.lang.Object... o)
          Prints a debug message with the class and method name preceeding
static void debugMsg(java.lang.Object... o)
          Prints a debug message
static void doing(java.lang.Object... o)
          Writes "s..." - intended for major states telling a user what the program does
static void doingDetailed(java.lang.Object... o)
          Writes "s..." - intended for more detailed states, in case the user wants to follow (nearly) every step of the program in detail
static void done()
          Writes "done NEWLINE" - closes a doing statement
static void done(java.lang.String text)
          Writes "done NEWLINE" - closes a doing statement
static void doneDetailed()
          Writes "done NEWLINE" - closes a doingDetailed statement
static void doneDoing(java.lang.Object... s)
          Calls done() and doing(...) - closes a doing statement opening the next one
static void doneWithProbs()
          Writes "done with problems NEWLINE" - closes a doing statement
static void error(java.lang.Exception e)
          Prints an exception and aborts by exiting (aborts even if log level is mute)
static void error(java.lang.Object... o)
          Prints an error message and aborts by exiting (aborts even if log level is mute)
static void errorException(java.lang.Exception e)
          Prints an exception and aborts by throwing a RuntimeException (aborts even if log level is mute)
static void errorException(java.lang.Object... o)
          Prints an error message and aborts by throwing a RuntimeException (aborts even if log level is mute)
static void errorException(java.lang.String message, java.lang.Exception cause)
          Prints an error message and aborts by throwing a RuntimeException (aborts even if log level is mute)
static void failed()
          Writes "failed NEWLINE"
static Announce.Level getActiveLevel()
          Provides the current announce level
static long getTime()
          Retrieves the time
static java.lang.Long getTime(int number)
          Retrieves the accumulated time the named timer has run for
static java.util.Vector<java.lang.Long> getTimers()
          Retrieves the accumulated time the named timer has run for
static java.io.Writer getWriter()
          Gets the writer the data is written to
static void help(java.lang.Object... o)
          Writes a help text and exits
static int initTimer()
          Initiates a numbered timer
static boolean isActiveLevel(Announce.Level l)
          Tells whether the given level is within the currently active levels
static boolean isHelp(java.lang.String arg)
          Says whether a command line argument asks for help
static void main(java.lang.String[] args)
          Test routine
static void message(java.lang.Object... o)
          Prints an (indented) message intended to provide additional information to the user at a top level
static void messageDetailed(java.lang.Object... o)
          Prints an (indented) message intended to provide more detailed information to a user who is interested in the details of every program step
static void printTime()
          Retrieves the time
static void printTime(int timerNumber)
          Prints the time of a particular timer given by its timer number
static void printTime(java.lang.String name, int timerNumber)
          Prints the time of a particular timer given by its timer number, may be given a name for printout
static void progressAt(double d)
          Notes that the progress is at d, prints dots if necessary, calculates and displays the estimated time after 60sec of the progress then again after every 30min
static void progressAt(double d, Announce.Level lvl)
          Notes that the progress is at d, prints dots if necessary, calculates and displays the estimated time after 60sec of the progress then again after every 30min (takes only effect iff current Announce level >= the given lvl)
static void progressDone()
          Fills missing dots and writes "done NEWLINE"
static void progressDone(Announce.Level lvl)
          Fills missing dots and writes "done NEWLINE" (takes only effect iff current Announce level >= the given lvl)
static void progressFailed()
          Writes "failed NEWLINE"
static void progressShowTime()
          Shows remaining time
static void progressStart(java.lang.String s, double max)
          Writes s, prepares to make progress up to max
static void progressStart(java.lang.String s, double max, Announce.Level lvl)
          Writes s, prepares to make progress up to max (takes only effect iff current Announce level >= the given lvl)
static void progressStart(java.lang.String s, java.lang.String id, double max)
          Writes s, prepares to make progress up to max, remembers id as name for progress counter
static void progressStart(java.lang.String s, java.lang.String id, double max, Announce.Level lvl)
          Writes s, prepares to make progress up to max remembers id as name for progress counter (and prints it if necessary) (takes only effect iff current Announce level >= the given lvl)
static void progressStep()
          One progress step (use alternatively to progressAt)
static void progressStep(Announce.Level lvl)
          One progress step (use alternatively to progressAt) (takes only effect iff current Announce level >= the given lvl)
static long progressTimePassed()
          returns the time passed in the current tracked progress since its start
static void resetTimer(int number)
          Resets the named timer to 0
static void setDebugMode(boolean set)
          Switches debug prefix with method an code line on or off
static Announce.Level setLevel(Announce.Level l)
          Switches announcing on or off
static void setWriter(java.io.OutputStream s)
          Sets the writer the data is written to
static void setWriter(java.io.Writer w)
          Sets the writer the data is written to
static void startTimer()
          Starts the timer
static void startTimer(int number)
          Starts a named timer
static void stopTimer(int number)
          Stops a named timer
static void warning(java.lang.Object... o)
          Prints a warning
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAXDOTS

public static int MAXDOTS
Maximal number of dots


blanks

public static final java.lang.String blanks
Blanks

See Also:
Constant Field Values
Constructor Detail

Announce

public Announce()
Method Detail

startTimer

public static void startTimer()
Starts the timer


getTime

public static long getTime()
Retrieves the time


initTimer

public static int initTimer()
Initiates a numbered timer


startTimer

public static void startTimer(int number)
Starts a named timer


stopTimer

public static void stopTimer(int number)
Stops a named timer


getTime

public static java.lang.Long getTime(int number)
Retrieves the accumulated time the named timer has run for


getTimers

public static java.util.Vector<java.lang.Long> getTimers()
Retrieves the accumulated time the named timer has run for


resetTimer

public static void resetTimer(int number)
Resets the named timer to 0


printTime

public static void printTime(int timerNumber)
Prints the time of a particular timer given by its timer number


printTime

public static void printTime(java.lang.String name,
                             int timerNumber)
Prints the time of a particular timer given by its timer number, may be given a name for printout


close

public static void close()
                  throws java.io.IOException
Closes the writer

Throws:
java.io.IOException

setLevel

public static Announce.Level setLevel(Announce.Level l)
Switches announcing on or off


getActiveLevel

public static Announce.Level getActiveLevel()
Provides the current announce level


isActiveLevel

public static boolean isActiveLevel(Announce.Level l)
Tells whether the given level is within the currently active levels


setDebugMode

public static void setDebugMode(boolean set)
Switches debug prefix with method an code line on or off


blanks

public static java.lang.String blanks(int n)
Returns blanks


message

public static void message(java.lang.Object... o)
Prints an (indented) message intended to provide additional information to the user at a top level


messageDetailed

public static void messageDetailed(java.lang.Object... o)
Prints an (indented) message intended to provide more detailed information to a user who is interested in the details of every program step


debug

public static boolean debug(java.lang.Object... o)
Prints a debug message with the class and method name preceeding


debugMsg

public static void debugMsg(java.lang.Object... o)
Prints a debug message


error

public static void error(java.lang.Object... o)
Prints an error message and aborts by exiting (aborts even if log level is mute)


error

public static void error(java.lang.Exception e)
Prints an exception and aborts by exiting (aborts even if log level is mute)


errorException

public static void errorException(java.lang.Object... o)
Prints an error message and aborts by throwing a RuntimeException (aborts even if log level is mute)


errorException

public static void errorException(java.lang.String message,
                                  java.lang.Exception cause)
Prints an error message and aborts by throwing a RuntimeException (aborts even if log level is mute)


errorException

public static void errorException(java.lang.Exception e)
Prints an exception and aborts by throwing a RuntimeException (aborts even if log level is mute)


warning

public static void warning(java.lang.Object... o)
Prints a warning


setWriter

public static void setWriter(java.io.Writer w)
Sets the writer the data is written to


getWriter

public static java.io.Writer getWriter()
Gets the writer the data is written to

Returns:

setWriter

public static void setWriter(java.io.OutputStream s)
Sets the writer the data is written to


doing

public static void doing(java.lang.Object... o)
Writes "s..." - intended for major states telling a user what the program does


doingDetailed

public static void doingDetailed(java.lang.Object... o)
Writes "s..." - intended for more detailed states, in case the user wants to follow (nearly) every step of the program in detail


failed

public static void failed()
Writes "failed NEWLINE"


doneDetailed

public static void doneDetailed()
Writes "done NEWLINE" - closes a doingDetailed statement


done

public static void done()
Writes "done NEWLINE" - closes a doing statement


done

public static void done(java.lang.String text)
Writes "done NEWLINE" - closes a doing statement


doneWithProbs

public static void doneWithProbs()
Writes "done with problems NEWLINE" - closes a doing statement


doneDoing

public static void doneDoing(java.lang.Object... s)
Calls done() and doing(...) - closes a doing statement opening the next one


progressStart

public static void progressStart(java.lang.String s,
                                 double max)
Writes s, prepares to make progress up to max


progressStart

public static void progressStart(java.lang.String s,
                                 double max,
                                 Announce.Level lvl)
Writes s, prepares to make progress up to max (takes only effect iff current Announce level >= the given lvl)


progressStart

public static void progressStart(java.lang.String s,
                                 java.lang.String id,
                                 double max)
Writes s, prepares to make progress up to max, remembers id as name for progress counter


progressStart

public static void progressStart(java.lang.String s,
                                 java.lang.String id,
                                 double max,
                                 Announce.Level lvl)
Writes s, prepares to make progress up to max remembers id as name for progress counter (and prints it if necessary) (takes only effect iff current Announce level >= the given lvl)


progressShowTime

public static void progressShowTime()
Shows remaining time


progressAt

public static void progressAt(double d,
                              Announce.Level lvl)
Notes that the progress is at d, prints dots if necessary, calculates and displays the estimated time after 60sec of the progress then again after every 30min (takes only effect iff current Announce level >= the given lvl)


progressAt

public static void progressAt(double d)
Notes that the progress is at d, prints dots if necessary, calculates and displays the estimated time after 60sec of the progress then again after every 30min


progressStep

public static void progressStep(Announce.Level lvl)
One progress step (use alternatively to progressAt) (takes only effect iff current Announce level >= the given lvl)


progressStep

public static void progressStep()
One progress step (use alternatively to progressAt)


progressDone

public static void progressDone(Announce.Level lvl)
Fills missing dots and writes "done NEWLINE" (takes only effect iff current Announce level >= the given lvl)


progressDone

public static void progressDone()
Fills missing dots and writes "done NEWLINE"


progressTimePassed

public static long progressTimePassed()
returns the time passed in the current tracked progress since its start


progressFailed

public static void progressFailed()
Writes "failed NEWLINE"


help

public static void help(java.lang.Object... o)
Writes a help text and exits


printTime

public static void printTime()
Retrieves the time


isHelp

public static boolean isHelp(java.lang.String arg)
Says whether a command line argument asks for help


main

public static void main(java.lang.String[] args)
Test routine