Package Torello.Java

Class Q


  • public class Q
    extends java.lang.Object
    Q (User-Input) - Documentation.

    The letter Q refers to Questions - as in Shell input questions. The intention is to add a few "pre-written" yes/no or accept/reject methods, just like some of the provided Window-Event Questions in JavaScript.

    Static (Functional) API: The methods in this class are all (100%) defined with the Java Key-Word / Key-Concept 'static'. Furthermore, there is no way to obtain an instance of this class, because there are no public (nor private) constructors. Java's Spring-Boot, MVC feature is *not* utilized because it flies directly in the face of the light-weight data-classes philosophy. This has many advantages over the rather ornate Component Annotations (@Component, @Service, @AutoWired, etc... 'Java Beans') syntax:

    • The methods here use the key-word 'static' which means (by implication) that there is no internal-state. Without any 'internal state' there is no need for constructors in the first place! (This is often the complaint by MVC Programmers).
    • A 'Static' (Functional-Programming) API expects to use fewer data-classes, and light-weight data-classes, making it easier to understand and to program.
    • The Vectorized HTML data-model allows more user-control over HTML parse, search, update & scrape. Also, memory management, memory leakage, and the Java Garbage Collector ought to be intelligible through the 'reuse' of the standard JDK class Vector for storing HTML Web-Page data.

    The power that object-oriented programming extends to a user is (mostly) limited to data-representation. Thinking of "Services" as "Objects" (Spring-MVC, 'Java Beans') is somewhat 'over-applying' the Object Oriented Programming Model. Like most classes in the Java-HTML JAR Library, this class backtracks to a more C-Styled Functional Programming Model (no Objects) - by re-using (quite profusely) the key-word static with all of its methods, and by sticking to Java's well-understood class Vector

    Internal-State: A user may click on this class' source code (see link below) to view any and all internally defined fields class. A cursory inspection of the code would prove that this class has precisely zero internally defined global fields (Spaghetti). All variables used by the methods in this class are local fields only, and therefore this class ought to be though of as 'state-less'.



    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method
      static int intNUM()
      static String readLine()
      static boolean YN​(String yesOrNoQuestion)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • YN

        public static boolean YN​(java.lang.String yesOrNoQuestion)
        java.util.Scanner is not the most memorable class, but still, pretty useful. This static method will repeatedly prompt the user using System.out until a 'y' or an 'n' has been pressed.
        Parameters:
        yesOrNoQuestion - This is output to the prompt each time the user fails to enter 'y' or 'n'.
        Returns:
        TRUE if the user pushed 'y' on a single input line, and FALSE if the user has pushed 'n' on a single input line. The question asked will be repeated if neither of those has occurred.
        Code:
        Exact Method Body:
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
        11
        12
         Scanner input = new Scanner(System.in);
        
         while (true)
         {
             System.out.println(yesOrNoQuestion);
             System.out.println("Please type the letter 'y' or the letter 'n' and [ENTER]");
        
             String yesOrNo = input.nextLine();
        
             if (yesOrNo.toLowerCase().equals("y")) return true;
             if (yesOrNo.toLowerCase().equals("n")) return false;
         }
        
      • intNUM

        public static int intNUM()
        This will query a user for a valid input integer. If the user fails to enter a valid integer, and the Integer.parseInt(user-input); throws an exception, the method will ask the user repeatedly until a valid integer has been provided.
        Returns:
        The integer version of the user's input.
        Code:
        Exact Method Body:
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
        11
        12
        13
         Scanner input = new Scanner(System.in);
        
         while (true)
         {
             System.out.println("Please enter any valid integer, and then press [ENTER]");
        
             String s = input.nextLine();
        
             try
                 { int n = Integer.parseInt(s); return n; }
             catch (Exception e)
                 { System.out.println("That was not a valid integer, try again."); }
         }
        
      • readLine

        public static java.lang.String readLine()
        Reads a single line of user input, and returns that line as a string.
        Returns:
        return (new Scanner(System.in)).nextLine();
        Code:
        Exact Method Body:
        1
         return (new Scanner(System.in)).nextLine();