Package | org.as3collections.lists |
Class | public class TypedList |
Inheritance | TypedList TypedCollection Object |
Implements | IList |
Subclasses | TypedSortedList |
TypedList
works as a wrapper for a IList
object.
Since ActionScript 3.0 does not support typed arrays, TypedList
is a way to create typed lists.
It stores the wrapList
constructor's argument internaly.
So every method call to this class is forwarded to the wrappedList
object.
The methods that need to be checked for the type of the elements are previously validated before forward the call.
If the type of an element requested to be added to this list is incompatible with the type of the list a org.as3coreaddendum.errors.ClassCastError
is thrown.
The calls that are forwarded to the wrappedList
returns the return of the wrappedList
call.
TypedList
does not allow null
elements.
You can also create unique and typed lists. See below the link "ListUtil.getUniqueTypedList()".
See also
Property | Defined By | ||
---|---|---|---|
allEquatable : Boolean [read-only]
Indicates whether all elements in this collection implement the interface org.as3coreaddendum.system.IEquatable. | TypedCollection | ||
modCount : int [read-only]
Returns the return of the call wrappedList.modCount. | TypedList | ||
type : *
Defines the acceptable type of the elements by this collection. | TypedCollection |
Method | Defined By | ||
---|---|---|---|
Constructor, creates a new TypedList object. | TypedList | ||
add(element:*):Boolean
The element is validated with the validateType method to be forwarded to wrappedCollection.add. | TypedCollection | ||
addAll(collection:ICollection):Boolean
The collection is validated with the validateCollection method to be forwarded to wrappedCollection.addAll. | TypedCollection | ||
addAllAt(index:int, collection:ICollection):Boolean
The collection is validated to be forwarded to wrappedList.addAllAt. | TypedList | ||
addAt(index:int, element:*):Boolean
The element is validated to be forwarded to wrappedList.addAt. | TypedList | ||
clear():void
Forwards the call to wrappedCollection.clear. | TypedCollection | ||
clone():* [override]
Creates and return a new TypedList object with a clone of the wrappedList object. | TypedList | ||
contains(o:*):Boolean
Forwards the call to wrappedCollection.contains. | TypedCollection | ||
containsAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.containsAll. | TypedCollection | ||
equals(other:*):Boolean [override]
This method first checks if other argument is a TypedList. | TypedList | ||
getAt(index:int):*
Forwards the call to wrappedList.getAt. | TypedList | ||
indexOf(element:*, fromIndex:int = 0):int
Forwards the call to wrappedList.indexOf. | TypedList | ||
isEmpty():Boolean
Forwards the call to wrappedCollection.isEmpty. | TypedCollection | ||
Forwards the call to wrappedCollection.iterator. | TypedCollection | ||
lastIndexOf(element:*, fromIndex:int = 0x7fffffff):int
Forwards the call to wrappedList.lastIndexOf. | TypedList | ||
listIterator(index:int = 0):IListIterator
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list. | TypedList | ||
remove(o:*):Boolean
Forwards the call to wrappedCollection.remove. | TypedCollection | ||
removeAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.removeAll. | TypedCollection | ||
removeAt(index:int):*
Forwards the call to wrappedList.removeAt. | TypedList | ||
removeRange(fromIndex:int, toIndex:int):ICollection
Forwards the call to wrappedList.removeRange. | TypedList | ||
retainAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.retainAll. | TypedCollection | ||
reverse():void
Forwards the call to wrappedList.reverse. | TypedList | ||
setAt(index:int, element:*):*
The element is validated to be forwarded to wrappedList.setAt. | TypedList | ||
size():int
Forwards the call to wrappedCollection.size. | TypedCollection | ||
Returns a new TypedList(wrappedList.subList(fromIndex, toIndex)). | TypedList | ||
toArray():Array
Forwards the call to wrappedCollection.toArray. | TypedCollection | ||
toString():String
Returns the string representation of this instance. | TypedCollection |
modCount | property |
modCount:int
[read-only]
Returns the return of the call wrappedList.modCount
.
public function get modCount():int
TypedList | () | Constructor |
public function TypedList(wrapList:IList, type:*)
Constructor, creates a new TypedList
object.
wrapList:IList — the target list to wrap.
| |
type:* — the type of the elements allowed by this list.
|
ArgumentError — if the wrapList argument is null .
| |
ArgumentError — if the type argument is null .
| |
org.as3coreaddendum.errors:ClassCastError — if the types of one or more elements in the wrapList argument are incompatible with the type argument.
|
addAllAt | () | method |
public function addAllAt(index:int, collection:ICollection):Boolean
The collection is validated to be forwarded to wrappedList.addAllAt
.
Parameters
index:int | |
collection:ICollection — the collection to forward to wrappedList.addAllAt .
|
Boolean — the return of the call wrappedList.addAllAt .
|
org.as3coreaddendum.errors:ClassCastError — if the types of one or more elements in the collection argument are incompatible with the type of this list.
|
addAt | () | method |
public function addAt(index:int, element:*):Boolean
The element is validated to be forwarded to wrappedList.addAt
.
Parameters
index:int | |
element:* — the element to forward to wrappedList.addAt .
|
Boolean — the return of the call wrappedList.addAt .
|
org.as3coreaddendum.errors:ClassCastError — if the type of the element is incompatible with the type of this list.
|
clone | () | method |
override public function clone():*
Creates and return a new TypedList
object with a clone of the wrappedList
object.
* — a new TypedList object with a clone of the wrappedList object.
|
equals | () | method |
override public function equals(other:*):Boolean
This method first checks if other
argument is a TypedList
.
If not it returns false
.
If true
it checks the type
property of both lists.
If they are different it returns false
.
Otherwise it uses CollectionUtil.equalConsideringOrder
method to perform equality, sending this list and other
argument.
Parameters
other:* — the object to be compared for equality.
|
Boolean — true if the arbitrary evaluation considers the objects equal.
|
See also
getAt | () | method |
public function getAt(index:int):*
Forwards the call to wrappedList.getAt
.
Parameters
index:int |
* — the return of the call wrappedList.getAt .
|
indexOf | () | method |
public function indexOf(element:*, fromIndex:int = 0):int
Forwards the call to wrappedList.indexOf
.
Parameters
element:* | |
fromIndex:int (default = 0 )
|
int — the return of the call wrappedList.indexOf .
|
lastIndexOf | () | method |
public function lastIndexOf(element:*, fromIndex:int = 0x7fffffff):int
Forwards the call to wrappedList.lastIndexOf
.
Parameters
element:* | |
fromIndex:int (default = 0x7fffffff )
|
int — the return of the call wrappedList.lastIndexOf .
|
listIterator | () | method |
public function listIterator(index:int = 0):IListIterator
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list. The specified index indicates the first element that would be returned by an initial call to next
. An initial call to previous
would return the element with the specified index minus one.
This implementation returns an ListIterator
object.
Parameters
index:int (default = 0 ) — index of first element to be returned from the list iterator (by a call to the next method)
|
IListIterator — a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.
|
See also
removeAt | () | method |
public function removeAt(index:int):*
Forwards the call to wrappedList.removeAt
.
Parameters
index:int |
* — the return of the call wrappedList.removeAt .
|
removeRange | () | method |
public function removeRange(fromIndex:int, toIndex:int):ICollection
Forwards the call to wrappedList.removeRange
.
Parameters
fromIndex:int | |
toIndex:int |
ICollection — the return of the call wrappedList.removeRange .
|
reverse | () | method |
public function reverse():void
Forwards the call to wrappedList.reverse
.
setAt | () | method |
public function setAt(index:int, element:*):*
The element is validated to be forwarded to wrappedList.setAt
.
Parameters
index:int | |
element:* — the element to forward to wrappedList.setAt .
|
* — the return of the call wrappedList.setAt .
|
org.as3coreaddendum.errors:ClassCastError — if the type of the element is incompatible with the type of this list.
|
subList | () | method |
public function subList(fromIndex:int, toIndex:int):IList
Returns a new TypedList(wrappedList.subList(fromIndex, toIndex))
.
Modifications in the returned TypedList
object does not affect this list.
Parameters
fromIndex:int — the index to start retrieving elements (inclusive).
| |
toIndex:int — the index to stop retrieving elements (exclusive).
|
IList — a new TypedList(wrappedList.subList(fromIndex, toIndex)) .
|
IndexOutOfBoundsError — if fromIndex or toIndex is out of range (index < 0 || index > size()) .
|
import org.as3collections.IList; import org.as3collections.IListIterator; import org.as3collections.lists.ArrayList; import org.as3collections.lists.TypedList; import org.as3collections.utils.ListUtil; var l1:IList = new ArrayList([3, 5, 1, 7]); var list1:IList = new TypedList(l1, int); // you can use this way //var list1:IList = ListUtil.getTypedList(l1, int); // or you can use this way list1 // [3,5,1,7] list1.size() // 4 list1.add(8) // true list1 // [3,5,1,7,8] list1.size() // 5 list1.addAt(1, 4) // true list1 // [3,4,5,1,7,8] list1.size() // 6 list1.remove("abc") // false list1 // [3,4,5,1,7,8] list1.size() // 6 var it:IListIterator = list1.listIterator(); var e:int; while (it.hasNext()) { e = it.next() e // 3 e = it.next() e: // 4 e = it.next() e // 5 if (e == 5) { it.add(0) list1 // [3,4,5,0,1,7,8] list1.size() // 7 } e = it.next() e // 1 if (e == 1) { it.add(3) list1 // [3,4,5,0,1,3,7,8] list1.size() // 8 } e = it.next() e // 7 e = it.next() e // 8 if (e == 8) { it.add("ghi") // ClassCastError: Invalid element type. element: ghi | type: String | expected type: int } } list1 // [3,4,5,0,1,3,7,8] list1.size() // 8 list1.add("def") // ClassCastError: Invalid element type. element: def | type: String | expected type: int list1.setAt(0, 1) // 3 list1 // [1,4,5,0,1,3,7,8] list1.size() // 8 list1.setAt(0, [1,2]) // ClassCastError: Invalid element type. element: 1,2 | type: Array | expected type: int