Package | org.as3collections.lists |
Class | public class UniqueList |
Inheritance | UniqueList UniqueCollection Object |
Implements | IList |
Subclasses | UniqueSortedList |
UniqueList
works as a wrapper for a IList
object.
It does not allow duplicated elements in the collection.
It stores the wrapList
constructor's argument in the wrappedList
variable.
So every method call to this class is forwarded to the wrappedList
object.
The methods that need to be checked for duplication are previously validated before forward the call.
No error is thrown by the validation of duplication.
The calls that are forwarded to the wrappedList
returns the return of the wrappedList
call.
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. | UniqueCollection | ||
modCount : int [read-only]
Returns the return of the call wrappedList.modCount. | UniqueList |
Method | Defined By | ||
---|---|---|---|
UniqueList(wrapList:IList)
Constructor, creates a new UniqueList object. | UniqueList | ||
add(element:*):Boolean
If wrappedCollection.contains(element) returns true, then this method returns false. | UniqueCollection | ||
addAll(collection:ICollection):Boolean
If the specified collection is empty returns false. | UniqueCollection | ||
addAllAt(index:int, collection:ICollection):Boolean
If the specified collection is empty returns false. | UniqueList | ||
addAt(index:int, element:*):Boolean
If wrappedList.contains(element) returns true then returns false. | UniqueList | ||
clear():void
Forwards the call to wrappedCollection.clear. | UniqueCollection | ||
clone():* [override]
Creates and return a new UniqueList object with the clone of the wrappedList object. | UniqueList | ||
contains(o:*):Boolean
Forwards the call to wrappedCollection.contains. | UniqueCollection | ||
containsAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.containsAll. | UniqueCollection | ||
equals(other:*):Boolean [override]
This method uses CollectionUtil.equalConsideringOrder method to perform equality, sending this list and other argument. | UniqueList | ||
getAt(index:int):*
Forwards the call to wrappedList.getAt. | UniqueList | ||
indexOf(element:*, fromIndex:int = 0):int
Forwards the call to wrappedList.indexOf. | UniqueList | ||
isEmpty():Boolean
Forwards the call to wrappedCollection.isEmpty. | UniqueCollection | ||
Forwards the call to wrappedCollection.iterator. | UniqueCollection | ||
lastIndexOf(element:*, fromIndex:int = 0x7fffffff):int
Forwards the call to wrappedList.lastIndexOf. | UniqueList | ||
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. | UniqueList | ||
remove(o:*):Boolean
Forwards the call to wrappedCollection.remove. | UniqueCollection | ||
removeAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.removeAll. | UniqueCollection | ||
removeAt(index:int):*
Forwards the call to wrappedList.removeAt. | UniqueList | ||
removeRange(fromIndex:int, toIndex:int):ICollection
Forwards the call to wrappedList.removeRange. | UniqueList | ||
retainAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.retainAll. | UniqueCollection | ||
reverse():void
Forwards the call to wrappedList.reverse. | UniqueList | ||
setAt(index:int, element:*):*
If wrappedList.contains(element) returns true then returns false. | UniqueList | ||
size():int
Forwards the call to wrappedCollection.size. | UniqueCollection | ||
Returns a new UniqueList(wrappedList.subList(fromIndex, toIndex)). | UniqueList | ||
toArray():Array
Forwards the call to wrappedCollection.toArray. | UniqueCollection | ||
toString():String
Returns the string representation of this instance. | UniqueCollection |
modCount | property |
modCount:int
[read-only]
Returns the return of the call wrappedList.modCount
.
public function get modCount():int
UniqueList | () | Constructor |
public function UniqueList(wrapList:IList)
Constructor, creates a new UniqueList
object.
wrapList:IList — the target list to wrap.
|
ArgumentError — if the wrappedList argument is null .
|
addAllAt | () | method |
public function addAllAt(index:int, collection:ICollection):Boolean
If the specified collection is empty returns false
.
Otherwise, it clones the specified collection, removes from the cloned collection all elements that already are in the wrappedList
and removes all duplicates.
Then it forwards the call to wrappedList.addAllAt
sending the cloned (and filtered) collection.
Parameters
index:int — index at which to insert the first element from the specified collection.
| |
collection:ICollection — the collection to forward to wrappedList.addAllAt .
|
Boolean — false if the specified collection is null or empty. Otherwise returns the return of the call wrappedList.addAllAt .
|
ArgumentError — if the specified collection contains a null element and wrappedList does not permit null elements, or if the specified collection is null .
|
addAt | () | method |
public function addAt(index:int, element:*):Boolean
If wrappedList.contains(element)
returns true
then returns false
.
Otherwise, it forwards the call to wrappedList.addAt
.
Parameters
index:int — index at which the specified element is to be inserted.
| |
element:* — the element to be added.
|
Boolean — false if wrappedList.contains(element) returns true . Otherwise returns the return of the call wrappedList.addAt .
|
clone | () | method |
override public function clone():*
Creates and return a new UniqueList
object with the clone of the wrappedList
object.
* — a new UniqueList object with the clone of the wrappedList object.
|
equals | () | method |
override public function equals(other:*):Boolean
This method 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:*):*
If wrappedList.contains(element)
returns true
then returns false
. Otherwise, it forwards the call to wrappedList.setAt
.
Parameters
index:int | |
element:* |
* — false if wrappedList.contains(element) returns true . Otherwise returns the return of the call wrappedList.setAt .
|
subList | () | method |
public function subList(fromIndex:int, toIndex:int):IList
Returns a new UniqueList(wrappedList.subList(fromIndex, toIndex))
.
Modifications in the returned UniqueList
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 UniqueList(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.UniqueList; import org.as3collections.utils.ListUtil; var l1:IList = new ArrayList([3, 5, 1, 7]); var list1:IList = new UniqueList(l1); // you can use this way //var list1:IList = ListUtil.getUniqueList(l1); // or you can use this way list1 // [3,5,1,7] list1.size() // 4 list1.addAt(1, 4) // true list1 // [3,4,5,1,7] list1.size() // 5 list1.addAt(2, 3) // false list1 // [3,4,5,1,7] list1.size() // 5 list1.add(5) // false list1 // [3,4,5,1,7] list1.size() // 5 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] list1.size() // 6 } e = it.next() e // 1 if (e == 1) { it.add(3) list1 // [3,4,5,0,1,7] list1.size() // 6 } e = it.next() e // 7 } list1 // [3,4,5,0,1,7] list1.size() // 6 var l2:IList = new ArrayList([1, 2, 3, 4, 5, 1, 3, 5]); var list2:IList = new UniqueList(l2); // you can use this way //var list2:IList = ListUtil.getUniqueList(l2); // or you can use this way list2 // [1,2,3,4,5] list2.size() // 5