Class Percentile<E extends Comparable>

  • 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 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
      • toString

        public String toString()
        Returns the stored values as string.
        Overrides:
        toString in class Object
        Returns:
        the values as string