Class NullUnlimitedList<T>
- java.lang.Object
-
- com.itextpdf.commons.datastructures.NullUnlimitedList<T>
-
- Type Parameters:
T- elements of the list
- All Implemented Interfaces:
ISimpleList<T>
public final class NullUnlimitedList<T> extends java.lang.Object implements ISimpleList<T>
The class represents a list which allows null elements, but doesn't allocate a memory for them, in the rest of cases it behaves like usualArrayListand should have the same complexity (because keys are unique integers, so collisions are impossible).
-
-
Constructor Summary
Constructors Constructor Description NullUnlimitedList()Creates a new instance ofNullUnlimitedList.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, T element)Adds an element to the list at the specified index.voidadd(T element)Adds an element to the end of the list.Tget(int index)Returns the element at the specified index.intindexOf(java.lang.Object element)Returns the index of the first occurrence of the specified element in the list, or -1 if the list does not contain the element.booleanisEmpty()Returnstrueif the list contains no elements, false otherwise.voidremove(int index)In worth scenario O(n^2) but it is mostly impossible because keys shouldn't have collisions at all (they are integers).Tset(int index, T element)Replaces the element at the specified index with the specified element.intsize()Returns the number of elements in the list.
-
-
-
Field Detail
-
map
private final java.util.Map<java.lang.Integer,T> map
-
size
private int size
-
-
Constructor Detail
-
NullUnlimitedList
public NullUnlimitedList()
Creates a new instance ofNullUnlimitedList.
-
-
Method Detail
-
add
public void add(T element)
Adds an element to the end of the list.- Specified by:
addin interfaceISimpleList<T>- Parameters:
element- the element to add
-
add
public void add(int index, T element)Adds an element to the list at the specified index. In worth scenario O(n^2) but it is mostly impossible because keys shouldn't have collisions at all (they are integers). So in average should be O(n).- Specified by:
addin interfaceISimpleList<T>- Parameters:
index- the index at which to add the elementelement- the element to add
-
get
public T get(int index)
Returns the element at the specified index. average O(1), worth O(n) (mostly impossible in case when keys are integers)- Specified by:
getin interfaceISimpleList<T>- Parameters:
index- the index of the element to return- Returns:
- the element at the specified index
-
set
public T set(int index, T element)
Replaces the element at the specified index with the specified element. average O(1), worth O(n) (mostly impossible in case when keys are integers)- Specified by:
setin interfaceISimpleList<T>- Parameters:
index- the index of the element to replaceelement- the element to be stored at the specified index- Returns:
- the element previously at the specified index
-
indexOf
public int indexOf(java.lang.Object element)
Returns the index of the first occurrence of the specified element in the list, or -1 if the list does not contain the element.- Specified by:
indexOfin interfaceISimpleList<T>- Parameters:
element- the element to search for- Returns:
- the index of the first occurrence of the specified element in the list, or -1 if the list does not contain the element
-
remove
public void remove(int index)
In worth scenario O(n^2) but it is mostly impossible because keys shouldn't have collisions at all (they are integers). So in average should be O(n).- Specified by:
removein interfaceISimpleList<T>- Parameters:
index- the index of the element to be removed
-
size
public int size()
Description copied from interface:ISimpleListReturns the number of elements in the list.- Specified by:
sizein interfaceISimpleList<T>- Returns:
- the size of the list
-
isEmpty
public boolean isEmpty()
Description copied from interface:ISimpleListReturnstrueif the list contains no elements, false otherwise.- Specified by:
isEmptyin interfaceISimpleList<T>- Returns:
- true if the list is empty, false otherwise
-
-