package net.pizey.test.rdd;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;

public abstract class RequirementsVerifier {

  static HashMap<String, String> requirements = new HashMap<String, String>();
  static HashMap<String, ArrayList<String>> requirementTests = new HashMap<String, ArrayList<String>>();
  
  static void readAnnotation(Class<?> test) {
    System.out.println("Annotation element for " + test.getSimpleName());
    for (Method method : test.getMethods()) {
      if (method.isAnnotationPresent(Requirements.class)) {
        System.out.println(method.getName());
        // getAnnotation returns Annotation type
        Annotation singleAnnotation = method.getAnnotation(Requirements.class);
        Requirements requirementRefs = (Requirements) singleAnnotation;

        for (String id : requirementRefs.ids()){
          System.out.println(" " + id + ", " + requirements.get(id));
          requirementTests.get(id).add(test.getSimpleName() + "." + method.getName());
        }
        System.out.print("\n");
      }
    }
  }
  
  static void printRequirementVerificationMatrix() { 
    System.out.println("<html>");
    System.out.println("<body>");
    System.out.println("<h1>Requirements Verification Matrix</h1>");
    System.out.print("<h2>");
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Calendar cal = Calendar.getInstance();
    System.out.print(dateFormat.format(cal.getTime()));
    System.out.println("</h2>");
    
    for (String ref : requirements.keySet()){
      System.out.println("<h3>" + ref + " " + requirements.get(ref) + "</h3>");
      System.out.println("<ul>");
      for (String test : requirementTests.get(ref)){
        System.out.println(" <li>" + test + "</li>");
      }
      System.out.println("</ul>");
    }
    
    System.out.println("</body>");
    System.out.println("</html>");
  }

}

@@ -239,16 +239,70 @@
 HashMap;
+%0Aimport java.util.SortedMap;%0Aimport java.util.TreeMap;
 %0A%0Apublic
@@ -342,36 +342,38 @@
 ier %7B%0A%0A  static 
-Hash
+Sorted
 Map%3CString, Stri
@@ -387,36 +387,36 @@
 uirements = new 
-Hash
+Tree
 Map%3CString, Stri
@@ -431,20 +431,22 @@
  static 
-Hash
+Sorted
 Map%3CStri
@@ -491,20 +491,20 @@
 s = new 
-Hash
+Tree
 Map%3CStri
@@ -1051,11 +1051,13 @@
 efs.
-ids
+value
 ())%7B
@@ -1864,24 +1864,54 @@
 ln(%22%3Cul%3E%22);%0A
+      boolean hadOne = false;%0A
       for (S
@@ -2007,25 +2007,138 @@
 i%3E%22);%0A      
-%7D
+  hadOne = true;%0A      %7D%0A      if (!hadOne)%0A        System.out.println(%22 %3Cli%3E%3Cfont color='red'%3ENone%3C/font%3E%3C/li%3E%22);
 %0A      Syste

Order requirements, flag in red if one is not addressed