99 lines
2.8 KiB
Java
99 lines
2.8 KiB
Java
|
package fr.imirhil.april.hebdobot;
|
||
|
|
||
|
import java.util.HashSet;
|
||
|
import java.util.LinkedList;
|
||
|
import java.util.List;
|
||
|
import java.util.Set;
|
||
|
|
||
|
import org.apache.commons.lang.StringUtils;
|
||
|
|
||
|
public class Meeting {
|
||
|
private static final String SEPARATOR =
|
||
|
"========================================================================\n";
|
||
|
|
||
|
private final Set<String> participants = new HashSet<String>();
|
||
|
private final List<IndividualTopic> individualTopics =
|
||
|
new LinkedList<IndividualTopic>();
|
||
|
private final List<CollectiveTopic> collectiveTopics =
|
||
|
new LinkedList<CollectiveTopic>();
|
||
|
private final List<Message> messages = new LinkedList<Message>();
|
||
|
|
||
|
public void add(final Topic topic) {
|
||
|
if (topic instanceof IndividualTopic) {
|
||
|
this.individualTopics.add((IndividualTopic) topic);
|
||
|
} else if (topic instanceof CollectiveTopic) {
|
||
|
this.collectiveTopics.add((CollectiveTopic) topic);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void add(final Message message) {
|
||
|
this.messages.add(message);
|
||
|
this.participants.add(message.getAuthor());
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String toString() {
|
||
|
final StringBuffer buffer = new StringBuffer();
|
||
|
buffer.append(SEPARATOR);
|
||
|
buffer.append(getLine("Revue de la semaine en cours", ' '));
|
||
|
buffer.append(SEPARATOR);
|
||
|
buffer.append("\n\n");
|
||
|
buffer.append(SEPARATOR);
|
||
|
buffer.append("\n");
|
||
|
|
||
|
buffer.append(getLine("Participants", '-'));
|
||
|
for (final String participant : this.participants) {
|
||
|
buffer.append("* " + participant + "\n");
|
||
|
}
|
||
|
buffer.append("\n");
|
||
|
|
||
|
for (final String participant : this.participants) {
|
||
|
buffer.append(SEPARATOR + "\n");
|
||
|
buffer.append(getLine(participant, '-'));
|
||
|
buffer.append("\n");
|
||
|
|
||
|
for (final IndividualTopic topic : this.individualTopics) {
|
||
|
buffer.append(getTopic(topic));
|
||
|
buffer.append("\n");
|
||
|
for (final Message message : topic.getMessages(participant)) {
|
||
|
buffer.append("* " + message.getContent() + "\n");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
buffer.append("\n");
|
||
|
}
|
||
|
|
||
|
for (final CollectiveTopic topic : this.collectiveTopics) {
|
||
|
buffer.append("\n");
|
||
|
buffer.append(SEPARATOR);
|
||
|
buffer.append(getLine(topic.getTitle(), ' '));
|
||
|
buffer.append(SEPARATOR + "\n");
|
||
|
for (final Message message : topic.getMessages()) {
|
||
|
buffer.append("* " + message.getAuthor() + " : "
|
||
|
+ message.getContent() + "\n");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
buffer.append("\n");
|
||
|
buffer.append(SEPARATOR);
|
||
|
buffer.append(getLine("Log complet", ' '));
|
||
|
buffer.append(SEPARATOR + "\n");
|
||
|
|
||
|
for (final Message message : this.messages) {
|
||
|
buffer.append("* " + message.getAuthor() + " : "
|
||
|
+ message.getContent() + "\n");
|
||
|
}
|
||
|
|
||
|
return buffer.toString();
|
||
|
}
|
||
|
|
||
|
private static String getLine(final String content, final Character c) {
|
||
|
return StringUtils.center(" " + content + " ", SEPARATOR.length(), c)
|
||
|
+ "\n";
|
||
|
}
|
||
|
|
||
|
private static String getTopic(final Topic topic) {
|
||
|
return "=== " + topic.getTitle() + " ===";
|
||
|
}
|
||
|
}
|