Class ImmList1<E>

  • Type Parameters:
    E - the type of the list element
    All Implemented Interfaces:
    Iterable<E>

    public class ImmList1<E>
    extends ImmList<E>
    Implementation of an immutable list of length 1 (one)
    • Constructor Detail

      • ImmList1

        public ImmList1​(E member)
    • 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