/** * Copyright (C) 2017-2021 Christian Pierre MOMON * Copyright (C) 2011-2013 Nicolas Vinot * * This file is part of (April) Hebdobot. * * Hebdobot is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Hebdobot is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Hebdobot. If not, see */ package org.april.hebdobot.bot.review; import fr.devinsy.strings.StringSet; /** * The Class IndividualTopic. */ public class IndividualTopic extends Topic { private final MessageMap messages; /** * Instantiates a new individual topic. * * @param title * the title */ public IndividualTopic(final String title) { super(title); this.messages = new MessageMap(); } /* (non-Javadoc) * @see org.april.hebdobot.review.Topic#add(org.april.hebdobot.review.Message) */ @Override public void add(final Message message) { final String author = message.getAuthor(); if (!this.messages.containsKey(author)) { this.messages.put(author, new Messages()); } this.messages.get(author).add(message); } /* (non-Javadoc) * @see org.april.hebdobot.bot.review.Topic#cancelPrevious(java.lang.String) */ @Override public String cancelPreviousMessage(final String participant) { String result; Messages authorMessages = this.messages.get(participant); if (authorMessages == null) { result = null; } else { Message removed = authorMessages.removeLast(); result = removed.getContent(); } // return result; } /** * Gets the messages. * * @param author * the author * @return the messages */ public Messages getMessages(final String author) { Messages result; result = this.messages.get(author); // return result; } /* (non-Javadoc) * @see org.april.hebdobot.review.Topic#getParticipants() */ @Override public StringSet getParticipants() { StringSet result; result = new StringSet(this.messages.keySet()); // return result; } /** * Checks for message. * * @param participant * the participant * @return true, if successful */ @Override public boolean hasMessage(final String participant) { boolean result; Messages messages = this.messages.get(participant); if ((messages == null) || (messages.isEmpty())) { result = false; } else { result = true; } // return result; } /** * Checks for participant. * * @param participant * the participant * @return true, if successful */ public boolean hasParticipant(final String participant) { boolean result; result = this.messages.containsKey(participant); // return result; } }