From: Jérôme Benoit Date: Thu, 5 Apr 2018 14:45:49 +0000 (+0200) Subject: exo5: add a SortedMap from the TreeMap. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=fb7a0378b9ea3a11f28beec72fd2fbce063fda3c;p=Project_POO.git exo5: add a SortedMap from the TreeMap. Signed-off-by: Jérôme Benoit --- 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 #