Class NullUnlimitedList
java.lang.Object
com.itextpdf.commons.datastructures.NullUnlimitedList
- Type Parameters:
-
T
- elements of the list
- All Implemented Interfaces:
-
ISimpleList
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 usual
ArrayList
and should have the same complexity (because keys are unique integers, so collisions are impossible).
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an element to the list at the specified index.void
Adds an element to the end of the list.get
(int index) Returns the element at the specified index.int
Returns the index of the first occurrence of the specified element in the list, or -1 if the list does not contain the element.boolean
isEmpty()
Returnstrue
if the list contains no elements, false otherwise.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).Replaces the element at the specified index with the specified element.int
size()
Returns the number of elements in the list.
-
Constructor Details
-
NullUnlimitedList
public NullUnlimitedList()Creates a new instance ofNullUnlimitedList
.
-
-
Method Details
-
add
Adds an element to the end of the list.- Specified by:
-
add
in interfaceISimpleList<T>
- Parameters:
-
element
- the element to add
-
add
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:
-
add
in interfaceISimpleList<T>
- Parameters:
-
index
- the index at which to add the element -
element
- the element to add
-
get
Returns the element at the specified index. average O(1), worth O(n) (mostly impossible in case when keys are integers)- Specified by:
-
get
in interfaceISimpleList<T>
- Parameters:
-
index
- the index of the element to return - Returns:
- the element at the specified index
-
set
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:
-
set
in interfaceISimpleList<T>
- Parameters:
-
index
- the index of the element to replace -
element
- the element to be stored at the specified index - Returns:
- the element previously at the specified index
-
indexOf
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:
-
indexOf
in 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:
-
remove
in interfaceISimpleList<T>
- Parameters:
-
index
- the index of the element to be removed
-
size
public int size()Description copied from interface:ISimpleList
Returns the number of elements in the list.- Specified by:
-
size
in interfaceISimpleList<T>
- Returns:
- the size of the list
-
isEmpty
public boolean isEmpty()Description copied from interface:ISimpleList
Returnstrue
if the list contains no elements, false otherwise.- Specified by:
-
isEmpty
in interfaceISimpleList<T>
- Returns:
- true if the list is empty, false otherwise
-