Packageorg.as3collections.lists
Classpublic class UniqueList
InheritanceUniqueList Inheritance UniqueCollection Inheritance 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()".

View the examples

See also

ListUtil.getUniqueList()
ListUtil.getUniqueTypedList()


Public Properties
 PropertyDefined By
 InheritedallEquatable : 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
Public Methods
 MethodDefined By
  
UniqueList(wrapList:IList)
Constructor, creates a new UniqueList object.
UniqueList
 Inherited
add(element:*):Boolean
If wrappedCollection.contains(element) returns true, then this method returns false.
UniqueCollection
 Inherited
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
 Inherited
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
 Inherited
contains(o:*):Boolean
Forwards the call to wrappedCollection.contains.
UniqueCollection
 Inherited
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
 Inherited
isEmpty():Boolean
Forwards the call to wrappedCollection.isEmpty.
UniqueCollection
 Inherited
Forwards the call to wrappedCollection.iterator.
UniqueCollection
  
lastIndexOf(element:*, fromIndex:int = 0x7fffffff):int
Forwards the call to wrappedList.lastIndexOf.
UniqueList
  
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.
UniqueList
 Inherited
remove(o:*):Boolean
Forwards the call to wrappedCollection.remove.
UniqueCollection
 Inherited
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
 Inherited
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
 Inherited
size():int
Forwards the call to wrappedCollection.size.
UniqueCollection
  
subList(fromIndex:int, toIndex:int):IList
Returns a new UniqueList(wrappedList.subList(fromIndex, toIndex)).
UniqueList
 Inherited
toArray():Array
Forwards the call to wrappedCollection.toArray.
UniqueCollection
 Inherited
toString():String
Returns the string representation of this instance.
UniqueCollection
Property Detail
modCountproperty
modCount:int  [read-only]

Returns the return of the call wrappedList.modCount.


Implementation
    public function get modCount():int
Constructor Detail
UniqueList()Constructor
public function UniqueList(wrapList:IList)

Constructor, creates a new UniqueList object.

Parameters
wrapList:IList — the target list to wrap.

Throws
ArgumentError — if the wrappedList argument is null.
Method Detail
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.

Returns
Booleanfalse if the specified collection is null or empty. Otherwise returns the return of the call wrappedList.addAllAt.

Throws
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.

Returns
Booleanfalse 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.

Returns
* — 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.

Returns
Booleantrue 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

Returns
* — 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)

Returns
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)

Returns
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)

Returns
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

Returns
* — 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

Returns
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:*

Returns
*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).

Returns
IList — a new UniqueList(wrappedList.subList(fromIndex, toIndex)).

Throws
IndexOutOfBoundsError — if fromIndex or toIndex is out of range (index < 0 || index > size()).
Examples
     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