Class AbstractList
A partial List implementation.
This partial implementation can be used to create concrete Lists. This implementation implements all Collection methods except Add and Remove. It doesn't implement Enumerable methods or List methods as it has no knowledge of the specific concrete List implementation. Due to the lack of knowledge of the specific implementation method, some methods may be naive implementations for any particular concrete List implementation and can be overridden.
AbstractList has the same optional and required methods of Collection and List. AbstractList assumes all optional methods are intended to be implemented, however, they may overridden if they should not be in a particular concrete List implementation.
Functions
| AbstractList.new() | Creates a new AbstractList abstract class instance. |
Methods
| AbstractList:Add(item) | Adds an item to the AbstractList. |
| AbstractList:AddAll(items) | Adds multiple items to the AbstractList. |
| AbstractList:Clear() | Removes everything from the AbstractList. |
| AbstractList:Contains(item) | Determines whether the AbstractList contains an item. |
| AbstractList:ContainsAll(items) | Determines whether the AbstractList contains multiple items. |
| AbstractList:ContainsAny(items) | Determines whether the AbstractList contains any of the provided items. |
| AbstractList:Count() | Gets the number of items in the AbstractList. |
| AbstractList:Delete(index) | Removes the item at the specified index from the AbstractList. |
| AbstractList:Empty() | Determines whether the AbstractList contains no elements. |
| AbstractList:Enumerator() | Creates an enumerator for the AbstractList. |
| AbstractList:First() | Gets the item at the beginning of the AbstractList. |
| AbstractList:Get(index) | Gets the item at the specified index in the AbstractList. |
| AbstractList:IndexOf(item, index) | Determines the index of a specific item in the AbstractList. |
| AbstractList:Insert(index, item) | Inserts an item into the AbstractList at the specified index. |
| AbstractList:InsertAll(index, items) | Inserts all items into the AbstractList at the specified index. |
| AbstractList:Last() | Gets the item at the end of the AbstractList. |
| AbstractList:LastIndexOf(item) | Determines the last index of a specific item in the AbstractList. |
| AbstractList:Pop() | Gets an item from the end and removes that item from the AbstractList. |
| AbstractList:Push(item) | Adds an item to the end of the AbstractList. |
| AbstractList:Remove(item) | Removes the specified item from the AbstractList. |
| AbstractList:RemoveAll(items) | Removes all provided items from the AbstractList. |
| AbstractList:RetainAll(items) | Removes all items except those provided from the AbstractList. |
| AbstractList:Set(index) | Sets the element at the specified index. |
| AbstractList:Shift() | Gets an item from the beginning and removes that item from the AbstractList. |
| AbstractList:Sub(first, last) | Creates a new sub-List of this AbstractList. |
| AbstractList:ToArray() | Creates a new array-indexed table of this AbstractList. |
| AbstractList:ToTable() | Creates a new table of this AbstractList. |
| AbstractList:Unshift(item) | Adds an item to the beginning of the AbstractList. |
Functions
Methods- AbstractList.new()
-
Creates a new AbstractList abstract class instance.
This should only be used when implementing a new AbstractList.
Access:
-
private
Returns:
-
the new AbstractList abstract class
Methods
- AbstractList:Add(item)
-
Adds an item to the AbstractList.
This method is optional. All AbstractList implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.
This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this AbstractList.
Inherited from:
Parameters:
- item the item to add
Returns:
-
true if the AbstractList changed as a result, false otherwise
- AbstractList:AddAll(items)
-
Adds multiple items to the AbstractList.
Adds items provided in another Collection in an arbitrary,
deterministic order. The order is the same as the order of enumeration.
Inherited from:
Parameters:
- items the Collection of items to add to this AbstractList
Returns:
-
true always, since the AbstractList is always changed
- AbstractList:Clear()
-
Removes everything from the AbstractList.
Inherited from:
- AbstractList:Contains(item)
-
Determines whether the AbstractList contains an item.
Inherited from:
Parameters:
- item the item to locate in the AbstractList
Returns:
-
true if the item is in the AbstractList, false otherwise
- AbstractList:ContainsAll(items)
-
Determines whether the AbstractList contains multiple items.
Checks for items provided in another Collection in an arbitrary,
deterministic order. The order is the same as the order of enumeration.
Inherited from:
Parameters:
- items the Collection of items to locate in this AbstractList
Returns:
-
true if all items are in the AbstractList, false otherwise
- AbstractList:ContainsAny(items)
-
Determines whether the AbstractList contains any of the provided items.
Checks for items provided in another Collection in an arbitrary,
deterministic order. The order is the same as the order of enumeration.
Inherited from:
Parameters:
- items the Collection of items to locate in this AbstractList
Returns:
-
true if any items are in the AbstractList, false otherwise
- AbstractList:Count()
-
Gets the number of items in the AbstractList.
Inherited from:
Returns:
-
the number of items
- AbstractList:Delete(index)
-
Removes the item at the specified index from the AbstractList.
Shifts other elements to fill the gap left at the index of removal.
This method is optional. All AbstractList implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.
This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this AbstractList.
Inherited from:
Parameters:
- index the index of the item to remove from the AbstractList
Returns:
-
true if the AbstractList changed as a result, false otherwise
Raises:
if the index is out of bounds of the AbstractList - AbstractList:Empty()
-
Determines whether the AbstractList contains no elements.
Inherited from:
Returns:
-
true if the AbstractList empty, false otherwise
- AbstractList:Enumerator()
-
Creates an enumerator for the AbstractList.
The enumerator can be used directly in a generic for loop similar to pairs
or ipairs.
Inherited from:
Returns:
- the enumerator generator
- the invariant state
- the control variable state
- AbstractList:First()
-
Gets the item at the beginning of the AbstractList.
Inherited from:
Returns:
-
the first item in the AbstractList
Raises:
if the AbstractList is empty - AbstractList:Get(index)
-
Gets the item at the specified index in the AbstractList.
Inherited from:
Parameters:
- index the index to get
Returns:
-
the item in the AbstractList at the specified index
Raises:
if the index is out of bounds of the AbstractList - AbstractList:IndexOf(item, index)
-
Determines the index of a specific item in the AbstractList.
Starts from a specified index or from the beginning if none is provided.
Inherited from:
Parameters:
- item the item to locate
- index the index to start looking from
Returns:
-
the index of the item in the AbstractList if found, 0 otherwise
Raises:
if the index is out of bounds of the AbstractList - AbstractList:Insert(index, item)
-
Inserts an item into the AbstractList at the specified index.
Shifts other elements to make space at the index of insertion.
This method is optional. All AbstractList implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.
This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this AbstractList.
Inherited from:
Parameters:
- index the index to insert the item in the AbstractList
- item the item to add
Returns:
-
true if the AbstractList changed as a result, false otherwise
Raises:
if the index is out of bounds of the AbstractList - AbstractList:InsertAll(index, items)
-
Inserts all items into the AbstractList at the specified index.
Inserts all items from the provided Collection in an arbitrary,
deterministic order. The order is the same as the order of enumeration.
Shifts other elements to make space at the index of insertion.
This method is optional. All AbstractList implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.
This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this AbstractList.
Inherited from:
Parameters:
- index the index to insert the items in the AbstractList
- items the Collection of items to add to this AbstractList
Returns:
-
true if the AbstractList changed as a result, false otherwise
Raises:
if the index is out of bounds of the AbstractList - AbstractList:Last()
-
Gets the item at the end of the AbstractList.
Inherited from:
Returns:
-
the last item in the AbstractList
Raises:
if the AbstractList is empty - AbstractList:LastIndexOf(item)
-
Determines the last index of a specific item in the AbstractList.
Only returns the very last occurrence of the item in the AbstractList.
Inherited from:
Parameters:
- item the item to locate
Returns:
-
the index of the item in the AbstractList if found, 0 otherwise
- AbstractList:Pop()
-
Gets an item from the end and removes that item from the AbstractList.
This method is optional. All AbstractList implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.
This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this AbstractList.
Inherited from:
Returns:
-
the item in the AbstractList
Raises:
if the AbstractList is empty - AbstractList:Push(item)
-
Adds an item to the end of the AbstractList.
This method is optional. All AbstractList implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.
This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this AbstractList.
Inherited from:
Parameters:
- item the item to add
Returns:
-
true if the AbstractList changed as a result, false otherwise
- AbstractList:Remove(item)
-
Removes the specified item from the AbstractList.
Removes only a single item. If there are multiple of the same item, it
removes only the first encountered.
When an item is removed any others are shifted to fill the gap left at the index of removal.
This method is optional. All AbstractList implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.
This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this AbstractList.
Inherited from:
Parameters:
- item the item to remove from the AbstractList
Returns:
-
true if the AbstractList changed as a result, false otherwise
- AbstractList:RemoveAll(items)
-
Removes all provided items from the AbstractList.
Removes each instance of a provided item only once for each time provided.
If there are multiple of the same item in this AbstractList, it removes only
the first encountered for each provided.
Inherited from:
Parameters:
- items the Collection of items to remove from this AbstractList
Returns:
-
true if the AbstractList changed as a result, false otherwise
- AbstractList:RetainAll(items)
-
Removes all items except those provided from the AbstractList.
Retains only the items contained in the specified Collection. If there
are duplicates they are all kept.
Inherited from:
Parameters:
- items the Collection of items to retain in this AbstractList
Returns:
-
true if the AbstractList changed as a result, false otherwise
- AbstractList:Set(index)
-
Sets the element at the specified index.
This method is optional. All AbstractList implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.
This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this AbstractList.
Inherited from:
Parameters:
- index the index to set
Returns:
-
true if the AbstractList changed as a result, false otherwise
Raises:
if the index is out of bounds of the AbstractList - AbstractList:Shift()
-
Gets an item from the beginning and removes that item from the AbstractList.
Shifts other elements to fill the gap left.
This method is optional. All AbstractList implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.
This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this AbstractList.
Inherited from:
Returns:
-
the item in the AbstractList
Raises:
if the AbstractList is empty - AbstractList:Sub(first, last)
-
Creates a new sub-List of this AbstractList.
Creates the List that is the portion of this AbstractList between the
specified indices or from the first sepecified index to the end if only one
index is specified.
Inherited from:
Parameters:
- first the index to start at
- last the index to end at
Returns:
-
the new List
Raises:
if either index is out of bounds of the AbstractList - AbstractList:ToArray()
-
Creates a new array-indexed table of this AbstractList.
The order of the array is the same as the order of the AbstractList and uses
the same indexing.
Inherited from:
Returns:
-
the array indexed table
See also:
- AbstractList:ToTable()
-
Creates a new table of this AbstractList.
AbstractLists, being ordered and linear, use no indices that are not array
indices, so this provides a table identical to ToArray.
Inherited from:
Returns:
-
the table
See also:
- AbstractList:Unshift(item)
-
Adds an item to the beginning of the AbstractList.
Shifts other elements to make space.
This method is optional. All AbstractList implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.
This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this AbstractList.
Inherited from:
Parameters:
- item the item to add
Returns:
-
true if the AbstractList changed as a result, false otherwise