Skip to content
Snippets Groups Projects
Commit 40a35972 authored by BAUER Oscar's avatar BAUER Oscar
Browse files

maybe figured out sorting thing in tp10

parent 51f38dde
No related branches found
No related tags found
No related merge requests found
...@@ -42,26 +42,18 @@ public class WordsManager { ...@@ -42,26 +42,18 @@ public class WordsManager {
List<String> list = new ArrayList<>(this.uniqueWords); List<String> list = new ArrayList<>(this.uniqueWords);
String[] list2 = new String[list.size()]; String[] list2 = new String[list.size()];
int pos = 0; int pos = 0;
for (String word : list) { StringComparator comp = new StringComparator();
for (int idx = 0; idx < list.size(); idx++) { list.sort(comp);
if(list.indexOf(word) == idx) { for (String word : list) {
pos += word.compareTo(list.get(idx)); System.out.println(word + " : " + wordOccurrences.get(word));
}
}
} }
System.out.println(list);
System.out.println("pos: "+pos);
// Collections.sort(list);
//
// for (String word : list) {
// System.out.println(word + " : " + wordOccurrences.get(word));
// }
} }
void displayWordOccurrencesByCount() { void displayWordOccurrencesByCount() {
List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(); List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>();
StringComparator comp = new StringComparator(); ComparatorMapEntry comp = new ComparatorMapEntry();
list.sort(comp);
for (int idx = 0; idx < list.size(); idx++) { for (int idx = 0; idx < list.size(); idx++) {
} }
......
package tp11.exo1; package tp11.exo1;
import java.util.HashSet;
import java.util.Set;
public class Message { public class Message {
private final User author;
private final String title;
private final String content;
private final Set<User> likers;
public Message(User author, String title, String content) {
this.author = author;
this.title = title;
this.content = content;
this.likers = new HashSet<User>();
}
public void receiveLike(User liker) {
likers.add(liker);
}
@Override
public String toString() {
return "[" + this.author.getName() + "][" + this.title + "][" + this.content + "]";
}
public void display() {
System.out.println(title);
System.out.println("par : " + author.getName());
System.out.println(content);
System.out.println("Aimé par : " + likers + "\n");
}
} }
package tp11.exo1;
public class TestMessage {
public static void main(String[] args) {
User user1 = new User("Alice");
User user2 = new User("Bob");
User user3 = new User("Carol");
Message msg1 = new Message(user1, "Mon second message", "Je vous aime.");
msg1.receiveLike(user2);
msg1.receiveLike(user3);
Message msg2 = new Message(user1, "Test", "Test Test");
Message msg3 = new Message(user1, " propos de Bob.", "Quel boulet celui - l.");
msg3.receiveLike(user3);
System.out.println(msg1);
System.out.println(msg2);
System.out.println(msg3);
msg1.display();
msg2.display();
msg3.display();
}
}
package tp11.exo1;
public class TestUser {
public static void main(String[] args) {
User user1 = new User("hans");
User user2 = new User("peter");
User user3 = new User("ernst");
user1.addMessage("testtest");
System.out.println(user1);
System.out.println(user2);
System.out.println(user3);
}
}
package tp11.exo1; package tp11.exo1;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.TreeSet;
public class User { public class User {
private String name; private final String name;
private List<String> messages; private final List<Message> messages;
private Set<User> followers; private final Set<User> followers;
public User(String name) { public User(String name) {
this.name = name; this.name = name;
this.messages = new ArrayList<String>(); this.messages = new ArrayList<Message>();
this.followers = new this.followers = new HashSet<User>();
System.out.println("Cration de l'utilisateur " + this.name);
}
public String getName() {
return this.name;
}
public void receive(Message message) {
messages.add(message);
}
public void broadcast(Message message) {
for (User usr : followers) {
usr.receive(message);
}
}
public void follow(User other) {
System.out.println(other + " s'abonne la liste de Alice." + this.name);
}
public Message getLastPost() {
return messages.get(messages.lastIndexOf(messages));
}
@Override
public String toString() {
// TODO Auto-generated method stub
return this.name;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment