Class WeakPseudoList<T>

java.lang.Object
com.pnfsoftware.jeb.util.collect.WeakPseudoList<T>
Type Parameters:
T - element type
All Implemented Interfaces:
Iterable<T>

public class WeakPseudoList<T> extends Object implements Iterable<T>
A list of weak references. Holding objects in this list will not prevent them from being GC'ed. This interface does not abide by the usual Java List interface, hence the "pseudo".
  • Constructor Details

    • WeakPseudoList

      public WeakPseudoList()
      Create an empty weak pseudo-list.
    • WeakPseudoList

      public WeakPseudoList(int initialCapacity)
      Create an empty weak pseudo-list with an initial capacity.
      Parameters:
      initialCapacity - initial capacity
    • WeakPseudoList

      public WeakPseudoList(Iterable<T> l)
      Create a weak pseudo-list from an iterable.
      Parameters:
      l - elements to add
  • Method Details

    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • size

      public int size()
      Returns:
      number of weak references in the list
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if no weak reference is stored
    • clear

      public void clear()
      Remove all weak references.
    • get

      public T get(int index)
      Retrieve an element.
      Parameters:
      index - element index
      Returns:
      referenced element, or null if it was collected
    • add

      public boolean add(T e)
      Add an element.
      Parameters:
      e - element to weakly reference
      Returns:
      true if the list changed
    • add

      public void add(int index, T e)
      Insert an element.
      Parameters:
      index - insertion index
      e - element to weakly reference
    • addAll

      public void addAll(Iterable<T> l)
      Add all elements from an iterable.
      Parameters:
      l - elements to add
    • set

      public T set(int index, T e)
      Replace an element.
      Parameters:
      index - element index
      e - new element to weakly reference
      Returns:
      previous referenced element, or null if it was collected
    • remove

      public T remove(int index)
      Remove an element.
      Parameters:
      index - element index
      Returns:
      removed referenced element, or null if it was collected