Class HashList<T,​ID>

  • All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>

    public class HashList<T,​ID>
    extends java.util.AbstractList<T>
    List implementation with improved performance for List.indexOf(Object). The indexOf(Object) method uses a map of ID to index instead of searching the list for the value. Items in the list for which the ID Function returns null are allowed and can safely be assigned a non-null ID after being added to the list. Otherwise, the ID of an item in the list should not change.
    • Field Summary

      • Fields inherited from class java.util.AbstractList

        modCount
    • Constructor Summary

      Constructors 
      Constructor Description
      HashList​(java.util.function.Function<? super T,​ID> idFunction)  
      HashList​(java.util.function.Function<? super T,​ID> idFunction, int initialCapacity)  
      HashList​(java.util.List<T> list, java.util.function.Function<? super T,​ID> idFunction)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int index, T element)  
      T get​(int index)  
      int indexOf​(java.lang.Object o)  
      int lastIndexOf​(java.lang.Object o)  
      T remove​(int index)  
      T set​(int index, T element)  
      int size()  
      • Methods inherited from class java.util.AbstractList

        add, addAll, clear, equals, hashCode, iterator, listIterator, listIterator, removeRange, subList
      • Methods inherited from class java.util.AbstractCollection

        addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

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

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.List

        addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
    • Constructor Detail

      • HashList

        public HashList​(java.util.function.Function<? super T,​ID> idFunction)
      • HashList

        public HashList​(java.util.function.Function<? super T,​ID> idFunction,
                        int initialCapacity)
      • HashList

        public HashList​(java.util.List<T> list,
                        java.util.function.Function<? super T,​ID> idFunction)
    • Method Detail

      • get

        public T get​(int index)
        Specified by:
        get in interface java.util.List<T>
        Specified by:
        get in class java.util.AbstractList<T>
      • set

        public T set​(int index,
                     T element)
        Specified by:
        set in interface java.util.List<T>
        Overrides:
        set in class java.util.AbstractList<T>
      • add

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

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

        public int size()
        Specified by:
        size in interface java.util.Collection<T>
        Specified by:
        size in interface java.util.List<T>
        Specified by:
        size in class java.util.AbstractCollection<T>
      • indexOf

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

        public int lastIndexOf​(java.lang.Object o)
        Specified by:
        lastIndexOf in interface java.util.List<T>
        Overrides:
        lastIndexOf in class java.util.AbstractList<T>