Chunk long line on review
This commit is contained in:
parent
940c6f44a3
commit
b1f61e7e86
7
.settings/org.eclipse.core.resources.prefs
Normal file
7
.settings/org.eclipse.core.resources.prefs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#Sun Oct 09 17:20:12 CEST 2011
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding//src/main/java=UTF8
|
||||||
|
encoding//src/main/resources=UTF8
|
||||||
|
encoding//src/test/java=UTF8
|
||||||
|
encoding//src/test/resources=UTF8
|
||||||
|
encoding/<project>=UTF8
|
3
pom.xml
3
pom.xml
@ -1,4 +1,5 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>fr.imirhil.april</groupId>
|
<groupId>fr.imirhil.april</groupId>
|
||||||
<artifactId>hebdobot</artifactId>
|
<artifactId>hebdobot</artifactId>
|
||||||
|
@ -4,8 +4,6 @@ import java.util.Collection;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import org.jibble.pircbot.PircBot;
|
import org.jibble.pircbot.PircBot;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import fr.imirhil.april.hebdobot.review.CollectiveTopic;
|
import fr.imirhil.april.hebdobot.review.CollectiveTopic;
|
||||||
import fr.imirhil.april.hebdobot.review.IndividualTopic;
|
import fr.imirhil.april.hebdobot.review.IndividualTopic;
|
||||||
@ -14,8 +12,6 @@ import fr.imirhil.april.hebdobot.review.Review;
|
|||||||
import fr.imirhil.april.hebdobot.review.Topic;
|
import fr.imirhil.april.hebdobot.review.Topic;
|
||||||
|
|
||||||
public class Bot extends PircBot {
|
public class Bot extends PircBot {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(Bot.class);
|
|
||||||
|
|
||||||
private Review review = null;
|
private Review review = null;
|
||||||
private final String channel;
|
private final String channel;
|
||||||
private final Collection<ReviewListener> listeners =
|
private final Collection<ReviewListener> listeners =
|
||||||
|
@ -10,7 +10,7 @@ import org.apache.commons.lang.StringUtils;
|
|||||||
import fr.imirhil.april.hebdobot.xml.UserAlias;
|
import fr.imirhil.april.hebdobot.xml.UserAlias;
|
||||||
|
|
||||||
public class Review {
|
public class Review {
|
||||||
private static final int LENGTH = 74;
|
private static final int LENGTH = 80;
|
||||||
|
|
||||||
private final Set<String> participants = new HashSet<String>();
|
private final Set<String> participants = new HashSet<String>();
|
||||||
private final List<IndividualTopic> individualTopics =
|
private final List<IndividualTopic> individualTopics =
|
||||||
@ -67,7 +67,8 @@ public class Review {
|
|||||||
addBox(buffer, "Participants", '=');
|
addBox(buffer, "Participants", '=');
|
||||||
buffer.append("\n");
|
buffer.append("\n");
|
||||||
for (final String participant : this.participants) {
|
for (final String participant : this.participants) {
|
||||||
buffer.append("* " + userService.getRealName(participant) + "\n");
|
chunkAndAppend(buffer, "* " + userService.getRealName(participant)
|
||||||
|
+ "\n");
|
||||||
}
|
}
|
||||||
buffer.append("\n");
|
buffer.append("\n");
|
||||||
|
|
||||||
@ -80,11 +81,12 @@ public class Review {
|
|||||||
for (final IndividualTopic topic : this.individualTopics) {
|
for (final IndividualTopic topic : this.individualTopics) {
|
||||||
if (topic.hasParticipant(participant)) {
|
if (topic.hasParticipant(participant)) {
|
||||||
buffer.append("\n");
|
buffer.append("\n");
|
||||||
buffer.append(getTopic(topic));
|
chunkAndAppend(buffer, getTopic(topic));
|
||||||
buffer.append("\n");
|
buffer.append("\n");
|
||||||
for (final Message message : topic
|
for (final Message message : topic
|
||||||
.getMessages(participant)) {
|
.getMessages(participant)) {
|
||||||
buffer.append("* " + message.getContent() + "\n");
|
chunkAndAppend(buffer, "* " + message.getContent()
|
||||||
|
+ "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,7 +101,7 @@ public class Review {
|
|||||||
buffer.append("\n");
|
buffer.append("\n");
|
||||||
addBox(buffer, topic.getTitle(), '-');
|
addBox(buffer, topic.getTitle(), '-');
|
||||||
for (final Message message : topic.getMessages()) {
|
for (final Message message : topic.getMessages()) {
|
||||||
buffer.append("* " + message.getAuthor() + " : "
|
chunkAndAppend(buffer, "* " + message.getAuthor() + " : "
|
||||||
+ message.getContent() + "\n");
|
+ message.getContent() + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,8 +112,9 @@ public class Review {
|
|||||||
addBox(buffer, "Log complet", '=');
|
addBox(buffer, "Log complet", '=');
|
||||||
buffer.append("\n");
|
buffer.append("\n");
|
||||||
for (final Message message : this.messages) {
|
for (final Message message : this.messages) {
|
||||||
buffer.append("* " + message.getAuthor() + " : "
|
chunkAndAppend(buffer,
|
||||||
+ message.getContent() + "\n");
|
"* " + message.getAuthor() + " : " + message.getContent()
|
||||||
|
+ "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
@ -135,4 +138,43 @@ public class Review {
|
|||||||
buffer.append(getLine(title, ' '));
|
buffer.append(getLine(title, ' '));
|
||||||
buffer.append(getLine(c));
|
buffer.append(getLine(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String chunk(final String content, final int length) {
|
||||||
|
final String[] words = content.split(" ");
|
||||||
|
final StringBuffer result = new StringBuffer();
|
||||||
|
StringBuffer current = new StringBuffer();
|
||||||
|
|
||||||
|
for (final String word : words) {
|
||||||
|
if (current.length() + word.length() > length) {
|
||||||
|
if (result.length() > 0) {
|
||||||
|
result.append("\n");
|
||||||
|
}
|
||||||
|
result.append(current);
|
||||||
|
current = new StringBuffer(word);
|
||||||
|
} else {
|
||||||
|
if (current.length() > 0) {
|
||||||
|
current.append(" ");
|
||||||
|
}
|
||||||
|
current.append(word);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current.length() > 0) {
|
||||||
|
if (result.length() > 0) {
|
||||||
|
result.append("\n");
|
||||||
|
}
|
||||||
|
result.append(current);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user