Package adams.data.statistics
Class Percentile<E extends Comparable>
- java.lang.Object
-
- adams.data.statistics.Percentile<E>
-
- Type Parameters:
E
- The type of element to store in the container
- All Implemented Interfaces:
Serializable
public class Percentile<E extends Comparable> extends Object implements Serializable
Container class for sortable values, which allows to extract percentiles and percentiles.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Comparator
m_Comparator
a custom comparator.protected boolean
m_Sorted
whether the vector has been sorted already.protected List<E>
m_Values
contains the values to obtain the percentile from.
-
Constructor Summary
Constructors Constructor Description Percentile()
Initializes the container.Percentile(Comparator comparator)
Initializes the container with a custom comparator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(E value)
Adds the value to the internal list of values.void
addAll(E[] values)
Adds the values to the internal list of values.void
addAll(Collection<E> values)
Adds the values to the internal list of values.void
clear()
Removes all values.E
getPercentile(double percentage)
Returns the specified percentile.List<E>
getValues()
Returns the currently stored values.int
size()
Returns the number of stored values.protected void
sort()
Sorts the values, if necessary.String
toString()
Returns the stored values as string.
-
-
-
Field Detail
-
m_Values
protected List<E extends Comparable> m_Values
contains the values to obtain the percentile from.
-
m_Sorted
protected boolean m_Sorted
whether the vector has been sorted already.
-
m_Comparator
protected Comparator m_Comparator
a custom comparator.
-
-
Constructor Detail
-
Percentile
public Percentile()
Initializes the container.
-
Percentile
public Percentile(Comparator comparator)
Initializes the container with a custom comparator.- Parameters:
comparator
- the comparator to use for sorting, use null to use default sorting
-
-
Method Detail
-
add
public void add(E value)
Adds the value to the internal list of values.- Parameters:
value
- the value to add
-
addAll
public void addAll(Collection<E> values)
Adds the values to the internal list of values.- Parameters:
values
- the values to add
-
addAll
public void addAll(E[] values)
Adds the values to the internal list of values.- Parameters:
values
- the values to add
-
getValues
public List<E> getValues()
Returns the currently stored values.- Returns:
- the current values
-
sort
protected void sort()
Sorts the values, if necessary.
-
getPercentile
public E getPercentile(double percentage)
Returns the specified percentile. Math.round(...) is used to determine the index of the percentile.- Parameters:
percentage
- the percentage of the percentile (e.g., Q1: 0.25, Q3: 0.75)- Returns:
- the corresponding value or null if no percentile could be computed
-
clear
public void clear()
Removes all values.
-
size
public int size()
Returns the number of stored values.- Returns:
- the number of stored values
-
-