Class FloatList

java.lang.Object
processing.data.FloatList
All Implemented Interfaces:
Iterable<Float>

public class FloatList extends Object implements Iterable<Float>
Helper class for a list of float values. Lists are designed to have some features of ArrayList, but to maintain the simplicity and efficiency of working with arrays. Functions such as sort() and shuffle() always act on the list itself. To get a sorted copy, use list.copy().sort().
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    FloatList(float[] list)
     
    FloatList(int length)
     
    Construct an FloatList from an iterable pile of objects.
    FloatList(Object... items)
    Construct an FloatList from a random pile of objects.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int index, float amount)
    Add to a value.
    void
    append(float value)
    Add a new entry to the list.
    void
    append(float[] values)
     
    void
     
    void
    appendUnique(float value)
    Add this value, but only if it's not already in the list.
    float[]
    Deprecated.
    float[]
    array(float[] array)
    Deprecated.
    void
    Remove all entries from the list.
     
    void
    div(int index, float amount)
    Divide a value
    float
    get(int index)
    Get an entry at a particular index.
    Returns a normalized version of this array.
    getSubset(int start)
     
    getSubset(int start, int num)
     
    boolean
    hasValue(float value)
    Check if a number is a part of the list.
    int
    index(float what)
    Return the first index of a particular value.
    void
    insert(int index, float value)
     
    void
    insert(int index, float[] values)
     
    void
    insert(int index, FloatList list)
     
    Implemented this way so that we can use a FloatList in a for loop.
    join(String separator)
     
    float
    max()
    Return the largest value
    int
     
    float
    min()
    Return the smallest value
    int
     
    void
    mult(int index, float amount)
    Multiply a value
    float
    pop()
     
    void
     
    void
    push(float value)
    Just an alias for append(), but matches pop()
    float
    Return a random value from the list.
    float
    remove(int index)
    Remove an element from the specified index.
    float
     
    int
    removeValue(int value)
     
    int
    removeValues(float value)
     
    boolean
    replaceValue(float value, float newValue)
    Replace the first instance of a particular value
    boolean
    replaceValues(float value, float newValue)
    Replace all instances of a particular value
    void
    resize(int length)
     
    void
    Reverse the order of the list
    void
    save(File file)
    Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
    void
    set(int index, float what)
    Set the entry at a particular index.
    void
    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
    Get the length of the list.
    void
    Sorts an array, lowest to highest
    void
    A sort in reverse.
    void
    sub(int index, float amount)
    Subtract from a value
    float
    sum()
     
    double
     
    float[]
    Create a new array with a copy of all the values.
    float[]
    toArray(float[] array)
    Copy values into the specified array.
    Return this dictionary as a String in JSON format.
     
    float[]
    Returns the actual array being used to store the data.
    void
    Write entries to a PrintWriter, one per line

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • FloatList

      public FloatList()
    • FloatList

      public FloatList(int length)
    • FloatList

      public FloatList(float[] list)
    • FloatList

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

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

    • 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 float get(int index)
      Get an entry at a particular index.
    • set

      public void set(int index, float what)
      Set the entry at a particular index.
    • push

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

      public float pop()
    • remove

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

      public int removeValue(int value)
    • removeValues

      public int removeValues(float value)
    • replaceValue

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

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

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

      public void append(float[] values)
    • append

      public void append(FloatList list)
    • appendUnique

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

      public void insert(int index, float value)
    • insert

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

      public void insert(int index, FloatList list)
    • index

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

      public boolean hasValue(float value)
      Check if a number is a part of the list.
    • add

      public void add(int index, float amount)
      Add to a value.
    • sub

      public void sub(int index, float amount)
      Subtract from a value
    • mult

      public void mult(int index, float amount)
      Multiply a value
    • div

      public void div(int index, float amount)
      Divide a value
    • min

      public float min()
      Return the smallest value
    • minIndex

      public int minIndex()
    • max

      public float max()
      Return the largest value
    • maxIndex

      public int maxIndex()
    • sum

      public float sum()
    • sumDouble

      public double sumDouble()
    • sort

      public void sort()
      Sorts an array, lowest to highest
    • sortReverse

      public void sortReverse()
      A sort in reverse. It's equivalent to running sort() and then reverse(), but is more efficient than running each separately.
    • reverse

      public void reverse()
      Reverse the order of the list
    • shuffle

      public void shuffle()
      Randomize the order of the list elements.
    • 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.
    • random

      public float random()
      Return a random value from the list.
    • removeChoice

      public float removeChoice()
    • copy

      public FloatList copy()
    • values

      public float[] 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.
    • iterator

      public Iterator<Float> iterator()
      Implemented this way so that we can use a FloatList in a for loop.
      Specified by:
      iterator in interface Iterable<Float>
    • array

      @Deprecated public float[] array()
      Deprecated.
    • toArray

      public float[] toArray()
      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

      @Deprecated public float[] array(float[] array)
      Deprecated.
    • toArray

      public float[] toArray(float[] array)
      Copy values into the specified array. If the specified array is null or not the same size, a new array will be allocated.
    • getPercent

      public FloatList 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 return a new list (because IntList/Dict can't do percentages or normalization in place on int values).
    • getSubset

      public FloatList getSubset(int start)
    • getSubset

      public FloatList getSubset(int start, int num)
    • join

      public String join(String separator)
    • 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.
    • toString

      public String toString()
      Overrides:
      toString in class Object