Change review format

This commit is contained in:
Nicolas VINOT 2011-11-05 15:19:12 +01:00
parent b1f61e7e86
commit 4fe7de5d38

View File

@ -6,6 +6,8 @@ import java.util.List;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import fr.imirhil.april.hebdobot.xml.UserAlias;
@ -60,59 +62,60 @@ public class Review {
public String toString(final UserAlias userService) {
final StringBuffer buffer = new StringBuffer();
addBox(buffer, "Revue de la semaine en cours", '#');
buffer.append("\n");
addLine(buffer, '=');
addCenter(buffer, "Revue de la semaine en cours");
addEmpty(buffer);
addCenter(buffer, DateTimeFormat.fullDate().print(new DateTime()));
addLine(buffer, '=');
addEmpty(buffer);
addEmpty(buffer);
buffer.append("\n");
addBox(buffer, "Participants", '=');
buffer.append("\n");
addLine(buffer, '=');
addEmpty(buffer);
addCenter(buffer, "Participants", '-');
for (final String participant : this.participants) {
chunkAndAppend(buffer, "* " + userService.getRealName(participant)
+ "\n");
addChunk(buffer, "* " + userService.getRealName(participant) + "\n");
}
buffer.append("\n");
if (!this.individualTopics.isEmpty()) {
buffer.append("\n");
addBox(buffer, "Sujets individuels", '=');
for (final String participant : this.participants) {
buffer.append("\n");
buffer.append(getLine(userService.getRealName(participant), '-'));
addEmpty(buffer);
addLine(buffer, '=');
addEmpty(buffer);
addCenter(buffer, userService.getRealName(participant), '-');
for (final IndividualTopic topic : this.individualTopics) {
if (topic.hasParticipant(participant)) {
buffer.append("\n");
chunkAndAppend(buffer, getTopic(topic));
buffer.append("\n");
addEmpty(buffer);
add(buffer, getTopic(topic));
addEmpty(buffer);
for (final Message message : topic
.getMessages(participant)) {
chunkAndAppend(buffer, "* " + message.getContent()
+ "\n");
addChunk(buffer, "* " + message.getContent() + "\n");
}
}
}
}
buffer.append("\n");
}
if (!this.collectiveTopics.isEmpty()) {
buffer.append("\n");
addBox(buffer, "Sujets collectifs", '=');
for (final CollectiveTopic topic : this.collectiveTopics) {
buffer.append("\n");
addBox(buffer, topic.getTitle(), '-');
addEmpty(buffer);
addLine(buffer, '=');
addCenter(buffer, topic.getTitle());
addLine(buffer, '=');
addEmpty(buffer);
for (final Message message : topic.getMessages()) {
chunkAndAppend(buffer, "* " + message.getAuthor() + " : "
addChunk(buffer, "* " + message.getAuthor() + " : "
+ message.getContent() + "\n");
}
}
buffer.append("\n");
}
buffer.append("\n");
addBox(buffer, "Log complet", '=');
buffer.append("\n");
addEmpty(buffer);
addCenter(buffer, "Log IRC brut");
addEmpty(buffer);
for (final Message message : this.messages) {
chunkAndAppend(buffer,
addChunk(buffer,
"* " + message.getAuthor() + " : " + message.getContent()
+ "\n");
}
@ -124,21 +127,32 @@ public class Review {
return StringUtils.repeat(c.toString(), LENGTH) + "\n";
}
private static String getLine(final String content, final Character c) {
private static String getLine(final String content, final char c) {
return StringUtils.center(" " + content + " ", LENGTH, c) + "\n";
}
private static String getTopic(final Topic topic) {
return "=== " + topic.getTitle() + " ===";
return "=== " + topic.getTitle() + " ===\n";
}
private static void addBox(final StringBuffer buffer, final String title,
final Character c) {
buffer.append(getLine(c));
buffer.append(getLine(title, ' '));
private static void addCenter(final StringBuffer buffer,
final String content, final char c) {
buffer.append(getLine(content, c));
}
private static void addCenter(final StringBuffer buffer,
final String content) {
addCenter(buffer, content, ' ');
}
private static void addLine(final StringBuffer buffer, final char c) {
buffer.append(getLine(c));
}
private static void addEmpty(final StringBuffer buffer) {
buffer.append("\n");
}
private static String chunk(final String content, final int length) {
final String[] words = content.split(" ");
final StringBuffer result = new StringBuffer();
@ -169,12 +183,17 @@ public class Review {
return result.toString();
}
private static void add(final StringBuffer buffer, final String content) {
buffer.append(content);
}
private static String chunk(final String content) {
return chunk(content, LENGTH);
}
private static void chunkAndAppend(final StringBuffer buffer,
final String content) {
buffer.append(chunk(content));
private static void
addChunk(final StringBuffer buffer, final String content) {
add(buffer, chunk(content));
}
}