Class ArrayIndexList<M>

  • Type Parameters:
    M - Type of the elements in the list
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<M>, java.util.Collection<M>, java.util.List<M>, java.util.RandomAccess
    Direct Known Subclasses:
    Dictionary

    public class ArrayIndexList<M>
    extends java.util.ArrayList<M>
    ArrayIndexList is like an ArrayList, but keeps track of the indices where objects have been added. This improves the speed of indexOf() and contains()
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<M,​java.lang.Integer> indexMap  
      private static long serialVersionUID  
      • Fields inherited from class java.util.AbstractList

        modCount
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int index, M element)  
      boolean add​(M e)  
      boolean addAll​(int index, java.util.Collection<? extends M> c)  
      boolean addAll​(java.util.Collection<? extends M> c)  
      void clear()  
      boolean contains​(java.lang.Object o)  
      int indexOf​(java.lang.Object o)  
      int lastIndexOf​(java.lang.Object o)  
      M remove​(int index)  
      boolean remove​(java.lang.Object o)  
      M set​(int index, M element)  
      • Methods inherited from class java.util.ArrayList

        clone, ensureCapacity, forEach, get, isEmpty, iterator, listIterator, listIterator, removeAll, removeIf, removeRange, replaceAll, retainAll, size, sort, spliterator, subList, toArray, toArray, trimToSize
      • Methods inherited from class java.util.AbstractList

        equals, hashCode
      • Methods inherited from class java.util.AbstractCollection

        containsAll, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, stream
      • Methods inherited from interface java.util.List

        containsAll, equals, hashCode
    • Field Detail

      • indexMap

        private final java.util.Map<M,​java.lang.Integer> indexMap
    • Constructor Detail

      • ArrayIndexList

        public ArrayIndexList()
      • ArrayIndexList

        public ArrayIndexList​(java.util.Collection<? extends M> c)
    • Method Detail

      • add

        public void add​(int index,
                        M element)
        Specified by:
        add in interface java.util.List<M>
        Overrides:
        add in class java.util.ArrayList<M>
      • add

        public boolean add​(M e)
        Specified by:
        add in interface java.util.Collection<M>
        Specified by:
        add in interface java.util.List<M>
        Overrides:
        add in class java.util.ArrayList<M>
      • addAll

        public boolean addAll​(java.util.Collection<? extends M> c)
        Specified by:
        addAll in interface java.util.Collection<M>
        Specified by:
        addAll in interface java.util.List<M>
        Overrides:
        addAll in class java.util.ArrayList<M>
      • addAll

        public boolean addAll​(int index,
                              java.util.Collection<? extends M> c)
        Specified by:
        addAll in interface java.util.List<M>
        Overrides:
        addAll in class java.util.ArrayList<M>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<M>
        Specified by:
        clear in interface java.util.List<M>
        Overrides:
        clear in class java.util.ArrayList<M>
      • contains

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection<M>
        Specified by:
        contains in interface java.util.List<M>
        Overrides:
        contains in class java.util.ArrayList<M>
      • indexOf

        public int indexOf​(java.lang.Object o)
        Specified by:
        indexOf in interface java.util.List<M>
        Overrides:
        indexOf in class java.util.ArrayList<M>
      • lastIndexOf

        public int lastIndexOf​(java.lang.Object o)
        Specified by:
        lastIndexOf in interface java.util.List<M>
        Overrides:
        lastIndexOf in class java.util.ArrayList<M>
      • remove

        public M remove​(int index)
        Specified by:
        remove in interface java.util.List<M>
        Overrides:
        remove in class java.util.ArrayList<M>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<M>
        Specified by:
        remove in interface java.util.List<M>
        Overrides:
        remove in class java.util.ArrayList<M>
      • set

        public M set​(int index,
                     M element)
        Specified by:
        set in interface java.util.List<M>
        Overrides:
        set in class java.util.ArrayList<M>