org.jetbrains.kotlin.utils
Class SmartList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by org.jetbrains.kotlin.utils.SmartList<E>
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, java.util.RandomAccess

public class SmartList<E>
extends java.util.AbstractList<E>
implements java.util.RandomAccess

A List which is optimised for the sizes of 0 and 1, in which cases it would not allocate array at all. This class was copied from com.intellij.util.SmartList.


Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
SmartList()
           
SmartList(java.util.Collection<? extends E> elements)
           
SmartList(E... elements)
           
SmartList(E element)
           
 
Method Summary
 boolean add(E e)
           
 void add(int index, 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.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray
 

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.lang.Iterable<E>
Specified by:
iterator in interface java.util.Collection<E>
Specified by:
iterator in interface java.util.List<E>
Overrides:
iterator in class java.util.AbstractList<E>

sort

public void sort(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.