Class SmartList<E>

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

    public class SmartList<E>
    extends java.util.AbstractList<E>
    A List that is optimised for the sizes of 0 and 1, in which cases no array is allocated.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Object _data  
      private int _size  
      • 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, E e)  
      boolean add​(E e)  
      void clear()  
      E get​(int index)  
      int getModificationCount()  
      java.util.Iterator<E> iterator()  
      E remove​(int index)  
      E set​(int index, E element)  
      int size()  
      void sort​(java.util.Comparator<? super E> comparator)  
      <T> T[] toArray​(T[] a)  
      void trimToSize()
      Trims the capacity of this list to be the list's current size.
      • Methods inherited from class java.util.AbstractList

        addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, removeRange, subList
      • Methods inherited from class java.util.AbstractCollection

        addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, 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, spliterator, toArray
    • Field Detail

      • _data

        private java.lang.Object _data
      • _size

        private int _size
    • Constructor Detail

      • SmartList

        public SmartList()
      • SmartList

        public SmartList​(E element)
      • SmartList

        public SmartList​(@NotNull
                         java.util.Collection<? extends E> elements)
      • SmartList

        public SmartList​(@NotNull
                         E... elements)
    • Method Detail

      • get

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

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

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

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

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.List<E>
        Overrides:
        clear in class java.util.AbstractList<E>
      • set

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

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

        @NotNull
        public java.util.Iterator<E> iterator()
        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>
        Overrides:
        iterator in class java.util.AbstractList<E>
      • sort

        public void sort​(@NotNull
                         java.util.Comparator<? super E> comparator)
      • getModificationCount

        public int getModificationCount()
      • toArray

        @NotNull
        public <T> T[] toArray​(@NotNull
                               T[] a)
        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface java.util.List<E>
        Overrides:
        toArray in class java.util.AbstractCollection<E>
      • trimToSize

        public void trimToSize()
        Trims the capacity of this list to be the list's current size. An application can use this operation to minimize the storage of a list instance.