/**
 * Steven Ward
 * WardDomainName.java | Domain Name Project
 *
 * A program to demonstrate the DomainName class.
 * This program is intended to test and demonstrate the 'DomainName' class (defined in
 * 'DomainName.java'). It first prompts the user to enter a "domain name". Once the input received
 * from the user is considered "valid", it is used to construct an instance of the 'DomainName'
 * class. This instance is then used to call the 'hasPrefix', 'extension' and 'name' member
 * functions, which subsequently have their respective return values output in a human-readable
 * format.
 *
 * @see #main(String[] args)
 * @see DomainName#DomainName(String)
 * @see DomainName#hasPrefix
 * @see DomainName#extension
 * @see DomainName#name
 */

import javax.swing.JOptionPane;  /** Allows use of unqualified 'JOptionPane' class name. */

public class WardDomainName {

  /**
   * Method to validate a "domain name" string.
   * This is a utility method that takes the domain name String entered by the user and returns
   * a boolean value: 'true' if the domain name is "valid"; otherwise, 'false'. The predicates used
   * to determine validity are, 1) that the domain name String is not empty, and 2) that the domain
   * name matches a regular expression specifying the general format of a "valid" domain name, which
   * is case-insensitive and defined as:
   *   {optional "www."} + {sequence of letters/numbers} + "." + {sequence of exactly 3 letters}
   *
   * @param input  The domain name entered by the user, which is to be validated.
   * @return       A boolean reflecting the "validity" of the domain name argument.
   *
   * @see java.lang.String
   * @see java.lang.String#matches(String)
   * @see java.util.regex.Pattern
   */
  private static boolean isValidDomain(String input) {

    /**
     * Regular expression for a "valid" domain name.
     * Defines the pattern (described above method header) used by this method to validate a domain
     * name String. A brief overview of the tokens used follows:
     *
     *     Regex Token                          Meaning/Matches
     *    -------------                        -----------------
     *         \\           equivalent to a single backslash in the pattern - '\' is escaped ('\\').
     *        (?i)          makes the regular expression that follows case-insensitive.
     *          ^           matches the beginning of a String (so optional "www." must be at start).
     *      (www\.)?        matches ONE or NO occurrences of "www." - '.' is escaped ('\.').
     *         \w+          matches ONE or MANY "word" characters ('\w' - alphanumeric & underscore).
     *         \.           matches EXACTLY ONE literal '.' character.
     *     [a-zA-Z]{3}      matches a sequence of EXACTLY THREE upper or lowercase letters.
     *          $           matches the end of a String (no match if there are excess characters).
     */
    String domainRegex = "(?i)^(www\\.)?\\w+\\.[a-zA-Z]{3}$";

    /*
     * Return 'true' IFF the String, 'input', matches the regular expression defined in
     * 'domainRegex' (also implicitly checks that 'input' is non-empty).
     */
    return input.matches(domainRegex);
  }


  public static void main(String[] args) {

    String domainIn = JOptionPane.showInputDialog(frame, "A domain name is the \"core\" address of a website.\n"
        + "Here is an example:  'www.facebook.com'\n"
        + "Please enter a domain name of your choice, with or without the leading 'www.':");

    while (!isValidDomain(domainIn)) {
      JOptionPane.showMessageDialog(frame,
          "A valid domain name must contain:\n"
          + " 1. An optional \"www.\" at the start of the domain name\n"
          + " 2. A sequence of characters containing ONLY letters, digits and underscores ('_')\n"
          + " 3. A dot ('.') followed by EXACTLY THREE letters, which must be the last characters\n"
          + " 4. No \"whitespace\" characters (space, tab, <Enter>, etc.)", "Invalid Domain Name",
          JOptionPane.WARNING_MESSAGE);

      domainIn = JOptionPane.showInputDialog(frame, "Please enter a valid domain name:");
    }

    //! TODO:
    //!     - initialize an instance of 'DomainName' class
    //!     - output values returned from 'hasPrefix', 'extension' and 'name' methods
    //!     - end program execution
    //!     - DOCUMENTATION
  }
}

@@ -3244,24 +3244,91 @@
 %5B%5D args) %7B%0A%0A
+    // Prompt the user to enter a domain name of his/her choosing.%0A
     String d
@@ -3365,21 +3365,20 @@
 tDialog(
-frame
+null
 , %22A dom
@@ -3571,24 +3571,122 @@
 'www.':%22);%0A%0A
+    // Using the 'isValidDomain' function, loop until the program recieves a %22valid%22 domain name.%0A
     while (!
@@ -3748,21 +3748,20 @@
 eDialog(
-frame
+null
 ,%0A      
@@ -4264,13 +4264,12 @@
 log(
-frame
+null
 , %22P
@@ -4321,116 +4321,197 @@
   //
-! TODO:%0A    //!     - initialize an instance of 'DomainName' class%0A    //!     - output values returned from
+ Instantiate a 'DomainName' object and initialize it with the 'DomainName(String )' constructor.%0A    DomainName userDomain = new DomainName(domainIn);%0A%0A    // Demonstrate proper function of
  'ha
@@ -4509,32 +4509,34 @@
 on of 'hasPrefix
+()
 ', 'extension' a
@@ -4524,32 +4524,34 @@
 x()', 'extension
+()
 ' and 'name' met
@@ -4549,84 +4549,347 @@
 name
+()
 ' me
-thods
+mbers.%0A    JOptionPane.showMessageDialog(null, %22Your Domain: %22 + userDomain.getDomain() + %22%5Cn%22
 %0A    
-//!
     
- - end program execution
++ %22Prefix: %22 + (userDomain.hasPrefix() ? %22contains %5C%22www.%5C%22%5Cn%22 : %22does not contain %5C%22www.%5C%22%5Cn%22)%0A        + %22Extension: %22 + userDomain.extension() + %22%5Cn%22
 %0A    
-//!
     
- - DOCUMENTATION%0A  %7D
++ %22Name: %22 + userDomain.name() );%0A  %7D%0A  // Terminate program execution.
 %0A%7D%0A

Update 'WardDomainName' program to almost-complete version (has a bug).