hebdobot/src/org/april/hebdobot/bot/review/Review.java

357 lines
7.1 KiB
Java

/**
* Copyright (C) 2017-2019 Christian Pierre MOMON <cmomon@april.org>
* Copyright (C) 2011-2013 Nicolas Vinot <aeris@imirhil.fr>
*
* 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 <http://www.gnu.org/licenses/>
*/
package org.april.hebdobot.bot.review;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import org.april.hebdobot.bot.UserAliases;
import fr.devinsy.strings.StringSet;
/**
* The Class Review.
*/
public class Review
{
private static final int LENGTH = 80;
private final StringSet participants;
private final IndividualTopics individualTopics;
private final CollectiveTopics collectiveTopics;
private Topic currentTopic;
private final MessageList messages;
private final String owner;
private final UserAliases aliases;
private final LocalDateTime startTime;
private LocalDateTime endTime;
/**
* Instantiates a new review.
*
* @param owner
* the owner
* @param aliases
* the aliases
*/
public Review(final String owner, final UserAliases aliases)
{
this.participants = new StringSet();
this.individualTopics = new IndividualTopics();
this.collectiveTopics = new CollectiveTopics();
this.messages = new MessageList();
this.owner = owner;
this.aliases = aliases;
this.startTime = LocalDateTime.now();
this.endTime = null;
}
/**
* Adds the.
*
* @param message
* the message
*/
public void add(final Message message)
{
if (this.currentTopic != null)
{
this.participants.add(message.getAuthor());
this.currentTopic.add(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;
}
/**
* End review.
*/
public void endReview()
{
this.endTime = LocalDateTime.now();
}
public UserAliases getAliases()
{
return this.aliases;
}
/**
* Gets the collective topics.
*
* @return the collective topics
*/
public CollectiveTopics getCollectiveTopics()
{
return this.collectiveTopics;
}
/**
* Gets the current topic.
*
* @return the current topic
*/
public Topic getCurrentTopic()
{
return this.currentTopic;
}
/**
* Gets the duration.
*
* @return the duration
*/
public long getDuration()
{
long result;
if (this.endTime == null)
{
result = Duration.between(this.startTime, LocalDateTime.now()).getSeconds();
}
else
{
result = Duration.between(this.startTime, this.endTime).getSeconds();
}
//
return result;
}
/**
* Gets the duration.
*
* @return the duration
*/
public long getDurationInMinutes()
{
long result;
result = (long) Math.ceil(getDuration() / 60.0);
//
return result;
}
/**
* Gets the end time.
*
* @return the end time
*/
public LocalDateTime getEndTime()
{
return this.endTime;
}
/**
* Gets the formatted end time.
*
* @return the formatted end time
*/
public String getFormattedEndTime()
{
String result;
if (this.endTime == null)
{
result = "??h??";
}
else
{
result = this.endTime.format(DateTimeFormatter.ofPattern("kk'h'mm"));
}
//
return result;
}
/**
* Gets the formatted start time.
*
* @return the formatted start time
*/
public String getFormattedStartTime()
{
String result;
result = this.startTime.format(DateTimeFormatter.ofPattern("kk'h'mm"));
//
return result;
}
/**
* Gets the individual topics.
*
* @return the individual topics
*/
public IndividualTopics getIndividualTopics()
{
return this.individualTopics;
}
public MessageList getMessages()
{
return this.messages;
}
/**
* Gets the owner.
*
* @return the owner
*/
public String getOwner()
{
return this.owner;
}
/**
* Gets the participants.
*
* @return the participants
*/
public StringSet getParticipants()
{
StringSet result;
result = new StringSet();
for (final Topic topic : this.individualTopics)
{
result.addAll(topic.getParticipants());
}
for (final Topic topic : this.collectiveTopics)
{
result.addAll(topic.getParticipants());
}
//
return result;
}
/**
* Gets the start time.
*
* @return the start time
*/
public LocalDateTime getStartTime()
{
return this.startTime;
}
/**
* Checks if is empty.
*
* @return true, if is empty
*/
public boolean isEmpty()
{
boolean result;
if ((this.individualTopics.isEmpty()) && (this.collectiveTopics.isEmpty()))
{
result = true;
}
else
{
result = false;
}
//
return result;
}
/**
* Checks if is ended.
*
* @return true, if is ended
*/
public boolean isEnded()
{
boolean result;
if (this.endTime == null)
{
result = false;
}
else
{
result = true;
}
//
return result;
}
/**
* Checks if is owner.
*
* @param name
* the name
* @return true, if is owner
*/
public boolean isOwner(final String name)
{
boolean result;
result = this.owner.equalsIgnoreCase(name);
//
return result;
}
}