Class ObjectList<E,L extends ObjectList<E,?>>

java.lang.Object
org.basex.util.list.ElementList
org.basex.util.list.ObjectList<E,L>
Type Parameters:
E - generic object type
L - generic object type
All Implemented Interfaces:
Iterable<E>
Direct Known Subclasses:
AnnList, ANodeBuilder, ANodeList, ExprList, FTMatch, FTMatches, FTTokens, ItemList, RegExpList, StringList, TokenList, ValueList, VarStack

public abstract class ObjectList<E,L extends ObjectList<E,?>> extends ElementList implements Iterable<E>
This is an abstract class for storing objects of any kind in an array-based list.
Author:
BaseX Team 2005-21, BSD License, Christian Gruen
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    E[]
    Element container.

    Fields inherited from class org.basex.util.list.ElementList

    factor, size
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ObjectList(E... list)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(E element)
    Adds an element to the array.
    final L
    add(E... elements)
    Adds elements to the array.
    final L
    add(L elements)
    Adds elements from a string list to the array.
    addUnique(E element)
    Adds an element to the array if it is not contained yet.
    boolean
    contains(E element)
    Checks if the specified element is found in the list.
    boolean
    equals(E element1, E element2)
    Compares two list elements.
    boolean
     
    final E[]
    Returns an array with all elements and invalidates the internal array.
    get(int i)
    Returns the element at the specified index.
    final void
    insert(int index, E... elements)
    Inserts the given elements at the specified position.
     
    protected abstract E[]
    newArray(int s)
    Creates a resized array.
    E[]
    Returns an array with all elements and resets the array size.
    Returns the uppermost element on the stack, without removing it.
    final E
    pop()
    Pops the uppermost element from the stack.
    final void
    push(E element)
    Pushes an element onto the stack.
    final E
    remove(int index)
    Deletes the element at the specified position.
    boolean
    removeAll(E element)
    Removes all occurrences of the specified element from the list.
    removeAll(L elements)
    Removes all elements from the specified list.
    final L
    set(int index, E element)
    Sets an element at the specified index position.
    final L
    sort(Comparator<E> comp, boolean ascending)
    Sorts the elements.
    final E[]
    Returns an array with all elements.
     
    final L
    Removes duplicates, provided that the entries are sorted.

    Methods inherited from class org.basex.util.list.ElementList

    isEmpty, newCapacity, newCapacity, reset, size, size

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Field Details

    • list

      public E[] list
      Element container.
  • Constructor Details

    • ObjectList

      protected ObjectList(E... list)
      Constructor.
      Parameters:
      list - initial list .
  • Method Details

    • newArray

      protected abstract E[] newArray(int s)
      Creates a resized array.
      Parameters:
      s - size
      Returns:
      array
    • get

      public E get(int i)
      Returns the element at the specified index.
      Parameters:
      i - index
      Returns:
      element, or null if index exceeds list size
    • contains

      public boolean contains(E element)
      Checks if the specified element is found in the list.
      Parameters:
      element - element to be found
      Returns:
      result of check
    • addUnique

      public L addUnique(E element)
      Adds an element to the array if it is not contained yet.
      Parameters:
      element - element to be added
      Returns:
      result of check
    • add

      public L add(E element)
      Adds an element to the array.
      Parameters:
      element - element to be added
      Returns:
      self reference
    • add

      public final L add(E... elements)
      Adds elements to the array.
      Parameters:
      elements - elements to be added
      Returns:
      self reference
    • add

      public final L add(L elements)
      Adds elements from a string list to the array.
      Parameters:
      elements - string list to be added
      Returns:
      self reference
    • set

      public final L set(int index, E element)
      Sets an element at the specified index position.
      Parameters:
      index - index
      element - element to be set
      Returns:
      self reference
    • insert

      public final void insert(int index, E... elements)
      Inserts the given elements at the specified position.
      Parameters:
      index - inserting position
      elements - elements to insert
    • remove

      public final E remove(int index)
      Deletes the element at the specified position.
      Parameters:
      index - index of the element to delete
      Returns:
      deleted element
    • removeAll

      public boolean removeAll(E element)
      Removes all occurrences of the specified element from the list.
      Parameters:
      element - element to be removed
      Returns:
      flag, indicating if any element was removed
    • removeAll

      public L removeAll(L elements)
      Removes all elements from the specified list.
      Parameters:
      elements - elements
      Returns:
      self reference
    • pop

      public final E pop()
      Pops the uppermost element from the stack.
      Returns:
      the popped element
    • push

      public final void push(E element)
      Pushes an element onto the stack.
      Parameters:
      element - element
    • peek

      public E peek()
      Returns the uppermost element on the stack, without removing it.
      Returns:
      uppermost element
    • toArray

      public final E[] toArray()
      Returns an array with all elements.
      Returns:
      array
    • finish

      public final E[] finish()
      Returns an array with all elements and invalidates the internal array. Warning: the function must only be called if the list is discarded afterwards.
      Returns:
      array (internal representation!)
    • next

      public E[] next()
      Returns an array with all elements and resets the array size.
      Returns:
      array
    • sort

      public final L sort(Comparator<E> comp, boolean ascending)
      Sorts the elements.
      Parameters:
      comp - comparator
      ascending - ascending/descending order
      Returns:
      self reference
    • equals

      public boolean equals(E element1, E element2)
      Compares two list elements.
      Parameters:
      element1 - first element
      element2 - second element
      Returns:
      result of check
    • unique

      public final L unique()
      Removes duplicates, provided that the entries are sorted.
      Returns:
      self reference
    • iterator

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object