Class FixedArrayList<E>

java.lang.Object
org.graphstream.util.set.FixedArrayList<E>
All Implemented Interfaces:
Iterable<E>, Collection<E>, RandomAccess

public class FixedArrayList<E>
extends Object
implements Collection<E>, RandomAccess
Array list with immutable element indices.

A fixed array list is like an array list, but it ensures the property that each element will always stay at the same index, even if elements are removed in between. The counterpart of this property is that the array handles by itself the insertion of new elements (since when an element is removed in the middle, this position can be reused), and therefore indices cannot be chosen (i.e. only the add(Object) and addAll(Collection) methods are usable to insert new elements in the array).

This is the reason why this does not implement the List interface, because the add(int,E) method cannot be implemented.

Furthermore, this array cannot contain null values, because it marks unused positions within the array using the null value.

Since:
20040912
Author:
Antoine Dutot
  • Constructor Details

    • FixedArrayList

      public FixedArrayList()
    • FixedArrayList

      public FixedArrayList​(int capacity)
  • Method Details

    • size

      public int size()
      Number of elements in the array.
      Specified by:
      size in interface Collection<E>
      Returns:
      The number of elements in the array.
    • realSize

      public int realSize()
      Real size of the array, counting elements that have been erased.
      See Also:
      unsafeGet(int)
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<E>
    • get

      public E get​(int i)
      I-th element.
      Parameters:
      i - The element index.
      Returns:
      The element at index i.
    • unsafeGet

      public E unsafeGet​(int i)
      I-th element. Like the get(int) method but it does not check the element does not exists at the given index.
      Parameters:
      i - The element index.
      Returns:
      The element at index i.
    • contains

      public boolean contains​(Object o)
      Specified by:
      contains in interface Collection<E>
    • containsAll

      public boolean containsAll​(Collection<?> c)
      Specified by:
      containsAll in interface Collection<E>
    • equals

      public boolean equals​(Object o)
      Specified by:
      equals in interface Collection<E>
      Overrides:
      equals in class Object
    • iterator

      public Iterator<E> iterator()
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
    • getLastIndex

      public int getLastIndex()
      Last index used by the add(Object) method.
      Returns:
      The last insertion index.
    • getNextAddIndex

      public int getNextAddIndex()
      The index that will be used in case of a next insertion in this array.
      Returns:
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<E>
    • toArray

      public <T> T[] toArray​(T[] a)
      Specified by:
      toArray in interface Collection<E>
    • add

      public boolean add​(E element) throws NullPointerException
      Add one element in the array. The index used for inserting the element is then available using getLastIndex().
      Specified by:
      add in interface Collection<E>
      Parameters:
      element - The element to add.
      Returns:
      Always true.
      Throws:
      NullPointerException - If a null value is inserted.
      See Also:
      getLastIndex()
    • addAll

      public boolean addAll​(Collection<? extends E> c) throws UnsupportedOperationException
      Specified by:
      addAll in interface Collection<E>
      Throws:
      UnsupportedOperationException
    • remove

      public E remove​(int i)
      Remove the element at index i.
      Parameters:
      i - Index of the element to remove.
      Returns:
      The removed element.
    • remove

      public boolean remove​(Object e)
      Remove the element e.
      Specified by:
      remove in interface Collection<E>
      Parameters:
      e - The element to remove.
      Returns:
      True if removed.
    • removeAll

      public boolean removeAll​(Collection<?> c)
      Specified by:
      removeAll in interface Collection<E>
    • retainAll

      public boolean retainAll​(Collection<?> c)
      Specified by:
      retainAll in interface Collection<E>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<E>