From fb7a0378b9ea3a11f28beec72fd2fbce063fda3c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 5 Apr 2018 16:45:49 +0200 Subject: [PATCH] exo5: add a SortedMap from the TreeMap. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- exo5/IStrComparator.java | 14 -------------- exo5/Main.java | 9 +++++++++ exo5/Makefile | 1 - 3 files changed, 9 insertions(+), 15 deletions(-) delete mode 100644 exo5/IStrComparator.java diff --git a/exo5/IStrComparator.java b/exo5/IStrComparator.java deleted file mode 100644 index 080ba22..0000000 --- a/exo5/IStrComparator.java +++ /dev/null @@ -1,14 +0,0 @@ -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 6a78029..1ec7512 100644 --- a/exo5/Main.java +++ b/exo5/Main.java @@ -2,6 +2,7 @@ import java.io.File; import java.util.Scanner; import java.io.IOException; import java.util.TreeMap; +import java.util.SortedMap; class Main { @@ -30,8 +31,16 @@ class Main { catch (IOException e) { e.printStackTrace(); } + + System.out.println("TreeMap full content:"); for (String wordCursor : tm.keySet()) { System.out.println("Word \"" + wordCursor + "\" occured " + tm.get(wordCursor) + " times"); } + + System.out.println("SortedMap content after the word \"milieu\":"); + SortedMap stm = tm.tailMap("milieu"); + for (String wordCursor : stm.keySet()) { + System.out.println("Word \"" + wordCursor + "\" occured " + stm.get(wordCursor) + " times"); + } } } diff --git a/exo5/Makefile b/exo5/Makefile index d928d62..57e5217 100644 --- a/exo5/Makefile +++ b/exo5/Makefile @@ -47,7 +47,6 @@ JVM = java CLASSES = \ StrComparator.java \ - IStrComparator.java \ Main.java # -- 2.34.1