Class RestrictedCollections.RestrictedList

All Implemented Interfaces:
Serializable, Iterable, Collection, List, SequencedCollection
Enclosing class:
RestrictedCollections

public static class RestrictedCollections.RestrictedList extends RestrictedCollections.RestrictedCollection implements List, Serializable
A restricted List that requires its contents to be of a specified class.
See Also:
  • Constructor Details

    • RestrictedList

      public RestrictedList(List list, Class clz)
      Constructor.
      Parameters:
      list - the underlying List
      clz - the class of objects that may be stored in the List
  • Method Details

    • get

      public Object get(int index)
      Returns the element at the specified position in this list.
      Specified by:
      get in interface List
      Parameters:
      index - index of element to return
      Returns:
      the element at the specified position in this list
    • set

      public Object set(int index, Object element)
      Replaces the element at the specified position in this list with the specified element (optional operation).
      Specified by:
      set in interface List
      Parameters:
      index - index of element to replace.
      element - element to be stored at the specified position.
      Returns:
      the element previously at the specified position.
      Throws:
      ClassCastException - if the class of the specified element prevents it from being added to this list
    • add

      public void add(int index, Object element)
      Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
      Specified by:
      add in interface List
      Parameters:
      index - index at which the specified element is to be inserted
      element - element to be inserted
      Throws:
      ClassCastException - if the class of the specified element prevents it from being added to this list
    • addAll

      public boolean addAll(int index, Collection col)
      Inserts all of the elements in the specified collection into this list at the specified position (optional operation).
      Specified by:
      addAll in interface List
      Parameters:
      index - index at which to insert first element from the specified collection
      col - elements to be inserted into this list
      Returns:
      true if this list changed as a result of the call
      Throws:
      ClassCastException - if the class of one of elements of the specified collection prevents it from being added to this list
    • remove

      public Object remove(int index)
      Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
      Specified by:
      remove in interface List
      Parameters:
      index - the index of the element to removed
      Returns:
      the element previously at the specified position
    • indexOf

      public int indexOf(Object o)
      Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.
      Specified by:
      indexOf in interface List
      Parameters:
      o - element to search for
      Returns:
      the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element
    • lastIndexOf

      public int lastIndexOf(Object o)
      Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element. More formally, returns the highest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.
      Specified by:
      lastIndexOf in interface List
      Parameters:
      o - element to search for
      Returns:
      the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.
    • listIterator

      public ListIterator listIterator()
      Returns a list iterator of the elements in this list (in proper sequence).
      Specified by:
      listIterator in interface List
      Returns:
      a list iterator of the elements in this list (in proper sequence)
    • listIterator

      public ListIterator listIterator(int index)
      Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list. The specified index indicates the first element that would be returned by an initial call to the next method. An initial call to the previous method would return the element with the specified index minus one.
      Specified by:
      listIterator in interface List
      Parameters:
      index - index of first element to be returned from the list iterator (by a call to the next method)
      Returns:
      a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list
    • subList

      public List subList(int fromIndex, int toIndex)
      Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. Obeys the general contract of List.subList.
      Specified by:
      subList in interface List
      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