Class CLITools


  • public class CLITools
    extends Object
    Tools for creating command line clients

    Created by Jeff Gaynor
    on Jun 25, 2010 at 2:15:40 PM

    • Constructor Detail

      • CLITools

        public CLITools()
    • Method Detail

      • prompt

        public static String prompt​(String prompt,
                                    Object defaultValue)
        A utility for getting user input. For command line clients. This display the first argument and encloses the second in parentheses. If the user enters a value that is returned, otherwise the second argument is.
        Parameters:
        prompt -
        defaultValue -
        Returns:
      • getOutputStream

        public static OutputStream getOutputStream()
      • setOutputStream

        public static void setOutputStream​(OutputStream outputStream)
      • getPrintWriter

        protected static PrintWriter getPrintWriter()
      • say

        public static void say​(String x)
      • say

        public static void say​(Object obj,
                               String x)
        Very useful for debugging. Supply the local "this" to get the name of the object plus the current time.
        Parameters:
        obj -
        x -
      • listChoose

        public static int listChoose​(String head,
                                     Object[] options)
        This displays the head then each of the list choices which are numbered. The user enters the choice which is converted to an integer then returned. This is perfect for switch statements, e.g. Each option displayed is just the toString method for the object.
        Parameters:
        head -
        options -
        Returns:
      • listChoose

        public static int listChoose​(String head,
                                     Object[] options,
                                     int defaultChoice)
      • listChoose

        public static int listChoose​(String head,
                                     List options,
                                     int defaultChoice)
        Convenience method to give a list of choices from a set of options.
        Parameters:
        head -
        options -
        Returns: