agirstatool/src/org/april/agirstatool/core/LongList.java

77 lines
1.5 KiB
Java

/*
* Copyright (C) 2021 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of AgirStatool, simple key value database.
*
* AgirStatool 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.
*
* AgirStatool 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 AgirStatool. If not, see <http://www.gnu.org/licenses/>.
*/
package org.april.agirstatool.core;
import java.util.ArrayList;
import java.util.Collections;
/**
* The Class LongList.
*/
public class LongList extends ArrayList<Long>
{
private static final long serialVersionUID = 2724688980125113107L;
/**
* Instantiates a new stat.
*/
public LongList()
{
super();
}
/**
* Median.
*
* @return the double
*/
public double median()
{
double result;
sort();
if (this.isEmpty())
{
result = 0;
}
else if (this.size() % 2 == 0)
{
long a = get(this.size() / 2 - 1);
long b = get(this.size() / 2);
result = (a + b) / 2;
}
else
{
result = get(this.size() / 2);
}
//
return result;
}
/**
* Sort.
*/
public void sort()
{
Collections.sort(this);
}
}