Improved review reporter code.

This commit is contained in:
Christian P. MOMON 2018-09-25 22:57:22 +02:00
parent 1e8f06f373
commit 95c12449d1

View File

@ -40,19 +40,6 @@ public class ReviewReporter
private static final int LENGTH_LINE = 80; private static final int LENGTH_LINE = 80;
/**
* Adds the.
*
* @param buffer
* the buffer
* @param content
* the content
*/
private static void add(final StringList buffer, final String content)
{
buffer.append(content);
}
/** /**
* Adds the center. * Adds the center.
* *
@ -73,12 +60,12 @@ public class ReviewReporter
* the buffer * the buffer
* @param content * @param content
* the content * the content
* @param c * @param letter
* the c * the c
*/ */
private static void addCenter(final StringList buffer, final String content, final char c) private static void addCenter(final StringList buffer, final String content, final char letter)
{ {
buffer.append(getLine(content, c)); buffer.appendln(getLine(content, letter));
} }
/** /**
@ -91,7 +78,7 @@ public class ReviewReporter
*/ */
private static void addChunk(final StringList buffer, final String content) private static void addChunk(final StringList buffer, final String content)
{ {
add(buffer, chunk(content)); appendln(buffer, chunk(content));
} }
/** /**
@ -102,7 +89,7 @@ public class ReviewReporter
*/ */
private static void addEmpty(final StringList buffer) private static void addEmpty(final StringList buffer)
{ {
buffer.append("\n"); buffer.appendln();
} }
/** /**
@ -115,7 +102,33 @@ public class ReviewReporter
*/ */
private static void addLine(final StringList buffer, final char c) private static void addLine(final StringList buffer, final char c)
{ {
buffer.append(getLine(c)); buffer.append(getLine(c)).appendln();
}
/**
* Adds the.
*
* @param buffer
* the buffer
* @param content
* the content
*/
private static void append(final StringList buffer, final String content)
{
buffer.append(content);
}
/**
* Appendln.
*
* @param buffer
* the buffer
* @param content
* the content
*/
private static void appendln(final StringList buffer, final String content)
{
buffer.appendln(content);
} }
/** /**
@ -140,11 +153,11 @@ public class ReviewReporter
* *
* @param content * @param content
* the content * the content
* @param length * @param maxLength
* the length * the length
* @return the string * @return the string
*/ */
private static String chunk(final String content, final int length) private static String chunk(final String content, final int maxLength)
{ {
String result; String result;
@ -154,7 +167,7 @@ public class ReviewReporter
for (final String word : words) for (final String word : words)
{ {
if (current.length() + word.length() > length) if (current.length() + word.length() > maxLength)
{ {
if (buffer.length() > 0) if (buffer.length() > 0)
{ {
@ -199,7 +212,7 @@ public class ReviewReporter
{ {
String result; String result;
result = StringUtils.repeat(letter.toString(), LENGTH_LINE) + "\n"; result = StringUtils.repeat(letter.toString(), LENGTH_LINE);
// //
return result; return result;
@ -218,7 +231,7 @@ public class ReviewReporter
{ {
String result; String result;
result = StringUtils.center(" " + content + " ", LENGTH_LINE, letter) + "\n"; result = StringUtils.center(" " + content + " ", LENGTH_LINE, letter);
// //
return result; return result;
@ -235,7 +248,7 @@ public class ReviewReporter
{ {
String result; String result;
result = "=== " + topic.getTitle() + " ===\n"; result = "=== " + topic.getTitle() + " ===";
// //
return result; return result;
@ -256,6 +269,8 @@ public class ReviewReporter
// //
StringList buffer = new StringList(); StringList buffer = new StringList();
//
addLine(buffer, '='); addLine(buffer, '=');
addCenter(buffer, "Revue de la semaine en cours"); addCenter(buffer, "Revue de la semaine en cours");
addEmpty(buffer); addEmpty(buffer);
@ -270,7 +285,7 @@ public class ReviewReporter
addCenter(buffer, "Participants", '-'); addCenter(buffer, "Participants", '-');
for (final String participant : review.getParticipants()) for (final String participant : review.getParticipants())
{ {
addChunk(buffer, "* " + review.getAliases().getRealName(participant) + "\n"); addChunk(buffer, "* " + review.getAliases().getRealName(participant));
} }
// //
@ -287,11 +302,11 @@ public class ReviewReporter
if (topic.hasParticipant(participant)) if (topic.hasParticipant(participant))
{ {
addEmpty(buffer); addEmpty(buffer);
add(buffer, getTopic(topic)); appendln(buffer, getTopic(topic));
addEmpty(buffer); addEmpty(buffer);
for (final Message message : topic.getMessages(participant)) for (final Message message : topic.getMessages(participant))
{ {
addChunk(buffer, "* " + message.getContent() + "\n"); addChunk(buffer, "* " + message.getContent());
} }
} }
} }
@ -310,7 +325,7 @@ public class ReviewReporter
addEmpty(buffer); addEmpty(buffer);
for (final Message message : topic.getMessages()) for (final Message message : topic.getMessages())
{ {
addChunk(buffer, "* " + message.getAuthor() + " : " + message.getContent() + "\n"); addChunk(buffer, "* " + message.getAuthor() + " : " + message.getContent());
} }
} }
} }
@ -321,21 +336,21 @@ public class ReviewReporter
addEmpty(buffer); addEmpty(buffer);
for (Message message : review.getMessages()) for (Message message : review.getMessages())
{ {
addChunk(buffer, "* " + message.getAuthor() + " : " + message.getContent() + "\n"); addChunk(buffer, "* " + message.getAuthor() + " : " + message.getContent());
} }
// Add statistics in text review. // Add statistics in text review.
addEmpty(buffer); addEmpty(buffer);
addCenter(buffer, "Statistiques"); addCenter(buffer, "Statistiques");
addEmpty(buffer); addEmpty(buffer);
addChunk(buffer, ReviewStatsReporter.reportReviewCount(datas) + "\n"); addChunk(buffer, ReviewStatsReporter.reportReviewCount(datas));
addChunk(buffer, "Horaire de début de la revue : " + review.getFormattedStartTime() + "\n"); addChunk(buffer, "Horaire de début de la revue : " + review.getFormattedStartTime());
addChunk(buffer, "Horaire de fin de la revue : " + review.getFormattedEndTime() + "\n"); addChunk(buffer, "Horaire de fin de la revue : " + review.getFormattedEndTime());
addChunk(buffer, "Durée de la revue : " + review.getDurationInMinutes() + " minutes\n"); addChunk(buffer, "Durée de la revue : " + review.getDurationInMinutes() + " minutes");
addChunk(buffer, "Nombre de personnes participantes : " + review.getParticipants().size() + "\n"); addChunk(buffer, "Nombre de personnes participantes : " + review.getParticipants().size());
addChunk(buffer, ReviewStatsReporter.reportUserCount(datas, review.getParticipants().size()) + "\n"); addChunk(buffer, ReviewStatsReporter.reportUserCount(datas, review.getParticipants().size()));
addChunk(buffer, ReviewStatsReporter.reportNewMaxUserCount(datas, review.getParticipants().size()) + "\n"); addChunk(buffer, ReviewStatsReporter.reportNewMaxUserCount(datas, review.getParticipants().size()));
addChunk(buffer, ReviewStatsReporter.reportDuration(datas, review.getDurationInMinutes()) + "\n"); addChunk(buffer, ReviewStatsReporter.reportDuration(datas, review.getDurationInMinutes()));
// //
result = buffer.toString(); result = buffer.toString();