exo4: fix the class annotation to be included inside the bytecode.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 5 Apr 2018 14:11:44 +0000 (16:11 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 5 Apr 2018 14:11:44 +0000 (16:11 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
exo4/ClassPreamble.java
exo4/Main.java
exo5/IStrComparator.java [new file with mode: 0644]
exo5/Main.java
exo5/Makefile
exo5/StrComparator.java [new file with mode: 0644]

index 59c7fd96c7730b15fd7a5922b2932f5162458f34..523ea4f08cc270ddf9652a8a545a5086256fdc37 100644 (file)
@@ -1,5 +1,8 @@
 import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
 
+@Retention(RetentionPolicy.RUNTIME)
 @Documented
 public @interface ClassPreamble {
    String author();
index 040c2e2e356b8f755a5e3f723c0c8ffe7b5ec19d..cd7afc54357296ac0655a09dfc6c2bdc843532cc 100644 (file)
@@ -22,11 +22,11 @@ class Main {
 
         for (Class<?> cl : packageClasses) {
             ClassPreamble classPreamble = cl.getAnnotation(ClassPreamble.class);
-            if (classPreamble == null)
+            if (classPreamble == null) {
                 System.out.println("No annotation for " + cl.getName());
                 continue;
-
-            //System.out.println("Annotation date = " + classPreamble.date());
+            }
+            System.out.println(cl.getName() + " class annotation date = " + classPreamble.date());
         }
     }
 }
diff --git a/exo5/IStrComparator.java b/exo5/IStrComparator.java
new file mode 100644 (file)
index 0000000..080ba22
--- /dev/null
@@ -0,0 +1,14 @@
+import java.util.Comparator;
+
+class IStrComparator implements Comparator<String> {
+    private String wordToCompare;
+
+    IStrComparator(String w) {
+        wordToCompare = w;
+    }
+
+    public int compare(String str1, String str2) {
+        return str1.compareTo(str2);
+    }
+
+}
index 953bdfe46f61bf06b962e85745c9feeacae93d06..6a780291e35fc7025c3e84ef8410156c76d116d8 100644 (file)
@@ -10,6 +10,8 @@ class Main {
      * @param String[] args main() function arguments array
      */
     public static void main(String[] args) {
+        //TreeMap<String, Integer> tm = new TreeMap<String, Integer>(new StrComparator());
+        // default TreeMap comparator keep alphabetical order
         TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
         File f = new File("test_file.txt");
         try {
index b6e4a343dad9d00ba92b69f64df514da632242fc..d928d62148d9d2391a1ce1198239b9c88c5d18e6 100644 (file)
@@ -46,6 +46,8 @@ JVM = java
 # NAME = Camilo        Juan
 
 CLASSES = \
+               StrComparator.java \
+               IStrComparator.java \
                Main.java
 
 #
diff --git a/exo5/StrComparator.java b/exo5/StrComparator.java
new file mode 100644 (file)
index 0000000..b797083
--- /dev/null
@@ -0,0 +1,9 @@
+import java.util.Comparator;
+
+class StrComparator implements Comparator<String> {
+
+    public int compare(String str1, String str2) {
+        return str1.compareTo(str2);
+    }
+
+}