Class DoubleList

  • All Implemented Interfaces:
    Iterable<Double>

    public class DoubleList
    extends Object
    implements Iterable<Double>
    Helper class for a list of floats. Lists are designed to have some of the features of ArrayLists, but to maintain the simplicity and efficiency of working with arrays. Functions like sort() and shuffle() always act on the list itself. To get a sorted copy, use list.copy().sort().
    See Also:
    IntList, StringList
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int index, double amount)  
      void append​(double value)
      Add a new entry to the list.
      void append​(double[] values)  
      void append​(DoubleList list)  
      void appendUnique​(double value)
      Add this value, but only if it's not already in the list.
      double[] array()
      Create a new array with a copy of all the values.
      double[] array​(double[] array)
      Copy values into the specified array.
      void clear()
      Remove all entries from the list.
      DoubleList copy()  
      void div​(int index, double amount)  
      double get​(int index)
      Get an entry at a particular index.
      DoubleList getPercent()
      Returns a normalized version of this array.
      DoubleList getSubset​(int start)  
      DoubleList getSubset​(int start, int num)  
      boolean hasValue​(double value)  
      int index​(double what)
      Return the first index of a particular value.
      void insert​(int index, double value)  
      void insert​(int index, double[] values)  
      void insert​(int index, DoubleList list)  
      Iterator<Double> iterator()
      Implemented this way so that we can use a FloatList in a for loop.
      String join​(String separator)  
      double max()  
      int maxIndex()  
      double min()  
      int minIndex()  
      void mult​(int index, double amount)  
      double pop()  
      void print()  
      void push​(double value)
      Just an alias for append(), but matches pop()
      double remove​(int index)
      Remove an element from the specified index.
      int removeValue​(int value)  
      int removeValues​(int value)  
      boolean replaceValue​(double value, double newValue)
      Replace the first instance of a particular value
      boolean replaceValues​(double value, double newValue)
      Replace all instances of a particular value
      void resize​(int length)  
      void reverse()  
      void save​(File file)
      Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
      void set​(int index, double what)
      Set the entry at a particular index.
      void shuffle()
      Randomize the order of the list elements.
      void shuffle​(PApplet sketch)
      Randomize the list order using the random() function from the specified sketch, allowing shuffle() to use its current randomSeed() setting.
      int size()
      Get the length of the list.
      void sort()
      Sorts the array in place.
      void sortReverse()
      Reverse sort, orders values from highest to lowest
      void sub​(int index, double amount)  
      double sum()  
      String toJSON()
      Return this dictionary as a String in JSON format.
      String toString()  
      double[] values()
      Returns the actual array being used to store the data.
      void write​(PrintWriter writer)
      Write entries to a PrintWriter, one per line
    • Constructor Detail

      • DoubleList

        public DoubleList()
      • DoubleList

        public DoubleList​(int length)
      • DoubleList

        public DoubleList​(double[] list)
      • DoubleList

        public DoubleList​(Iterable<Object> iter)
        Construct an FloatList from an iterable pile of objects. For instance, a double array, an array of strings, who knows). Un-parseable or null values will be set to NaN.
      • DoubleList

        public DoubleList​(Object... items)
        Construct an FloatList from a random pile of objects. Un-parseable or null values will be set to NaN.
    • Method Detail

      • size

        public int size()
        Get the length of the list.
      • resize

        public void resize​(int length)
      • clear

        public void clear()
        Remove all entries from the list.
      • get

        public double get​(int index)
        Get an entry at a particular index.
      • set

        public void set​(int index,
                        double what)
        Set the entry at a particular index. If the index is past the length of the list, it'll expand the list to accommodate, and fill the intermediate entries with 0s.
      • push

        public void push​(double value)
        Just an alias for append(), but matches pop()
      • pop

        public double pop()
      • remove

        public double remove​(int index)
        Remove an element from the specified index.
      • removeValue

        public int removeValue​(int value)
      • removeValues

        public int removeValues​(int value)
      • replaceValue

        public boolean replaceValue​(double value,
                                    double newValue)
        Replace the first instance of a particular value
      • replaceValues

        public boolean replaceValues​(double value,
                                     double newValue)
        Replace all instances of a particular value
      • append

        public void append​(double value)
        Add a new entry to the list.
      • append

        public void append​(double[] values)
      • append

        public void append​(DoubleList list)
      • appendUnique

        public void appendUnique​(double value)
        Add this value, but only if it's not already in the list.
      • insert

        public void insert​(int index,
                           double value)
      • insert

        public void insert​(int index,
                           double[] values)
      • insert

        public void insert​(int index,
                           DoubleList list)
      • index

        public int index​(double what)
        Return the first index of a particular value.
      • hasValue

        public boolean hasValue​(double value)
      • add

        public void add​(int index,
                        double amount)
      • sub

        public void sub​(int index,
                        double amount)
      • mult

        public void mult​(int index,
                         double amount)
      • div

        public void div​(int index,
                        double amount)
      • min

        public double min()
      • minIndex

        public int minIndex()
      • max

        public double max()
      • maxIndex

        public int maxIndex()
      • sum

        public double sum()
      • sort

        public void sort()
        Sorts the array in place.
      • sortReverse

        public void sortReverse()
        Reverse sort, orders values from highest to lowest
      • reverse

        public void reverse()
      • shuffle

        public void shuffle()
        Randomize the order of the list elements. Note that this does not obey the randomSeed() function in PApplet.
      • shuffle

        public void shuffle​(PApplet sketch)
        Randomize the list order using the random() function from the specified sketch, allowing shuffle() to use its current randomSeed() setting.
      • values

        public double[] values()
        Returns the actual array being used to store the data. For advanced users, this is the fastest way to access a large list. Suitable for iterating with a for() loop, but modifying the list will have terrible consequences.
      • array

        public double[] array()
        Create a new array with a copy of all the values.
        Returns:
        an array sized by the length of the list with each of the values.
      • array

        public double[] array​(double[] array)
        Copy values into the specified array. If the specified array is null or not the same size, a new array will be allocated.
        Parameters:
        array -
      • getPercent

        public DoubleList getPercent()
        Returns a normalized version of this array. Called getPercent() for consistency with the Dict classes. It's a getter method because it needs to returns a new list (because IntList/Dict can't do percentages or normalization in place on int values).
      • getSubset

        public DoubleList getSubset​(int start)
      • getSubset

        public DoubleList getSubset​(int start,
                                    int num)
      • print

        public void print()
      • save

        public void save​(File file)
        Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
      • write

        public void write​(PrintWriter writer)
        Write entries to a PrintWriter, one per line
      • toJSON

        public String toJSON()
        Return this dictionary as a String in JSON format.