Class Messager


  • public class Messager
    extends java.lang.Object
    A replacement for System.out, System.err and even the StorageWriter class used to send error messages to the terminal about upgrade progress.

    This class is actually much less than meets the eye. All the Messager class really does is print output to a log / StorageWriter instance (this class inherits StorageWriter), while simultaneously keeping a count on the number of error messages that have been printed.

    The count allows this Tool's main-loops to ask if an error or warning has occured, thereby facilitating exiting the program more gracefully if an error has been printed. The primary value to a Messager over a simple exception throw is that multiple non-fatal errors can be printed before actually exiting the program. It is similar to the Java Compiler Messager - in that as many errors will be printed all at once, rather than expecting the user to receive just one error at a time between each attempt at compiling his code, thereby saving the programmer a significant amount of time! Collating a list of errors to the user about what has occured and report them all (at the end) is the primary feature of the messager.

    Recognizing that most of the classes in The Tool are not 'Helper Classes' at all, means that throwing an exception whenever a problem occurs is not really acceptable. Though several of the errors do involve printing an exception-message, and even its stack-trace, the messager forces the main method loops to take into consideration the end user's Java Virtual Machine, because halting the JVM with an exception throw is quite a bit more severe. Instead returning a null reply, and output explanatory error-text is quite a bit more reasonable.

    Essentially, anywhere this Messager's method's are used, try to envision that exact same error-message print being replaced with a throw new Exception..., and recognize that the surrounding loop body, instead, will continue iterating until too many errors have been logged, or the loop exits and the code attempts to move on to another section of the processing.

    Again, relying on Java's Exception Messages to report errors is a great way to signal a user mistke, but when an application is running, there has to be a more robust and advanced way of dealing with problems of user error, because wasint the user's time repairing one mistake at a time, and then re-running the Upgrader would be a very terrible waste of the end-user's time!


    • Field Summary

      Fields 
      Modifier and Type Field
      static String TNPE
    • Constructor Summary

      Constructors 
      Constructor
      Messager()
    • Field Detail

      • TNPE

        🡇    
        public static final java.lang.String TNPE
        Error Message for TypeNotPresentException
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
        public static final String TNPE = 
            "TypeNotPresentException thrown attempting to load Configuration Class.\n" +
            "Class requires correct Package-Name, options are:\n" +
            "    1) No Package-Name  2) Same Package-Name as the Package it's configuring";
        
    • Method Detail

      • isVerbose

        🡅  🡇    
        public static boolean isVerbose()
        Please review the Java code-body to understand what this does.
        Code:
        Exact Method Body:
         return VERBOSE_PRINT_STEPS;
        
      • print

        🡅  🡇    
        public static void print​(java.lang.String s)
        Prints input 's'
        Parameters:
        s - Any java.lang.String
        Code:
        Exact Method Body:
         sw.print(s);
        
      • println

        🡅  🡇    
        public static void println​(java.lang.String s)
        Prints input 's', followed by a newline.
        Parameters:
        s - Any java.lang.String
        Code:
        Exact Method Body:
         sw.println(s);
        
      • println

        🡅  🡇    
        public static void println()
        Prints a newline character
        Code:
        Exact Method Body:
         sw.println();
        
      • ifVPrintln

        🡅  🡇    
        public static void ifVPrintln​(java.lang.String s)
        This prints a message to the parent-class StorageWriter, but only if the user has requested Upgrade.VERBOSE_PRINT_STEPS

        MINOR NOTE: If the message being passed involves some complicated Java StringBuilder, it would be smarter & more efficient, to only build that message after the 'VERBOSE' flag has been checked. Essentially, using this method is silly, if 's' has a bunch of '+' symbols before it is passed here.
        Parameters:
        s - The message to print to StorageWriter (the Messager's parent class)
        Code:
        Exact Method Body:
         if (VERBOSE_PRINT_STEPS) sw.println(s);
        
      • ifVPrint

        🡅    
        public static void ifVPrint​(java.lang.String s)
        This prints a message to the parent-class StorageWriter, but only if the user has requested Upgrade.VERBOSE_PRINT_STEPS

        MINOR NOTE: If the message being passed involves some complicated Java StringBuilder, it would be smarter & more efficient, to only build that message after the 'VERBOSE' flag has been checked. Essentially, using this method is silly, if 's' has a bunch of '+' symbols before it is passed here.
        Parameters:
        s - The message to print to StorageWriter (the Messager's parent class)
        Code:
        Exact Method Body:
         if (VERBOSE_PRINT_STEPS) sw.print(s);