From 688d5f0a8885198dafef4fa9117f966dd95457f0 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Thu, 14 Dec 2017 16:58:45 +0100 Subject: [PATCH] Made a code review. --- .settings/org.eclipse.jdt.core.prefs | 10 + .settings/org.eclipse.jdt.ui.prefs | 4 + .../imirhil/april/hebdobot/Application.java | 39 +- .../fr/imirhil/april/hebdobot/Context.java | 28 +- .../java/fr/imirhil/april/hebdobot/Job.java | 30 ++ .../april/hebdobot/OAuthRegistration.java | 11 + .../fr/imirhil/april/hebdobot/irc/Bot.java | 451 ++++++++++++------ .../april/hebdobot/irc/ReviewListener.java | 15 + .../april/hebdobot/pastebin/Expiration.java | 14 + .../april/hebdobot/pastebin/Format.java | 14 + .../april/hebdobot/pastebin/Option.java | 14 + .../hebdobot/pastebin/PastebinClient.java | 338 ++++++++++++- .../april/hebdobot/pastebin/Private.java | 14 + .../hebdobot/review/CollectiveTopic.java | 20 + .../hebdobot/review/IndividualTopic.java | 29 ++ .../april/hebdobot/review/Message.java | 26 + .../imirhil/april/hebdobot/review/Review.java | 224 ++++++++- .../imirhil/april/hebdobot/review/Topic.java | 25 + .../imirhil/april/hebdobot/xml/UserAlias.java | 28 +- .../imirhil/april/hebdobot/irc/BotTest.java | 28 +- .../hebdobot/pastebin/PastebinClientTest.java | 9 + 21 files changed, 1177 insertions(+), 194 deletions(-) diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index a41f3ba..b70abf3 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,14 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.codeComplete.argumentPrefixes= +org.eclipse.jdt.core.codeComplete.argumentSuffixes= +org.eclipse.jdt.core.codeComplete.fieldPrefixes= +org.eclipse.jdt.core.codeComplete.fieldSuffixes= +org.eclipse.jdt.core.codeComplete.localPrefixes= +org.eclipse.jdt.core.codeComplete.localSuffixes= +org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= +org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= +org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes= +org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes= org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs index 9335075..773d084 100644 --- a/.settings/org.eclipse.jdt.ui.prefs +++ b/.settings/org.eclipse.jdt.ui.prefs @@ -63,6 +63,10 @@ formatter_profile=_Hebdobot formatter_settings_version=12 jautodoc.cleanup.add_header=false jautodoc.cleanup.replace_header=false +org.eclipse.jdt.ui.exception.name=exception +org.eclipse.jdt.ui.gettersetter.use.is=true +org.eclipse.jdt.ui.keywordthis=false +org.eclipse.jdt.ui.overrideannotation=true sp_cleanup.add_default_serial_version_id=true sp_cleanup.add_generated_serial_version_id=false sp_cleanup.add_missing_annotations=true diff --git a/src/main/java/fr/imirhil/april/hebdobot/Application.java b/src/main/java/fr/imirhil/april/hebdobot/Application.java index 5dfec1b..6b2845e 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/Application.java +++ b/src/main/java/fr/imirhil/april/hebdobot/Application.java @@ -35,21 +35,36 @@ import fr.imirhil.april.hebdobot.pastebin.PastebinClient; import fr.imirhil.april.hebdobot.pastebin.Private; import fr.imirhil.april.hebdobot.review.Review; +/** + * The Class Application. + */ public class Application implements ReviewListener { - private static final Logger LOGGER = LoggerFactory.getLogger(Application.class); + private static final Logger logger = LoggerFactory.getLogger(Application.class); private static final String FILE_SUFFIX = "file.suffix"; - private final Properties properties = Context.getBean("properties"); - private final Bot bot = Context.getBean(Bot.class); - private final PastebinClient pastebinClient = Context.getBean(PastebinClient.class); + private final Properties properties; + private final Bot bot; + private final PastebinClient pastebinClient; + /** + * Instantiates a new application. + * + * @throws Exception + * the exception + */ private Application() throws Exception { + this.properties = Context.getBean("properties"); + this.bot = Context.getBean(Bot.class); + this.pastebinClient = Context.getBean(PastebinClient.class); this.bot.add(this); } + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.irc.ReviewListener#onEnd(fr.imirhil.april.hebdobot.review.Review) + */ @Override public void onEnd(final Review review) { @@ -59,9 +74,9 @@ public class Application implements ReviewListener { this.bot.sendMessage("% Compte-rendu de la revue : " + this.pastebinClient.paste(text, "Revue APRIL " + date, Private.UNLISTED)); } - catch (final Exception e) + catch (final Exception exception) { - LOGGER.error("Error during Pastebin submit", e); + logger.error("Error during Pastebin submit", exception); } if (this.properties.containsKey(FILE_SUFFIX)) @@ -72,13 +87,21 @@ public class Application implements ReviewListener FileUtils.writeStringToFile(file, text); this.bot.sendMessage("% Compte-rendu de la revue : " + file.getName()); } - catch (final Exception e) + catch (final Exception exception) { - LOGGER.error("Error during file generation", e); + logger.error("Error during file generation", exception); } } } + /** + * The main method. + * + * @param args + * the arguments + * @throws Exception + * the exception + */ public static void main(final String[] args) throws Exception { new FileSystemXmlApplicationContext(System.getProperty("spring.conf", "conf.xml")).registerShutdownHook(); diff --git a/src/main/java/fr/imirhil/april/hebdobot/Context.java b/src/main/java/fr/imirhil/april/hebdobot/Context.java index af81a04..d86ea47 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/Context.java +++ b/src/main/java/fr/imirhil/april/hebdobot/Context.java @@ -25,17 +25,26 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.stereotype.Component; +/** + * The Class Context. + */ @Component public final class Context implements ApplicationContextAware { private static ApplicationContext CONTEXT; + /* (non-Javadoc) + * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) + */ @Override public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException { CONTEXT = applicationContext; } + /** + * Close. + */ public static void close() { if (CONTEXT instanceof ConfigurableApplicationContext) @@ -44,12 +53,29 @@ public final class Context implements ApplicationContextAware } } + /** + * Gets the bean. + * + * @param + * the generic type + * @param clazz + * the clazz + * @return the bean + */ public static T getBean(final Class clazz) { return CONTEXT.getBean(clazz); } - @SuppressWarnings("unchecked") + /** + * Gets the bean. + * + * @param + * the generic type + * @param name + * the name + * @return the bean + */ public static T getBean(final String name) { return (T) CONTEXT.getBean(name); diff --git a/src/main/java/fr/imirhil/april/hebdobot/Job.java b/src/main/java/fr/imirhil/april/hebdobot/Job.java index 9deb75f..e7997ce 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/Job.java +++ b/src/main/java/fr/imirhil/april/hebdobot/Job.java @@ -25,6 +25,9 @@ import org.springframework.social.twitter.api.impl.TwitterTemplate; import fr.imirhil.april.hebdobot.irc.Bot; +/** + * The Class Job. + */ public class Job { @Resource @@ -34,21 +37,36 @@ public class Job private String tweet; private String irc; + /** + * At 30. + */ public void at30() { this.notify(30); } + /** + * At 45. + */ public void at45() { this.notify(15); } + /** + * At 55. + */ public void at55() { this.notify(5); } + /** + * Notify. + * + * @param min + * the min + */ private void notify(final int min) { this.bot.sendMessage(String.format(this.irc, min)); @@ -56,11 +74,23 @@ public class Job this.twitterClient.timelineOperations().updateStatus(tweet); } + /** + * Sets the irc. + * + * @param message + * the new irc + */ public void setIrc(final String message) { this.irc = message; } + /** + * Sets the tweet. + * + * @param message + * the new tweet + */ public void setTweet(final String message) { this.tweet = message; diff --git a/src/main/java/fr/imirhil/april/hebdobot/OAuthRegistration.java b/src/main/java/fr/imirhil/april/hebdobot/OAuthRegistration.java index 6e0c117..07cfbdc 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/OAuthRegistration.java +++ b/src/main/java/fr/imirhil/april/hebdobot/OAuthRegistration.java @@ -27,8 +27,19 @@ import org.scribe.model.Token; import org.scribe.model.Verifier; import org.scribe.oauth.OAuthService; +/** + * The Class OAuthRegistration. + */ public class OAuthRegistration { + /** + * The main method. + * + * @param args + * the arguments + * @throws Exception + * the exception + */ public static void main(final String args[]) throws Exception { final OAuthService service = new ServiceBuilder().provider(TwitterApi.class).apiKey("uCZMXbUWuda7a2RqqKd2yg") diff --git a/src/main/java/fr/imirhil/april/hebdobot/irc/Bot.java b/src/main/java/fr/imirhil/april/hebdobot/irc/Bot.java index 0759eff..2e738f5 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/irc/Bot.java +++ b/src/main/java/fr/imirhil/april/hebdobot/irc/Bot.java @@ -20,6 +20,7 @@ package fr.imirhil.april.hebdobot.irc; import java.util.Collection; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -36,41 +37,86 @@ import fr.imirhil.april.hebdobot.review.Message; import fr.imirhil.april.hebdobot.review.Review; import fr.imirhil.april.hebdobot.review.Topic; +/** + * The Class Bot. + */ public class Bot extends PircBot { + /** + * The Class Handler. + */ private abstract class Handler { + /** + * Handle. + * + * @param sender + * the sender + * @param message + * the message + * @return true, if successful + */ public abstract boolean handle(String sender, String message); } - private static final Logger LOGGER = LoggerFactory.getLogger(Bot.class); + private static final Logger logger = LoggerFactory.getLogger(Bot.class); private final String host; private final int port; private final String channel; private Review review = null; - private final Collection listeners = new LinkedList(); - private final List handlers = new LinkedList(); + private final Collection listeners; + private final List handlers; + /** + * Instantiates a new bot. + * + * @param host + * the host + * @param port + * the port + * @param name + * the name + * @param channel + * the channel + */ public Bot(final String host, final int port, final String name, final String channel) { this.host = host; this.port = port; this.channel = channel; this.setName(name); + + this.listeners = new LinkedList(); + this.handlers = new LinkedList(); } + /** + * Adds the. + * + * @param listener + * the listener + */ public void add(final ReviewListener listener) { this.listeners.add(listener); } + /** + * Close. + */ public void close() { this.disconnect(); this.dispose(); } + /** + * Inits the. + * + * @throws Exception + * the exception + */ public void init() throws Exception { this.connect(this.host, this.port); @@ -79,282 +125,415 @@ public class Bot extends PircBot this.registerHandlers(); } + /* (non-Javadoc) + * @see org.jibble.pircbot.PircBot#onMessage(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + */ @Override protected void onMessage(final String channel, final String sender, final String login, final String hostname, String message) { - LOGGER.debug("Message received - channel : {}, sender : {}, message : {}", new Object[] { channel, sender, message }); - if (!channel.equalsIgnoreCase(this.channel)) + logger.debug("Message received - channel : {}, sender : {}, message : {}", channel, sender, message); + if (channel.equalsIgnoreCase(this.channel)) { - return; - } + message = message.trim(); - message = message.trim(); - - for (final Handler handler : this.handlers) - { - if (handler.handle(sender, message)) + boolean ended = false; + Iterator iterator = this.handlers.iterator(); + while (!ended) { - break; + if (iterator.hasNext()) + { + Handler currentHandler = iterator.next(); + + if (currentHandler.handle(sender, message)) + { + ended = true; + } + } + else + { + ended = true; + } } } } + /** + * Register handlers. + */ private void registerHandlers() { // Help this.handlers.add(new Handler() { + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String) + */ @Override public boolean handle(final String sender, final String message) { - if (!"!help".equalsIgnoreCase(message)) + boolean result; + + if (StringUtils.equalsIgnoreCase(message, "!help")) { - return false; + Bot.this.sendMessage(sender, "Bienvenue " + sender); + Bot.this.sendMessage(sender, "Je suis " + Bot.this.getName() + ", le robot de gestion des revues hebdomadaires de l'APRIL"); + Bot.this.sendMessage(sender, "Voici les commandes que je comprend :"); + Bot.this.sendMessage(sender, " "); + Bot.this.sendMessage(sender, "— !debut : commencer une nouvelle revue"); + Bot.this.sendMessage(sender, "— !fin : terminer la revue en cours"); + Bot.this.sendMessage(sender, "— # titre : démarrer un sujet individuel"); + Bot.this.sendMessage(sender, "— ## titre : démarrer un sujet collectif"); + Bot.this.sendMessage(sender, "— !courant : affiche le sujet en cours"); + Bot.this.sendMessage(sender, "— !manquants : affiche les participants qui n'ont pas répondu sur le dernier sujet"); + Bot.this.sendMessage(sender, "— % message : un commentaire"); + result = true; + } + else + { + result = false; } - Bot.this.sendMessage(sender, "Bienvenue " + sender); - Bot.this.sendMessage(sender, "Je suis " + Bot.this.getName() + ", le robot de gestion des revues hebdomadaires de l'APRIL"); - Bot.this.sendMessage(sender, "Voici les commandes que je comprend :"); - Bot.this.sendMessage(sender, " "); - Bot.this.sendMessage(sender, "— !debut : commencer une nouvelle revue"); - Bot.this.sendMessage(sender, "— !fin : terminer la revue en cours"); - Bot.this.sendMessage(sender, "— # titre : démarrer un sujet individuel"); - Bot.this.sendMessage(sender, "— ## titre : démarrer un sujet collectif"); - Bot.this.sendMessage(sender, "— !courant : affiche le sujet en cours"); - Bot.this.sendMessage(sender, "— !manquants : affiche les participants qui n'ont pas répondu sur le dernier sujet"); - Bot.this.sendMessage(sender, "— % message : un commentaire"); - return true; + // + return result; } }); // Die this.handlers.add(new Handler() { + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String) + */ @Override public boolean handle(final String sender, final String message) { - if (!"!stop".equalsIgnoreCase(message)) - { - return false; - } + boolean result; - if (Bot.this.review != null) + if (!StringUtils.equalsIgnoreCase(message, "!stop")) + { + result = false; + } + else if (Bot.this.review != null) { Bot.this.sendMessage("% Une revue est en cours, arrêt impossible"); - return false; + result = false; + } + else + { + Context.close(); + result = true; } - Context.close(); - return true; + // + return result; } }); // Start this.handlers.add(new Handler() { + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String) + */ @Override public boolean handle(final String sender, final String message) { - if (!"!debut".equalsIgnoreCase(message)) + boolean result; + + if (!StringUtils.equalsIgnoreCase(message, "!debut")) { - return false; + result = false; + } + else + { + Bot.this.review = new Review(sender); + Bot.this.sendMessage(sender, "Vous êtes le conducteur de réunion"); + Bot.this.sendMessage(sender, "Pour terminer la réunion, tapez \"!fin\""); + Bot.this.sendMessage("% Début de la réunion hebdomadaire"); + Bot.this.sendMessage( + "% rappel : toute ligne commençant par % sera considérée comme un commentaire et non prise en compte dans la synthèse"); + result = true; } - Bot.this.review = new Review(sender); - Bot.this.sendMessage(sender, "Vous êtes le conducteur de réunion"); - Bot.this.sendMessage(sender, "Pour terminer la réunion, tapez \"!fin\""); - Bot.this.sendMessage("% Début de la réunion hebdomadaire"); - Bot.this.sendMessage( - "% rappel : toute ligne commençant par % sera considérée comme un commentaire et non prise en compte dans la synthèse"); - return true; + // + return result; } }); // Stop this.handlers.add(new Handler() { + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String) + */ @Override public boolean handle(final String sender, final String message) { - if (Bot.this.review == null || !"!fin".equalsIgnoreCase(message)) + boolean result; + + if (Bot.this.review == null || !StringUtils.equalsIgnoreCase(message, "!fin")) { - return false; + result = false; + } + else + { + if (!Bot.this.review.isOwner(sender)) + { + Bot.this.sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion"); + result = false; + } + else + { + for (final ReviewListener listener : Bot.this.listeners) + { + listener.onEnd(Bot.this.review); + } + + Bot.this.sendMessage("% " + Bot.this.review.getOwner() + + ", ne pas oublier d'ajouter le compte-rendu de la revue sur https://agir.april.org/issues/135"); + final String participants = StringUtils.join(Bot.this.review.getParticipants(), " "); + Bot.this.sendMessage("% " + participants + ", pensez à noter votre bénévalo : http://www.april.org/my?action=benevalo"); + Bot.this.sendMessage("% Fin de la revue hebdomadaire"); + Bot.this.review = null; + + result = true; + } } - if (!Bot.this.review.isOwner(sender)) - { - Bot.this.sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion"); - return false; - } - - for (final ReviewListener listener : Bot.this.listeners) - { - listener.onEnd(Bot.this.review); - } - - Bot.this.sendMessage("% " + Bot.this.review.getOwner() - + ", ne pas oublier d'ajouter le compte-rendu de la revue sur https://agir.april.org/issues/135"); - final String participants = StringUtils.join(Bot.this.review.getParticipants(), " "); - Bot.this.sendMessage("% " + participants + ", pensez à noter votre bénévalo : http://www.april.org/my?action=benevalo"); - Bot.this.sendMessage("% Fin de la revue hebdomadaire"); - Bot.this.review = null; - return true; + // + return result; } }); // Collective topic, must be before individual topic this.handlers.add(new Handler() { + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String) + */ @Override public boolean handle(final String sender, final String message) { + boolean result; + if (Bot.this.review == null || !message.matches("\\s*##.*")) { - return false; - } - - if (!Bot.this.review.isOwner(sender)) - { - Bot.this.sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion"); - return false; - } - - final CollectiveTopic topic = new CollectiveTopic(message.replaceFirst("##", "").trim()); - Bot.this.review.begin(topic); - Bot.this.sendMessage("Sujet collectif : " + topic.getTitle()); - if (topic.getTitle().toLowerCase().contains("bloquage")) - { - Bot.this.sendMessage("% si rien à dire vous pouvez dire %ras"); + result = false; } else { - Bot.this.sendMessage("% 1 minute max"); + if (Bot.this.review.isOwner(sender)) + { + final CollectiveTopic topic = new CollectiveTopic(message.replaceFirst("##", "").trim()); + Bot.this.review.begin(topic); + Bot.this.sendMessage("Sujet collectif : " + topic.getTitle()); + if (topic.getTitle().toLowerCase().contains("bloquage")) + { + Bot.this.sendMessage("% si rien à dire vous pouvez dire %ras"); + } + else + { + Bot.this.sendMessage("% 1 minute max"); + } + result = true; + } + else + { + Bot.this.sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion"); + result = false; + } } - return true; + + // + return result; } }); // Individual topic this.handlers.add(new Handler() { + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String) + */ @Override public boolean handle(final String sender, final String message) { + boolean result; + if (Bot.this.review == null || !message.matches("\\s*#[^#].*")) { - return false; + result = false; } - - if (!Bot.this.review.isOwner(sender)) + else { - Bot.this.sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion"); - return false; + if (Bot.this.review.isOwner(sender)) + { + Bot.this.sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion"); + result = false; + } + else + { + final IndividualTopic topic = new IndividualTopic(message.replaceFirst("#", "").trim()); + Bot.this.review.begin(topic); + Bot.this.sendMessage("Sujet individuel : " + topic.getTitle()); + Bot.this.sendMessage("% quand vous avez fini vous le dites par % fini"); + result = true; + } } - final IndividualTopic topic = new IndividualTopic(message.replaceFirst("#", "").trim()); - Bot.this.review.begin(topic); - Bot.this.sendMessage("Sujet individuel : " + topic.getTitle()); - Bot.this.sendMessage("% quand vous avez fini vous le dites par % fini"); - return true; + // + return result; } }); // Missing this.handlers.add(new Handler() { + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String) + */ @Override public boolean handle(final String sender, final String message) { - if (Bot.this.review == null || !"!manquants".equalsIgnoreCase(message)) + boolean result; + + if (Bot.this.review == null || !StringUtils.equalsIgnoreCase(message, "!manquants")) { - return false; + result = false; + } + else + { + final Topic topic = Bot.this.review.getCurrentTopic(); + if (topic == null) + { + Bot.this.sendMessage("Aucun sujet traité"); + result = true; + } + else + { + final Collection participants = Bot.this.review.getParticipants(); + final Collection currentParticipants = topic.getParticipants(); + + final Collection missing = CollectionUtils.subtract(participants, currentParticipants); + if (missing.isEmpty()) + { + Bot.this.sendMessage("Aucun participant manquant \\o/"); + result = true; + } + else + { + Bot.this.sendMessage(String.format("Les participants suivants sont manquants : %1s", StringUtils.join(missing, ", "))); + result = true; + } + } } - final Topic topic = Bot.this.review.getCurrentTopic(); - if (topic == null) - { - Bot.this.sendMessage("Aucun sujet traité"); - return true; - } - - final Collection participants = Bot.this.review.getParticipants(); - final Collection currentParticipants = topic.getParticipants(); - - @SuppressWarnings("unchecked") - final Collection missing = CollectionUtils.subtract(participants, currentParticipants); - if (missing.isEmpty()) - { - Bot.this.sendMessage("Aucun participant manquant \\o/"); - return true; - } - - Bot.this.sendMessage(String.format("Les participants suivants sont manquants : %1s", StringUtils.join(missing, ", "))); - return true; + // + return result; } }); // Current this.handlers.add(new Handler() { + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String) + */ @Override public boolean handle(final String sender, final String message) { - if (Bot.this.review == null || !"!courant".equalsIgnoreCase(message)) + boolean result; + + if (Bot.this.review == null || !StringUtils.equalsIgnoreCase(message, "!courant")) { - return false; + result = false; + } + else + { + final Topic current = Bot.this.review.getCurrentTopic(); + if (current == null) + { + Bot.this.sendMessage("% Pas de sujet en cours"); + } + else if (current instanceof IndividualTopic) + { + Bot.this.sendMessage("% Sujet individuel en cours : " + current.getTitle()); + } + else if (current instanceof CollectiveTopic) + { + Bot.this.sendMessage("% Sujet collectif en cours : " + current.getTitle()); + } + + result = true; } - final Topic current = Bot.this.review.getCurrentTopic(); - if (current == null) - { - Bot.this.sendMessage("% Pas de sujet en cours"); - } - else if (current instanceof IndividualTopic) - { - Bot.this.sendMessage("% Sujet individuel en cours : " + current.getTitle()); - } - else if (current instanceof CollectiveTopic) - { - Bot.this.sendMessage("% Sujet collectif en cours : " + current.getTitle()); - } - return true; + // + return result; } }); // Topic message this.handlers.add(new Handler() { + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String) + */ @Override public boolean handle(final String sender, final String message) { + boolean result; + if (Bot.this.review == null || message.startsWith("%")) { - return false; + result = false; } - Bot.this.review.add(new Message(sender, message)); - return true; + else + { + Bot.this.review.add(new Message(sender, message)); + result = true; + } + + // + return result; } }); // All the other this.handlers.add(new Handler() { + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String) + */ @Override public boolean handle(final String sender, final String message) { + boolean result; + if (Bot.this.review == null) { - return false; + result = false; } - Bot.this.review.addRaw(new Message(sender, message)); - return true; + else + { + Bot.this.review.addRaw(new Message(sender, message)); + result = true; + } + + // + return result; } }); } + /** + * Send message. + * + * @param message + * the message + */ public void sendMessage(final String message) { - LOGGER.debug("Send message : {}", message); + logger.debug("Send message : {}", message); this.sendMessage(this.channel, message); } } diff --git a/src/main/java/fr/imirhil/april/hebdobot/irc/ReviewListener.java b/src/main/java/fr/imirhil/april/hebdobot/irc/ReviewListener.java index 1041389..a30b7f9 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/irc/ReviewListener.java +++ b/src/main/java/fr/imirhil/april/hebdobot/irc/ReviewListener.java @@ -21,7 +21,22 @@ package fr.imirhil.april.hebdobot.irc; import fr.imirhil.april.hebdobot.review.Review; +/** + * The listener interface for receiving review events. The class that is + * interested in processing a review event implements this interface, and the + * object created with that class is registered with a component using the + * component's addReviewListener method. When the review event + * occurs, that object's appropriate method is invoked. + * + * @see ReviewEvent + */ public interface ReviewListener { + /** + * On end. + * + * @param review + * the review + */ void onEnd(Review review); } diff --git a/src/main/java/fr/imirhil/april/hebdobot/pastebin/Expiration.java b/src/main/java/fr/imirhil/april/hebdobot/pastebin/Expiration.java index 06e4878..d0ec39f 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/pastebin/Expiration.java +++ b/src/main/java/fr/imirhil/april/hebdobot/pastebin/Expiration.java @@ -19,6 +19,9 @@ */ package fr.imirhil.april.hebdobot.pastebin; +/** + * The Enum Expiration. + */ public enum Expiration { NEVER(null), @@ -29,11 +32,22 @@ public enum Expiration private final String value; + /** + * Instantiates a new expiration. + * + * @param value + * the value + */ private Expiration(final String value) { this.value = value; } + /** + * Gets the value. + * + * @return the value + */ public String getValue() { return this.value; diff --git a/src/main/java/fr/imirhil/april/hebdobot/pastebin/Format.java b/src/main/java/fr/imirhil/april/hebdobot/pastebin/Format.java index 8e2aa7b..610b9cc 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/pastebin/Format.java +++ b/src/main/java/fr/imirhil/april/hebdobot/pastebin/Format.java @@ -19,6 +19,9 @@ */ package fr.imirhil.april.hebdobot.pastebin; +/** + * The Enum Format. + */ public enum Format { NONE(null), @@ -29,11 +32,22 @@ public enum Format private final String value; + /** + * Instantiates a new format. + * + * @param value + * the value + */ private Format(final String value) { this.value = value; } + /** + * Gets the value. + * + * @return the value + */ public String getValue() { return this.value; diff --git a/src/main/java/fr/imirhil/april/hebdobot/pastebin/Option.java b/src/main/java/fr/imirhil/april/hebdobot/pastebin/Option.java index bda96ab..b9b9212 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/pastebin/Option.java +++ b/src/main/java/fr/imirhil/april/hebdobot/pastebin/Option.java @@ -19,17 +19,31 @@ */ package fr.imirhil.april.hebdobot.pastebin; +/** + * The Enum Option. + */ public enum Option { PASTE("paste"); private final String value; + /** + * Instantiates a new option. + * + * @param value + * the value + */ private Option(final String value) { this.value = value; } + /** + * Gets the value. + * + * @return the value + */ public String getValue() { return this.value; diff --git a/src/main/java/fr/imirhil/april/hebdobot/pastebin/PastebinClient.java b/src/main/java/fr/imirhil/april/hebdobot/pastebin/PastebinClient.java index 3ac169c..aaaecdc 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/pastebin/PastebinClient.java +++ b/src/main/java/fr/imirhil/april/hebdobot/pastebin/PastebinClient.java @@ -32,17 +32,37 @@ import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; +/** + * The Class PastebinClient. + */ public class PastebinClient { + /** + * The Class APIException. + */ public static class APIException extends Exception { private static final long serialVersionUID = 1L; + /** + * Instantiates a new API exception. + * + * @param message + * the message + */ private APIException(final String message) { super(message); } + /** + * Throw if error. + * + * @param content + * the content + * @throws APIException + * the API exception + */ private static void throwIfError(final String content) throws APIException { if (content.contains(API_ERROR)) @@ -52,6 +72,9 @@ public class PastebinClient } } + private static final String API_LOGIN_URL = "http://pastebin.com/api/api_login.php"; + private static final String API_POST_URL = "http://pastebin.com/api/api_post.php"; + private static final String API_DEV_KEY = "api_dev_key"; private static final String API_USER_KEY = "api_user_key"; private static final String API_USER_NAME = "api_user_name"; @@ -60,6 +83,7 @@ public class PastebinClient private static final String API_PASTE_PRIVATE = "api_paste_private"; private static final String API_PASTE_NAME = "api_paste_name"; private static final String API_PASTE_EXPIRATION = "api_paste_expire_date"; + private static final String API_PASTE_FORMAT = "api_paste_format"; private static final String API_PASTE_CODE = "api_paste_code"; @@ -68,13 +92,30 @@ public class PastebinClient private final String apiKey; private String apiUserKey = null; - HttpClient httpClient = new DefaultHttpClient(); + private HttpClient httpClient = new DefaultHttpClient(); + + /** + * Instantiates a new pastebin client. + * + * @param apiKey + * the api key + */ public PastebinClient(final String apiKey) { this.apiKey = apiKey; } + /** + * Login. + * + * @param name + * the name + * @param password + * the password + * @throws Exception + * the exception + */ public void login(final String name, final String password) throws Exception { final List params = new LinkedList(); @@ -82,7 +123,7 @@ public class PastebinClient setParameter(params, API_USER_NAME, name); setParameter(params, API_USER_PASSWORD, password); - final HttpPost request = new HttpPost("http://pastebin.com/api/api_login.php"); + final HttpPost request = new HttpPost(API_LOGIN_URL); request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); final HttpResponse response = this.httpClient.execute(request); @@ -91,68 +132,297 @@ public class PastebinClient this.apiUserKey = content; } + /** + * Paste. + * + * @param code + * the code + * @return the string + * @throws Exception + * the exception + */ public String paste(final String code) throws Exception { - return this.paste(code, null, Format.NONE, Private.PUBLIC, Expiration.DAY_1); + String result; + + result = this.paste(code, null, Format.NONE, Private.PUBLIC, Expiration.DAY_1); + + // + return result; } + /** + * Paste. + * + * @param code + * the code + * @param expiration + * the expiration + * @return the string + * @throws Exception + * the exception + */ public String paste(final String code, final Expiration expiration) throws Exception { - return this.paste(code, null, Format.NONE, Private.PUBLIC, expiration); + String result; + + result = this.paste(code, null, Format.NONE, Private.PUBLIC, expiration); + + // + return result; } + /** + * Paste. + * + * @param code + * the code + * @param format + * the format + * @return the string + * @throws Exception + * the exception + */ public String paste(final String code, final Format format) throws Exception { - return this.paste(code, null, format, Private.PUBLIC, Expiration.DAY_1); + String result; + + result = this.paste(code, null, format, Private.PUBLIC, Expiration.DAY_1); + + // + return result; } + /** + * Paste. + * + * @param code + * the code + * @param format + * the format + * @param expiration + * the expiration + * @return the string + * @throws Exception + * the exception + */ public String paste(final String code, final Format format, final Expiration expiration) throws Exception { - return this.paste(code, null, format, Private.PUBLIC, expiration); + String result; + + result = this.paste(code, null, format, Private.PUBLIC, expiration); + + // + return result; } + /** + * Paste. + * + * @param code + * the code + * @param format + * the format + * @param privat + * the privat + * @return the string + * @throws Exception + * the exception + */ public String paste(final String code, final Format format, final Private privat) throws Exception { - return this.paste(code, null, format, privat, Expiration.DAY_1); + String result; + + result = this.paste(code, null, format, privat, Expiration.DAY_1); + + // + return result; } + /** + * Paste. + * + * @param code + * the code + * @param format + * the format + * @param privat + * the privat + * @param expiration + * the expiration + * @return the string + * @throws Exception + * the exception + */ public String paste(final String code, final Format format, final Private privat, final Expiration expiration) throws Exception { - return this.paste(code, null, format, privat, expiration); + String result; + + result = this.paste(code, null, format, privat, expiration); + + // + return result; } + /** + * Paste. + * + * @param code + * the code + * @param privat + * the privat + * @return the string + * @throws Exception + * the exception + */ public String paste(final String code, final Private privat) throws Exception { - return this.paste(code, null, Format.NONE, privat, Expiration.DAY_1); + String result; + + result = this.paste(code, null, Format.NONE, privat, Expiration.DAY_1); + + // + return result; } + /** + * Paste. + * + * @param code + * the code + * @param privat + * the privat + * @param expiration + * the expiration + * @return the string + * @throws Exception + * the exception + */ public String paste(final String code, final Private privat, final Expiration expiration) throws Exception { - return this.paste(code, null, Format.NONE, privat, expiration); + String result; + + result = this.paste(code, null, Format.NONE, privat, expiration); + + // + return result; } + /** + * Paste. + * + * @param code + * the code + * @param name + * the name + * @return the string + * @throws Exception + * the exception + */ public String paste(final String code, final String name) throws Exception { - return this.paste(code, name, Format.NONE, Private.PUBLIC, Expiration.DAY_1); + String result; + + result = this.paste(code, name, Format.NONE, Private.PUBLIC, Expiration.DAY_1); + + // + return result; } + /** + * Paste. + * + * @param code + * the code + * @param name + * the name + * @param format + * the format + * @return the string + * @throws Exception + * the exception + */ public String paste(final String code, final String name, final Format format) throws Exception { - return this.paste(code, name, format, Private.PUBLIC, Expiration.DAY_1); + String result; + + result = this.paste(code, name, format, Private.PUBLIC, Expiration.DAY_1); + + // + return result; } + /** + * Paste. + * + * @param code + * the code + * @param name + * the name + * @param format + * the format + * @param expiration + * the expiration + * @return the string + * @throws Exception + * the exception + */ public String paste(final String code, final String name, final Format format, final Expiration expiration) throws Exception { - return this.paste(code, name, format, Private.PUBLIC, expiration); + String result; + + result = this.paste(code, name, format, Private.PUBLIC, expiration); + + // + return result; } + /** + * Paste. + * + * @param code + * the code + * @param name + * the name + * @param format + * the format + * @param privat + * the privat + * @return the string + * @throws Exception + * the exception + */ public String paste(final String code, final String name, final Format format, final Private privat) throws Exception { - return this.paste(code, name, format, privat, Expiration.DAY_1); + String result; + + result = this.paste(code, name, format, privat, Expiration.DAY_1); + + // + return result; } + /** + * Paste. + * + * @param code + * the code + * @param name + * the name + * @param format + * the format + * @param privat + * the privat + * @param expiration + * the expiration + * @return the string + * @throws Exception + * the exception + */ public String paste(final String code, final String name, final Format format, final Private privat, final Expiration expiration) throws Exception { + String result; + final List params = new LinkedList(); setParameter(params, API_DEV_KEY, this.apiKey); setParameter(params, API_USER_KEY, this.apiUserKey); @@ -163,20 +433,50 @@ public class PastebinClient setParameter(params, API_PASTE_FORMAT, format.getValue()); setParameter(params, API_PASTE_CODE, code); - final HttpPost request = new HttpPost("http://pastebin.com/api/api_post.php"); + final HttpPost request = new HttpPost(API_POST_URL); request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); final HttpResponse response = this.httpClient.execute(request); - final String content = IOUtils.toString(response.getEntity().getContent()); - APIException.throwIfError(content); - return content; + result = IOUtils.toString(response.getEntity().getContent()); + APIException.throwIfError(result); + + // + return result; } + /** + * Paste. + * + * @param code + * the code + * @param name + * the name + * @param privat + * the privat + * @return the string + * @throws Exception + * the exception + */ public String paste(final String code, final String name, final Private privat) throws Exception { - return this.paste(code, name, Format.NONE, privat, Expiration.DAY_1); + String result; + + result = this.paste(code, name, Format.NONE, privat, Expiration.DAY_1); + + // + return result; } + /** + * Sets the parameter. + * + * @param params + * the params + * @param name + * the name + * @param value + * the value + */ private static void setParameter(final List params, final String name, final String value) { if (value == null) diff --git a/src/main/java/fr/imirhil/april/hebdobot/pastebin/Private.java b/src/main/java/fr/imirhil/april/hebdobot/pastebin/Private.java index dd8a1f8..a995fb5 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/pastebin/Private.java +++ b/src/main/java/fr/imirhil/april/hebdobot/pastebin/Private.java @@ -19,6 +19,9 @@ */ package fr.imirhil.april.hebdobot.pastebin; +/** + * The Enum Private. + */ public enum Private { PUBLIC("0"), @@ -27,11 +30,22 @@ public enum Private private String value; + /** + * Instantiates a new private. + * + * @param value + * the value + */ private Private(final String value) { this.value = value; } + /** + * Gets the value. + * + * @return the value + */ String getValue() { return this.value; diff --git a/src/main/java/fr/imirhil/april/hebdobot/review/CollectiveTopic.java b/src/main/java/fr/imirhil/april/hebdobot/review/CollectiveTopic.java index 4f4c36c..505e3bb 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/review/CollectiveTopic.java +++ b/src/main/java/fr/imirhil/april/hebdobot/review/CollectiveTopic.java @@ -24,26 +24,46 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; +/** + * The Class CollectiveTopic. + */ public class CollectiveTopic extends Topic { private final List messages = new LinkedList(); + /** + * Instantiates a new collective topic. + * + * @param title + * the title + */ public CollectiveTopic(final String title) { super(title); } + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.review.Topic#add(fr.imirhil.april.hebdobot.review.Message) + */ @Override public void add(final Message message) { this.messages.add(message); } + /** + * Gets the messages. + * + * @return the messages + */ public List getMessages() { return this.messages; } + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.review.Topic#getParticipants() + */ @Override public Set getParticipants() { diff --git a/src/main/java/fr/imirhil/april/hebdobot/review/IndividualTopic.java b/src/main/java/fr/imirhil/april/hebdobot/review/IndividualTopic.java index c77ad63..a637b14 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/review/IndividualTopic.java +++ b/src/main/java/fr/imirhil/april/hebdobot/review/IndividualTopic.java @@ -25,15 +25,27 @@ import java.util.List; import java.util.Map; import java.util.Set; +/** + * The Class IndividualTopic. + */ public class IndividualTopic extends Topic { private final Map> messages = new HashMap>(); + /** + * Instantiates a new individual topic. + * + * @param title + * the title + */ public IndividualTopic(final String title) { super(title); } + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.review.Topic#add(fr.imirhil.april.hebdobot.review.Message) + */ @Override public void add(final Message message) { @@ -45,17 +57,34 @@ public class IndividualTopic extends Topic this.messages.get(author).add(message); } + /** + * Gets the messages. + * + * @param author + * the author + * @return the messages + */ public List getMessages(final String author) { return this.messages.get(author); } + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.review.Topic#getParticipants() + */ @Override public Set getParticipants() { return this.messages.keySet(); } + /** + * Checks for participant. + * + * @param participant + * the participant + * @return true, if successful + */ public boolean hasParticipant(final String participant) { return this.messages.containsKey(participant); diff --git a/src/main/java/fr/imirhil/april/hebdobot/review/Message.java b/src/main/java/fr/imirhil/april/hebdobot/review/Message.java index c6db78d..fcf7399 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/review/Message.java +++ b/src/main/java/fr/imirhil/april/hebdobot/review/Message.java @@ -21,28 +21,54 @@ package fr.imirhil.april.hebdobot.review; import org.joda.time.DateTime; +/** + * The Class Message. + */ public class Message { private final DateTime date = new DateTime(); private final String author; private final String content; + /** + * Instantiates a new message. + * + * @param author + * the author + * @param content + * the content + */ public Message(final String author, final String content) { this.author = author; this.content = content; } + /** + * Gets the author. + * + * @return the author + */ public String getAuthor() { return this.author; } + /** + * Gets the content. + * + * @return the content + */ public String getContent() { return this.content; } + /** + * Gets the date. + * + * @return the date + */ public DateTime getDate() { return this.date; diff --git a/src/main/java/fr/imirhil/april/hebdobot/review/Review.java b/src/main/java/fr/imirhil/april/hebdobot/review/Review.java index 05d8c43..e6bb250 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/review/Review.java +++ b/src/main/java/fr/imirhil/april/hebdobot/review/Review.java @@ -32,23 +32,43 @@ import org.joda.time.format.DateTimeFormat; import fr.imirhil.april.hebdobot.Context; import fr.imirhil.april.hebdobot.xml.UserAlias; +/** + * The Class Review. + */ public class Review { private static final int LENGTH = 80; private static final UserAlias USER_ALIAS = Context.getBean(UserAlias.class); - private final Set participants = new HashSet(); - private final List individualTopics = new LinkedList(); - private final List collectiveTopics = new LinkedList(); + private final Set participants; + private final List individualTopics; + private final List collectiveTopics; private Topic currentTopic; - private final List messages = new LinkedList(); + private final List messages; private final String owner; + /** + * Instantiates a new review. + * + * @param owner + * the owner + */ public Review(final String owner) { + this.participants = new HashSet(); + this.individualTopics = new LinkedList(); + this.collectiveTopics = new LinkedList(); + this.messages = new LinkedList(); + this.owner = owner; } + /** + * Adds the. + * + * @param message + * the message + */ public void add(final Message message) { if (this.currentTopic != null) @@ -59,55 +79,105 @@ public class Review this.addRaw(message); } + /** + * Adds the raw. + * + * @param message + * the message + */ public void addRaw(final Message message) { this.messages.add(message); } + /** + * Begin. + * + * @param topic + * the topic + */ public void begin(final CollectiveTopic topic) { this.collectiveTopics.add(topic); this.currentTopic = topic; } + /** + * Begin. + * + * @param topic + * the topic + */ public void begin(final IndividualTopic topic) { this.individualTopics.add(topic); this.currentTopic = topic; } + /** + * Gets the current topic. + * + * @return the current topic + */ public Topic getCurrentTopic() { return this.currentTopic; } + /** + * Gets the owner. + * + * @return the owner + */ public String getOwner() { return this.owner; } + /** + * Gets the participants. + * + * @return the participants + */ public Collection getParticipants() { - final Collection reviewers = new HashSet(); + Collection result; + + result = new HashSet(); + for (final Topic topic : this.individualTopics) { - reviewers.addAll(topic.getParticipants()); + result.addAll(topic.getParticipants()); } + for (final Topic topic : this.collectiveTopics) { - reviewers.addAll(topic.getParticipants()); + result.addAll(topic.getParticipants()); } - return reviewers; + + return result; } + /** + * Checks if is owner. + * + * @param name + * the name + * @return true, if is owner + */ public boolean isOwner(final String name) { return this.owner.equalsIgnoreCase(name); } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ @Override public String toString() { + String result; + final StringBuffer buffer = new StringBuffer(); addLine(buffer, '='); addCenter(buffer, "Revue de la semaine en cours"); @@ -173,59 +243,128 @@ public class Review addChunk(buffer, "* " + message.getAuthor() + " : " + message.getContent() + "\n"); } - return buffer.toString(); + result = buffer.toString(); + + // + return result; } + /** + * Adds the. + * + * @param buffer + * the buffer + * @param content + * the content + */ private static void add(final StringBuffer buffer, final String content) { buffer.append(content); } + /** + * Adds the center. + * + * @param buffer + * the buffer + * @param content + * the content + */ private static void addCenter(final StringBuffer buffer, final String content) { addCenter(buffer, content, ' '); } + /** + * Adds the center. + * + * @param buffer + * the buffer + * @param content + * the content + * @param c + * the c + */ private static void addCenter(final StringBuffer buffer, final String content, final char c) { buffer.append(getLine(content, c)); } + /** + * Adds the chunk. + * + * @param buffer + * the buffer + * @param content + * the content + */ private static void addChunk(final StringBuffer buffer, final String content) { add(buffer, chunk(content)); } + /** + * Adds the empty. + * + * @param buffer + * the buffer + */ private static void addEmpty(final StringBuffer buffer) { buffer.append("\n"); } + /** + * Adds the line. + * + * @param buffer + * the buffer + * @param c + * the c + */ private static void addLine(final StringBuffer buffer, final char c) { buffer.append(getLine(c)); } + /** + * Chunk. + * + * @param content + * the content + * @return the string + */ private static String chunk(final String content) { return chunk(content, LENGTH); } + /** + * Chunk. + * + * @param content + * the content + * @param length + * the length + * @return the string + */ private static String chunk(final String content, final int length) { + String result; + final String[] words = content.split(" "); - final StringBuffer result = new StringBuffer(); + final StringBuffer buffer = new StringBuffer(); StringBuffer current = new StringBuffer(); for (final String word : words) { if (current.length() + word.length() > length) { - if (result.length() > 0) + if (buffer.length() > 0) { - result.append("\n"); + buffer.append("\n"); } - result.append(current); + buffer.append(current); current = new StringBuffer(word); } else @@ -240,29 +379,70 @@ public class Review if (current.length() > 0) { - if (result.length() > 0) + if (buffer.length() > 0) { - result.append("\n"); + buffer.append("\n"); } - result.append(current); + buffer.append(current); } - return result.toString(); + result = buffer.toString(); + + // + return result; } - private static String getLine(final Character c) + /** + * Gets the line. + * + * @param letter + * the letter + * @return the line + */ + private static String getLine(final Character letter) { - return StringUtils.repeat(c.toString(), LENGTH) + "\n"; + String result; + + result = StringUtils.repeat(letter.toString(), LENGTH) + "\n"; + + // + return result; } - private static String getLine(final String content, final char c) + /** + * Gets the line. + * + * @param content + * the content + * @param letter + * the c + * @return the line + */ + private static String getLine(final String content, final char letter) { - return StringUtils.center(" " + content + " ", LENGTH, c) + "\n"; + String result; + + result = StringUtils.center(" " + content + " ", LENGTH, letter) + "\n"; + + // + return result; } + /** + * Gets the topic. + * + * @param topic + * the topic + * @return the topic + */ private static String getTopic(final Topic topic) { - return "=== " + topic.getTitle() + " ===\n"; + String result; + + result = "=== " + topic.getTitle() + " ===\n"; + + // + return result; } } diff --git a/src/main/java/fr/imirhil/april/hebdobot/review/Topic.java b/src/main/java/fr/imirhil/april/hebdobot/review/Topic.java index 33f7b37..4091338 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/review/Topic.java +++ b/src/main/java/fr/imirhil/april/hebdobot/review/Topic.java @@ -21,19 +21,44 @@ package fr.imirhil.april.hebdobot.review; import java.util.Set; +/** + * The Class Topic. + */ public abstract class Topic { private final String title; + /** + * Instantiates a new topic. + * + * @param title + * the title + */ protected Topic(final String title) { this.title = title; } + /** + * Adds the. + * + * @param message + * the message + */ public abstract void add(Message message); + /** + * Gets the participants. + * + * @return the participants + */ public abstract Set getParticipants(); + /** + * Gets the title. + * + * @return the title + */ public String getTitle() { return this.title; diff --git a/src/main/java/fr/imirhil/april/hebdobot/xml/UserAlias.java b/src/main/java/fr/imirhil/april/hebdobot/xml/UserAlias.java index 4a044f1..6911205 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/xml/UserAlias.java +++ b/src/main/java/fr/imirhil/april/hebdobot/xml/UserAlias.java @@ -34,10 +34,19 @@ import javax.xml.validation.SchemaFactory; import org.jibble.pircbot.User; import org.xml.sax.SAXException; +/** + * The Class UserAlias. + */ public class UserAlias { private final Map aliases = new HashMap(); + /** + * Instantiates a new user alias. + * + * @param source + * the source + */ public UserAlias(final InputStream source) { try @@ -55,18 +64,25 @@ public class UserAlias } } } - catch (final SAXException e) + catch (final SAXException exception) { - e.printStackTrace(); - throw new RuntimeException(e); + exception.printStackTrace(); + throw new RuntimeException(exception); } - catch (final JAXBException e) + catch (final JAXBException exception) { - e.printStackTrace(); - throw new RuntimeException(e); + exception.printStackTrace(); + throw new RuntimeException(exception); } } + /** + * Gets the real name. + * + * @param nick + * the nick + * @return the real name + */ public String getRealName(final String nick) { for (final Entry entry : this.aliases.entrySet()) diff --git a/src/test/java/fr/imirhil/april/hebdobot/irc/BotTest.java b/src/test/java/fr/imirhil/april/hebdobot/irc/BotTest.java index c77fdd4..4fc889d 100644 --- a/src/test/java/fr/imirhil/april/hebdobot/irc/BotTest.java +++ b/src/test/java/fr/imirhil/april/hebdobot/irc/BotTest.java @@ -38,17 +38,32 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import fr.imirhil.april.hebdobot.review.Review; +/** + * The Class BotTest. + */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "/fr/imirhil/april/hebdobot/conf.xml") public class BotTest implements ReviewListener { + /** + * The Class BotMock. + */ private static class BotMock extends Bot { + /** + * Instantiates a new bot mock. + * + * @throws Exception + * the exception + */ public BotMock() throws Exception { super("", 0, "bot", "channel"); } + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.irc.Bot#onMessage(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + */ @Override public void onMessage(final String channel, final String sender, final String login, final String hostname, final String message) { @@ -56,6 +71,9 @@ public class BotTest implements ReviewListener } } + /* (non-Javadoc) + * @see fr.imirhil.april.hebdobot.irc.ReviewListener#onEnd(fr.imirhil.april.hebdobot.review.Review) + */ @Override public void onEnd(final Review review) { @@ -66,12 +84,18 @@ public class BotTest implements ReviewListener final File file = new File("target/" + date + "_revue.txt"); FileUtils.writeStringToFile(file, text); } - catch (final IOException e) + catch (final IOException exception) { - throw new RuntimeException(e); + throw new RuntimeException(exception); } } + /** + * Redo. + * + * @throws Exception + * the exception + */ @Test public void redo() throws Exception { diff --git a/src/test/java/fr/imirhil/april/hebdobot/pastebin/PastebinClientTest.java b/src/test/java/fr/imirhil/april/hebdobot/pastebin/PastebinClientTest.java index 7dcd750..7bb90a5 100644 --- a/src/test/java/fr/imirhil/april/hebdobot/pastebin/PastebinClientTest.java +++ b/src/test/java/fr/imirhil/april/hebdobot/pastebin/PastebinClientTest.java @@ -21,10 +21,19 @@ package fr.imirhil.april.hebdobot.pastebin; import org.junit.Test; +/** + * The Class PastebinClientTest. + */ public class PastebinClientTest { private final PastebinClient client = new PastebinClient("b95ea42d539ec9dca02a7da1f5b229c7"); + /** + * Test paste. + * + * @throws Exception + * the exception + */ @Test public void testPaste() throws Exception {