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