Package open.java.toolkit.arrays.lists
Class EfficientList<E>
- java.lang.Object
-
- open.java.toolkit.arrays.lists.EfficientList<E>
-
- All Implemented Interfaces:
InterfaceList<E>
public class EfficientList<E> extends java.lang.Object implements InterfaceList<E>
-
-
Constructor Summary
Constructors Constructor Description EfficientList()Constructor for this class.EfficientList(int capacity)Constructor for this class.EfficientList(E[] data)Constructor for this class.EfficientList(java.util.List<E> data)Constructor for this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E element)Adds an element to the list.voidclear()Clears the list.booleancontains(E element)Checks if an element is in the list or not.Eget(int index)Gets an element from the list.intindexOf(E element)Gets the index of an element in the list.booleanisEmpty()Checks if the list is empty or not.booleanremove(E element)Removes an existing element from the list.booleanset(int index, E element)Sets an existing element in the list to something else.intsize()Gets the current size of the list.
-
-
-
Constructor Detail
-
EfficientList
public EfficientList(int capacity)
Constructor for this class. Initiates list with capacity.- Parameters:
capacity- The initial capacity of the list.
-
EfficientList
public EfficientList(E[] data)
Constructor for this class. Initiates list with data.- Parameters:
data- The initial data for the list.
-
EfficientList
public EfficientList(java.util.List<E> data)
Constructor for this class. Initiates list with data.- Parameters:
data- The initial data for the list.
-
EfficientList
public EfficientList()
Constructor for this class. No initiate data or capacity.
-
-
Method Detail
-
size
public int size()
Gets the current size of the list.- Specified by:
sizein interfaceInterfaceList<E>- Returns:
- The size of the list.
-
isEmpty
public boolean isEmpty()
Checks if the list is empty or not.- Specified by:
isEmptyin interfaceInterfaceList<E>- Returns:
- Whether or not the list is empty.
-
add
public boolean add(E element)
Adds an element to the list.- Specified by:
addin interfaceInterfaceList<E>- Parameters:
element- The element to add to the list.- Returns:
- Whether or not the element has been successfully added to the list.
-
clear
public void clear()
Clears the list.- Specified by:
clearin interfaceInterfaceList<E>
-
get
public E get(int index)
Gets an element from the list.- Specified by:
getin interfaceInterfaceList<E>- Parameters:
index- The index of the element in the list.- Returns:
- The element from the list.
-
set
public boolean set(int index, E element)Sets an existing element in the list to something else.- Specified by:
setin interfaceInterfaceList<E>- Parameters:
index- The index of the existing element in the list.element- The new element to replace the existing one with.- Returns:
- Whether or not the element has been successfully set.
-
remove
public boolean remove(E element)
Removes an existing element from the list.- Specified by:
removein interfaceInterfaceList<E>- Parameters:
element- The existing element from the list.- Returns:
- Whether or not the element has been successfully removed.
-
indexOf
public int indexOf(E element)
Gets the index of an element in the list.- Specified by:
indexOfin interfaceInterfaceList<E>- Parameters:
element- The element to look for in the list.- Returns:
- The index of the element in the list.
-
contains
public boolean contains(E element)
Checks if an element is in the list or not.- Specified by:
containsin interfaceInterfaceList<E>- Parameters:
element- The element to check.- Returns:
- Whether or not the element is in the list.
-
-