Class LongArrayList

java.lang.Object
java.util.AbstractCollection<Long>
java.util.AbstractList<Long>
org.jhotdraw8.collection.primitive.LongArrayList
All Implemented Interfaces:
Iterable<Long>, Collection<Long>, List<Long>, SequencedCollection<Long>

public class LongArrayList extends AbstractList<Long>
A long-valued list backed by a primitive array.
Author:
Werner Randelshofer
  • Constructor Details

    • LongArrayList

      public LongArrayList()
      Creates a new empty instance with 0 initial capacity.
    • LongArrayList

      public LongArrayList(int initialCapacity)
      Creates a new empty instance with the specified initial capacity.
      Parameters:
      initialCapacity - the initial capacity
    • LongArrayList

      public LongArrayList(Collection<Long> collection)
      Creates a new instance from the specified collection
      Parameters:
      collection - a collection of integers
  • Method Details

    • of

      public static LongArrayList of(long... items)
      Creates a new instance with the specified items.
      Parameters:
      items - the items (the newly created instance references the provided array)
      Returns:
      the new instance
    • addAsLong

      public void addAsLong(long newItem)
      Adds a new item to the end of the list.
      Parameters:
      newItem - the new item
    • addAsLong

      public void addAsLong(int index, long newItem)
      Inserts a new item at the specified index into this list.
      Parameters:
      index - the index
      newItem - the new item
    • addAllAsLong

      public void addAllAsLong(LongArrayList that)
      Adds all items of the specified list to this list.
      Parameters:
      that - another list
    • addAllInto

      public <T extends Collection<Long>> T addAllInto(T out)
      Adds all items of this collection to the specified collection.
      Type Parameters:
      T - the type of the collection
      Parameters:
      out - the output collection
      Returns:
      out
    • clear

      public void clear()
      Clears the list in O(1).
      Specified by:
      clear in interface Collection<Long>
      Specified by:
      clear in interface List<Long>
      Overrides:
      clear in class AbstractList<Long>
    • copyInto

      public void copyInto(long[] a, int offset)
      Copies the contents of this list into the provided array.
      Parameters:
      a - an array
      offset - the offset into the array
    • equals

      public boolean equals(@Nullable Object obj)
      Specified by:
      equals in interface Collection<Long>
      Specified by:
      equals in interface List<Long>
      Overrides:
      equals in class AbstractList<Long>
    • getAsLong

      public long getAsLong(int index)
      Gets the item at the specified index.
      Parameters:
      index - an index
      Returns:
      the item at the index
    • get

      public Long get(int index)
      Specified by:
      get in interface List<Long>
      Specified by:
      get in class AbstractList<Long>
    • getLastAsLong

      public long getLastAsLong()
    • getFirstAsLong

      public long getFirstAsLong()
    • setSize

      public void setSize(int newSize)
      Sets the size of this list. If the new size is greater than the current size, new 0 items are added to the end of the list. If the new size is less than the current size, all items at indices greater or equal newSize are discarded.
      Parameters:
      newSize - the new size
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<Long>
      Specified by:
      hashCode in interface List<Long>
      Overrides:
      hashCode in class AbstractList<Long>
    • indexOfAsLong

      public int indexOfAsLong(long item)
      Returns the last index of the item, or -1 if this list does not contain the item.
      Parameters:
      item - the item
      Returns:
      the index of the item, or -1.
    • indexOfAsLong

      public int indexOfAsLong(long item, int start)
    • lastIndexOfAsLong

      public int lastIndexOfAsLong(long item)
    • lastIndexOfAsLong

      public int lastIndexOfAsLong(long item, int start)
    • isEmpty

      public boolean isEmpty()
      Returns true if size==0.
      Specified by:
      isEmpty in interface Collection<Long>
      Specified by:
      isEmpty in interface List<Long>
      Overrides:
      isEmpty in class AbstractCollection<Long>
      Returns:
      true if empty
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<Long>
      Specified by:
      contains in interface List<Long>
      Overrides:
      contains in class AbstractCollection<Long>
    • removeAtAsLong

      public long removeAtAsLong(int index)
      Removes the item at the specified index from this list.
      Parameters:
      index - an index
      Returns:
      the removed item
    • removeLastAsLong

      public long removeLastAsLong()
      Removes the last item
      Returns:
      the removed item
      Throws:
      NoSuchElementException - if the list is empty
    • setAsLong

      public long setAsLong(int index, long newItem)
      Replaces the item at the specified index.
      Parameters:
      index - an index
      newItem - the new item
      Returns:
      the old item
    • size

      public int size()
      Returns the size of the list.
      Specified by:
      size in interface Collection<Long>
      Specified by:
      size in interface List<Long>
      Specified by:
      size in class AbstractCollection<Long>
      Returns:
      the size
    • trimToSize

      public void trimToSize()
      Trims the capacity of the list its current size.
    • iterator

      public PrimitiveIterator.OfLong iterator()
      Returns an iterator for this list.
      Specified by:
      iterator in interface Collection<Long>
      Specified by:
      iterator in interface Iterable<Long>
      Specified by:
      iterator in interface List<Long>
      Overrides:
      iterator in class AbstractList<Long>
      Returns:
      an iterator over the elements of this list
    • spliterator

      public Spliterator.OfLong spliterator()
      Returns a spliterator for this list.
      Returns:
      a spliterator over the elements of this list
    • longStream

      public LongStream longStream()
      Returns a stream for processing the items of this list.
      Returns:
      a stream
    • toLongArray

      public long[] toLongArray()
      Returns a new array containing all the elements in this collection.
      Returns:
      array
    • add

      public boolean add(Long e)
      Specified by:
      add in interface Collection<Long>
      Specified by:
      add in interface List<Long>
      Overrides:
      add in class AbstractList<Long>
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<Long>
      Specified by:
      remove in interface List<Long>
      Overrides:
      remove in class AbstractCollection<Long>
    • toString

      public String toString()
      Overrides:
      toString in class AbstractCollection<Long>
    • sort

      public void sort()
      Sorts the items in ascending order.
    • removeIfAsLong

      public boolean removeIfAsLong(LongPredicate filter)
      Removes all the elements of this collection that satisfy the given predicate.
      Parameters:
      filter - a predicate which returns true for elements to be removed
      Returns:
      true if any elements were removed
    • sort

      public void sort(@Nullable Comparator<? super Long> c)
      Sorts this list according to the order induced by the specified Comparator. The sort is stable: it does not reorder equal elements.
      Parameters:
      c - the Comparator used to compare list elements. A null value indicates that the elements' natural ordering should be used.