187 lines
3.9 KiB
Java
187 lines
3.9 KiB
Java
/**
|
|
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
|
|
*
|
|
* 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.model.stats;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Iterator;
|
|
|
|
import org.april.hebdobot.model.stats.ReviewDataComparator.Sorting;
|
|
|
|
/**
|
|
* The Class Stats.
|
|
*/
|
|
public class ReviewDatas extends ArrayList<ReviewData>
|
|
{
|
|
private static final long serialVersionUID = 326880908257489774L;
|
|
|
|
/**
|
|
* Instantiates a new ReviewDatas.
|
|
*/
|
|
public ReviewDatas()
|
|
{
|
|
super();
|
|
}
|
|
|
|
/**
|
|
* Clean.
|
|
*
|
|
* @return the int
|
|
*/
|
|
public int clean()
|
|
{
|
|
int result;
|
|
|
|
result = 0;
|
|
Iterator<ReviewData> iterator = iterator();
|
|
while (iterator.hasNext())
|
|
{
|
|
if (iterator.next().getUserCount() < 2)
|
|
{
|
|
iterator.remove();
|
|
result += 1;
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the last by max user count.
|
|
*
|
|
* @return the last by max user count
|
|
*/
|
|
public ReviewData getLastByMaxUserCount()
|
|
{
|
|
ReviewData result;
|
|
|
|
if (isEmpty())
|
|
{
|
|
result = null;
|
|
}
|
|
else
|
|
{
|
|
int max = Integer.MIN_VALUE;
|
|
result = null;
|
|
for (ReviewData data : this)
|
|
{
|
|
if (data.getUserCount() > max)
|
|
{
|
|
max = data.getUserCount();
|
|
result = data;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the max user count.
|
|
*
|
|
* @return the max user count
|
|
*/
|
|
public int getMaxUserCount()
|
|
{
|
|
int result;
|
|
|
|
if (isEmpty())
|
|
{
|
|
result = 0;
|
|
}
|
|
else
|
|
{
|
|
result = Integer.MIN_VALUE;
|
|
for (ReviewData data : this)
|
|
{
|
|
if (data.getUserCount() > result)
|
|
{
|
|
result = data.getUserCount();
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the min user count.
|
|
*
|
|
* @return the min user count
|
|
*/
|
|
public int getMinUserCount()
|
|
{
|
|
int result;
|
|
|
|
if (isEmpty())
|
|
{
|
|
result = 0;
|
|
}
|
|
else
|
|
{
|
|
result = Integer.MAX_VALUE;
|
|
for (ReviewData data : this)
|
|
{
|
|
if (data.getUserCount() < result)
|
|
{
|
|
result = data.getUserCount();
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Reverse.
|
|
*/
|
|
public void reverse()
|
|
{
|
|
Collections.reverse(this);
|
|
}
|
|
|
|
/**
|
|
* Sort by date.
|
|
*/
|
|
public void sortByDate()
|
|
{
|
|
Collections.sort(this, new ReviewDataComparator(Sorting.DATE));
|
|
}
|
|
|
|
/**
|
|
* Sort by duration.
|
|
*/
|
|
public void sortByDuration()
|
|
{
|
|
Collections.sort(this, new ReviewDataComparator(Sorting.DURATION));
|
|
}
|
|
|
|
/**
|
|
* Sort by user count.
|
|
*/
|
|
public void sortByUserCount()
|
|
{
|
|
Collections.sort(this, new ReviewDataComparator(Sorting.USERCOUNT));
|
|
}
|
|
}
|