Class SequentialListSegment<E>

  • All Implemented Interfaces:
    java.lang.CharSequence, java.lang.Comparable<Segment>, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>
    Direct Known Subclasses:
    Attributes

    public abstract class SequentialListSegment<E>
    extends Segment
    implements java.util.List<E>
    A base class used internally to simulate multiple inheritance of Segment and java.util.AbstractSequentialList.

    It allows a Segment based class to implement java.util.List without having to implement all of the List methods explicitly, which would clutter the API documentation with mostly irrelevant methods. By extending this class, most of the list implementation methods are simply listed in the inherited methods list. The list is assumed to be immutable.

    See Also:
    Attributes
    • Constructor Detail

      • SequentialListSegment

        public SequentialListSegment​(Source source,
                                     int begin,
                                     int end)
    • Method Detail

      • getCount

        public abstract int getCount()
        Returns the number of items in the list.
        Returns:
        the number of items in the list.
      • listIterator

        public abstract java.util.ListIterator<E> listIterator​(int index)
        Returns a list iterator of the items in this list (in proper sequence), starting at the specified position in the list.

        The specified index indicates the first item that would be returned by an initial call to the next() method. An initial call to the previous() method would return the item with the specified index minus one.

        Specified by:
        listIterator in interface java.util.List<E>
        Parameters:
        index - index of the first item to be returned from the list iterator (by a call to the next() method).
        Returns:
        a list iterator of the items in this list (in proper sequence), starting at the specified position in the list.
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index > size()).
      • get

        public E get​(int index)
        Returns the item at the specified position in this list.

        This implementation first gets a list iterator pointing to the indexed item (with listIterator(index)). Then, it gets the element using ListIterator.next and returns it.

        Specified by:
        get in interface java.util.List<E>
        Parameters:
        index - the index of the item to return.
        Returns:
        the item at the specified position in this list.
        Throws:
        java.lang.IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index >= size()).
      • size

        public int size()
        Returns the number of items in the list.

        This is equivalent to getCount(), and is necessary to for the implementation of the java.util.Collection interface.

        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.List<E>
        Returns:
        the number of items in the list.
      • isEmpty

        public boolean isEmpty()
        Indicates whether this list is empty.
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Specified by:
        isEmpty in interface java.util.List<E>
        Returns:
        true if there are no items in the list, otherwise false.
      • contains

        public boolean contains​(java.lang.Object o)
        Indicates whether this list contains the specified object.
        Specified by:
        contains in interface java.util.Collection<E>
        Specified by:
        contains in interface java.util.List<E>
        Parameters:
        o - object to be checked for containment in this list.
        Returns:
        true if this list contains the specified object, otherwise false.
      • toArray

        public java.lang.Object[] toArray()
        Returns an array containing all of the items in this list.
        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface java.util.List<E>
        Returns:
        an array containing all of the items in this list.
      • toArray

        public <T> T[] toArray​(T[] a)
        Returns an array containing all of the items in this list in the correct order; the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.

        If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the item in the array immediately following the end of the collection is set to null. This is useful in determining the length of the list only if the caller knows that the list does not contain any null items.

        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface java.util.List<E>
        Parameters:
        a - the array into which the items of the list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
        Returns:
        an array containing the items of the list.
        Throws:
        java.lang.NullPointerException - if the specified array is null.
        java.lang.ArrayStoreException - if the runtime type of the specified array is not a supertype of the runtime type of every item in this list.
      • remove

        public boolean remove​(java.lang.Object o)
        This list is unmodifiable, so this method always throws an UnsupportedOperationException.
        Specified by:
        remove in interface java.util.Collection<E>
        Specified by:
        remove in interface java.util.List<E>
        Throws:
        java.lang.UnsupportedOperationException
      • containsAll

        public boolean containsAll​(java.util.Collection<?> collection)
        Indicates whether this list contains all of the items in the specified collection.
        Specified by:
        containsAll in interface java.util.Collection<E>
        Specified by:
        containsAll in interface java.util.List<E>
        Parameters:
        collection - the collection to be checked for containment in this list.
        Returns:
        true if this list contains all of the items in the specified collection, otherwise false.
        Throws:
        java.lang.NullPointerException - if the specified collection is null.
        See Also:
        contains(Object)
      • addAll

        public boolean addAll​(java.util.Collection<? extends E> collection)
        This list is unmodifiable, so this method always throws an UnsupportedOperationException.
        Specified by:
        addAll in interface java.util.Collection<E>
        Specified by:
        addAll in interface java.util.List<E>
        Throws:
        java.lang.UnsupportedOperationException
      • removeAll

        public boolean removeAll​(java.util.Collection<?> collection)
        This list is unmodifiable, so this method always throws an UnsupportedOperationException.
        Specified by:
        removeAll in interface java.util.Collection<E>
        Specified by:
        removeAll in interface java.util.List<E>
        Throws:
        java.lang.UnsupportedOperationException
      • retainAll

        public boolean retainAll​(java.util.Collection<?> collection)
        This list is unmodifiable, so this method always throws an UnsupportedOperationException.
        Specified by:
        retainAll in interface java.util.Collection<E>
        Specified by:
        retainAll in interface java.util.List<E>
        Throws:
        java.lang.UnsupportedOperationException
      • add

        public boolean add​(E e)
        This list is unmodifiable, so this method always throws an UnsupportedOperationException.
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.List<E>
        Throws:
        java.lang.UnsupportedOperationException
      • set

        public E set​(int index,
                     E element)
        This list is unmodifiable, so this method always throws an UnsupportedOperationException.
        Specified by:
        set in interface java.util.List<E>
        Throws:
        java.lang.UnsupportedOperationException
      • add

        public void add​(int index,
                        E element)
        This list is unmodifiable, so this method always throws an UnsupportedOperationException.
        Specified by:
        add in interface java.util.List<E>
        Throws:
        java.lang.UnsupportedOperationException
      • remove

        public E remove​(int index)
        This list is unmodifiable, so this method always throws an UnsupportedOperationException.
        Specified by:
        remove in interface java.util.List<E>
        Throws:
        java.lang.UnsupportedOperationException
      • indexOf

        public int indexOf​(java.lang.Object o)
        Returns the index in this list of the first occurence of the specified object, or -1 if the list does not contain this object.
        Specified by:
        indexOf in interface java.util.List<E>
        Parameters:
        o - object to search for.
        Returns:
        the index in this list of the first occurence of the specified object, or -1 if the list does not contain this object.
      • lastIndexOf

        public int lastIndexOf​(java.lang.Object o)
        Returns the index in this list of the last occurence of the specified object, or -1 if the list does not contain this object.
        Specified by:
        lastIndexOf in interface java.util.List<E>
        Parameters:
        o - object to search for.
        Returns:
        the index in this list of the last occurence of the specified object, or -1 if the list does not contain this object.
      • clear

        public void clear()
        This list is unmodifiable, so this method always throws an UnsupportedOperationException.
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.List<E>
        Throws:
        java.lang.UnsupportedOperationException
      • addAll

        public boolean addAll​(int index,
                              java.util.Collection<? extends E> collection)
        This list is unmodifiable, so this method always throws an UnsupportedOperationException.
        Specified by:
        addAll in interface java.util.List<E>
        Throws:
        java.lang.UnsupportedOperationException
      • iterator

        public java.util.Iterator<E> iterator()
        Returns an iterator over the items in the list in proper sequence.
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.List<E>
        Returns:
        an iterator over the items in the list in proper sequence.
      • listIterator

        public java.util.ListIterator<E> listIterator()
        Returns a list iterator of the items in this list (in proper sequence), starting with the first item in the list.
        Specified by:
        listIterator in interface java.util.List<E>
        Returns:
        a list iterator of the items in this list (in proper sequence), starting with the first item in the list.
        See Also:
        listIterator(int)
      • subList

        public java.util.List<E> subList​(int fromIndex,
                                         int toIndex)
        Returns a view of the portion of this list between fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.
        Specified by:
        subList in interface java.util.List<E>
        Parameters:
        fromIndex - low endpoint (inclusive) of the subList.
        toIndex - high endpoint (exclusive) of the subList.
        Returns:
        a view of the specified range within this list.
        Throws:
        java.lang.IndexOutOfBoundsException - endpoint index value out of range (fromIndex < 0 || toIndex > size)
        java.lang.IllegalArgumentException - endpoint indices out of order (fromIndex > toIndex)
        See Also:
        List.subList(int fromIndex, int toIndex)