Class LongList

java.lang.Object
processing.data.LongList
All Implemented Interfaces:
Iterable<Long>

public class LongList extends Object implements Iterable<Long>
Helper class for a list of long 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
     
    LongList(int length)
     
    LongList(long[] source)
     
    Construct an IntList from an iterable pile of objects.
    LongList(Object... items)
    Construct an IntList from a random pile of objects.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int index, int amount)
    Add to a value
    void
    append(int[] values)
     
    void
    append(long value)
    Add a new entry to the list.
    void
     
    void
    appendUnique(int value)
    Add this value, but only if it's not already in the list.
    long
    Return a random value from the list.
    void
    Remove all entries from the list.
     
    void
    div(int index, int amount)
    Divide a value
    static LongList
    fromRange(int stop)
     
    static LongList
    fromRange(int start, int stop)
     
    long
    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(int value)
    Check if a number is a part of the list
    void
    increment(int index)
    Add one to a value
    int
    index(int what)
    Return the first index of a particular value.
    void
    insert(int index, long value)
     
    void
    insert(int index, long[] values)
     
    void
    insert(int index, LongList list)
     
     
    join(String separator)
     
    long
    max()
    Return the largest value
    int
     
    long
    min()
    Return the smallest value
    int
     
    void
    mult(int index, int amount)
    Multiply a value
    long
    pop()
     
    void
     
    void
    push(int value)
    Just an alias for append(), but matches pop()
    long
    remove(int index)
    Remove an element from the specified index
    long
     
    int
    removeValue(int value)
     
    int
    removeValues(int value)
     
    void
    resize(int length)
     
    void
    Reverse the order of the list elements
    void
    save(File file)
    Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
    void
    set(int index, int 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 the array in place.
    void
    Reverse sort, orders values from highest to lowest.
    void
    sub(int index, int amount)
    Subtract from a value
    int
    sum()
     
    long
     
    long[]
    Create a new array with a copy of all the values.
    long[]
    toArray(long[] array)
    Copy values into the specified array.
    Return this dictionary as a String in JSON format.
     
    long[]
    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

    • LongList

      public LongList()
    • LongList

      public LongList(int length)
    • LongList

      public LongList(long[] source)
    • LongList

      public LongList(Iterable<Object> iterable)
      Construct an IntList 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 0.
    • LongList

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

    • fromRange

      public static LongList fromRange(int stop)
    • fromRange

      public static LongList fromRange(int start, int stop)
    • 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 long get(int index)
      Get an entry at a particular index.
    • set

      public void set(int index, int 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(int value)
      Just an alias for append(), but matches pop()
    • pop

      public long pop()
    • remove

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

      public int removeValue(int value)
    • removeValues

      public int removeValues(int value)
    • append

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

      public void append(int[] values)
    • append

      public void append(LongList list)
    • appendUnique

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

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

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

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

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

      public boolean hasValue(int value)
      Check if a number is a part of the list
    • increment

      public void increment(int index)
      Add one to a value
    • add

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

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

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

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

      public long min()
      Return the smallest value
    • minIndex

      public int minIndex()
    • max

      public long max()
      Return the largest value
    • maxIndex

      public int maxIndex()
    • sum

      public int sum()
    • sumLong

      public long sumLong()
    • 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()
      Reverse the order of the list elements
    • 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.
    • choice

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

      public long removeChoice()
    • copy

      public LongList copy()
    • values

      public long[] 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<Long> iterator()
      Specified by:
      iterator in interface Iterable<Long>
    • toArray

      public long[] 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.
    • toArray

      public long[] toArray(long[] 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 get 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 LongList getSubset(int start)
    • getSubset

      public LongList 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