Class ImmList2<E>

  • Type Parameters:
    E - the type of the elements of the list
    All Implemented Interfaces:
    java.lang.Iterable<E>

    public class ImmList2<E>
    extends ImmList<E>
    Implementation of an immutable list of arbitrary length, implemented as a binary tree
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ImmList2​(ImmList<E> left, ImmList<E> right)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ImmList<E> append​(E member)
      Append an element at the end of the list
      ImmList<E> appendList​(ImmList<E> members)
      Append multiple elements at the end of the list
      E get​(int index)
      Get the element at a given index
      ImmList<E> insert​(int index, E member)
      Insert an element at a given position
      boolean isEmpty()
      Ask if the list is empty
      java.util.Iterator<E> iterator()  
      protected ImmList<E> rebalance()
      Return a list containing the same elements as this list, but optimized for efficient access
      ImmList<E> remove​(int index)
      Remove the member at a given position
      ImmList<E> replace​(int index, E member)
      Replace the element at a given index
      int size()
      Get the size of the list
      ImmList<E> subList​(int start, int end)
      Return a sub-sequence with a given start and end position
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Method Detail

      • get

        public E get​(int index)
        Description copied from class: ImmList
        Get the element at a given index
        Specified by:
        get in class ImmList<E>
        Parameters:
        index - the required index (zero-based)
        Returns:
        the element at the given index
      • size

        public int size()
        Description copied from class: ImmList
        Get the size of the list
        Specified by:
        size in class ImmList<E>
        Returns:
        the number of members in the list
      • isEmpty

        public boolean isEmpty()
        Description copied from class: ImmList
        Ask if the list is empty
        Specified by:
        isEmpty in class ImmList<E>
        Returns:
        true if the list contains no elements, otherwise false
      • replace

        public ImmList<E> replace​(int index,
                                  E member)
        Description copied from class: ImmList
        Replace the element at a given index
        Specified by:
        replace in class ImmList<E>
        Parameters:
        index - the index (zero-based) of the element to be replaced
        member - the replacement member to be included in the new list
        Returns:
        a new list, identical to the old except for the replacement of one member
      • insert

        public ImmList<E> insert​(int index,
                                 E member)
        Description copied from class: ImmList
        Insert an element at a given position
        Specified by:
        insert in class ImmList<E>
        Parameters:
        index - the position (zero-based) for the insertion. The new element will be inserted before the existing element at this position. If the index is equal to the list size, the new element is inserted at the end.
        member - the new member to be included in the new list
        Returns:
        a new list, identical to the old except for the addition of one member
      • append

        public ImmList<E> append​(E member)
        Description copied from class: ImmList
        Append an element at the end of the list
        Specified by:
        append in class ImmList<E>
        Parameters:
        member - the new member to be included in the new list
        Returns:
        a new list, identical to the old except for the addition of one member
      • appendList

        public ImmList<E> appendList​(ImmList<E> members)
        Description copied from class: ImmList
        Append multiple elements at the end of the list
        Specified by:
        appendList in class ImmList<E>
        Parameters:
        members - the new members to be included in the new list
        Returns:
        a new list, identical to the old except for the addition of new members
      • remove

        public ImmList<E> remove​(int index)
        Description copied from class: ImmList
        Remove the member at a given position
        Specified by:
        remove in class ImmList<E>
        Parameters:
        index - the zero-based index position of the member to be removed
        Returns:
        a new list, identical to the old except for the removal of one member
      • subList

        public ImmList<E> subList​(int start,
                                  int end)
        Description copied from class: ImmList
        Return a sub-sequence with a given start and end position
        Specified by:
        subList in class ImmList<E>
        Parameters:
        start - the zero-based index position of the first member to be extracted
        end - the zero-based index position of the first member after the sub-sequence to be extracted
        Returns:
        a new list containing the elements from the specified range of positions
      • iterator

        public java.util.Iterator<E> iterator()
      • rebalance

        protected ImmList<E> rebalance()
        Description copied from class: ImmList
        Return a list containing the same elements as this list, but optimized for efficient access
        Overrides:
        rebalance in class ImmList<E>
        Returns:
        either this list, or a copy containing the same elements in the same order