From: Jérôme Benoit Date: Thu, 5 Apr 2018 14:11:44 +0000 (+0200) Subject: exo4: fix the class annotation to be included inside the bytecode. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=80eafbcb677fe79a952242b527492b8d9184d5e3;p=Project_POO.git exo4: fix the class annotation to be included inside the bytecode. Signed-off-by: Jérôme Benoit --- diff --git a/exo4/ClassPreamble.java b/exo4/ClassPreamble.java index 59c7fd9..523ea4f 100644 --- a/exo4/ClassPreamble.java +++ b/exo4/ClassPreamble.java @@ -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(); diff --git a/exo4/Main.java b/exo4/Main.java index 040c2e2..cd7afc5 100644 --- a/exo4/Main.java +++ b/exo4/Main.java @@ -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 index 0000000..080ba22 --- /dev/null +++ b/exo5/IStrComparator.java @@ -0,0 +1,14 @@ +import java.util.Comparator; + +class IStrComparator implements Comparator { + private String wordToCompare; + + IStrComparator(String w) { + wordToCompare = w; + } + + public int compare(String str1, String str2) { + return str1.compareTo(str2); + } + +} diff --git a/exo5/Main.java b/exo5/Main.java index 953bdfe..6a78029 100644 --- a/exo5/Main.java +++ b/exo5/Main.java @@ -10,6 +10,8 @@ class Main { * @param String[] args main() function arguments array */ public static void main(String[] args) { + //TreeMap tm = new TreeMap(new StrComparator()); + // default TreeMap comparator keep alphabetical order TreeMap tm = new TreeMap(); File f = new File("test_file.txt"); try { diff --git a/exo5/Makefile b/exo5/Makefile index b6e4a34..d928d62 100644 --- a/exo5/Makefile +++ b/exo5/Makefile @@ -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 index 0000000..b797083 --- /dev/null +++ b/exo5/StrComparator.java @@ -0,0 +1,9 @@ +import java.util.Comparator; + +class StrComparator implements Comparator { + + public int compare(String str1, String str2) { + return str1.compareTo(str2); + } + +}