From 80eafbcb677fe79a952242b527492b8d9184d5e3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 5 Apr 2018 16:11:44 +0200 Subject: [PATCH] exo4: fix the class annotation to be included inside the bytecode. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- exo4/ClassPreamble.java | 3 +++ exo4/Main.java | 6 +++--- exo5/IStrComparator.java | 14 ++++++++++++++ exo5/Main.java | 2 ++ exo5/Makefile | 2 ++ exo5/StrComparator.java | 9 +++++++++ 6 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 exo5/IStrComparator.java create mode 100644 exo5/StrComparator.java 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); + } + +} -- 2.34.1