Packagecom.yworks.bridge.util
Classpublic class Collections
InheritanceCollections Inheritance YObject Inheritance Object

Collections contains static methods which operate on Collection classes.



Public Methods
 MethodDefined By
  
Collections(init:Boolean = true)
Collections
  
addAll(c:Collection, a:Vector.<Object>):Boolean
[static] Adds all the specified elements to the specified collection
Collections
  
binarySearch(list:List, object:Object):int
[static] Performs a binary search for the specified element in the specified sorted List.
Collections
  
binarySearchWithComparator(list:List, object:Object, comparator:Comparator):int
[static] Performs a binary search for the specified element in the specified sorted List using the specified Comparator.
Collections
  
copy(destination:List, source:List):void
[static] Copies the elements from the source list to the destination list.
Collections
  
[static] Returns true if the collections have no elements in common
Collections
  
[static] Returns a type-safe empty, immutable com.yworks.bridge.util.List.
Collections
  
[static] Returns a type-safe empty, immutable com.yworks.bridge.util.Map.
Collections
  
[static] Returns a type-safe empty, immutable com.yworks.bridge.util.Set.
Collections
 Inherited
equals(o:Object):Boolean
YObject
  
fill(list:List, object:Object):void
[static] Fills the specified List with the specified element.
Collections
  
frequency(c:Collection, o:Object):int
[static] Returns the number of elements in the Collection that match the Object passed.
Collections
  
getClass():Class
[override]
Collections
 Inherited
hashCode():int
YObject
  
indexOfSubList(list:List, sublist:List):int
[static] Searches the list for sublist and answers the beginning index of the first occurrence.
Collections
  
lastIndexOfSubList(list:List, sublist:List):int
[static] Searches the list for sublist and answers the beginning index of the last occurrence.
Collections
  
max(collection:Collection):Object
[static] Searches the specified Collection for the maximum element.
Collections
  
max2(collection:Collection, comparator:Comparator):Object
[static] Searches the specified Collection for the maximum element using the specified Comparator.
Collections
  
min(collection:Collection):Object
[static] Searches the specified Collection for the minimum element.
Collections
  
min2(collection:Collection, comparator:Comparator):Object
[static] Searches the specified Collection for the minimum element using the specified Comparator.
Collections
  
nCopies(length:int, object:Object):List
[static] Answers a List containing the specified number of the specified element.
Collections
  
replaceAll(list:List, obj:Object, obj2:Object):Boolean
[static] Replaces all occurrences of Object obj in list with newObj.
Collections
  
reverse(list:List):void
[static] Returns the supplied List with the order of its contained elements reversed.
Collections
  
[static] A Comparator which reverses the natural order of the elements.
Collections
  
[static] Returns a Comparator that reverses the order of the Comparator passed.
Collections
  
rotate(lst:List, dist:int):void
[static] Rotates the elements in List list by the distance dist.
Collections
  
shuffle(list:List):void
[static] Moves every element of the List to a random new position in the list.
Collections
  
shuffle2(list:List, random:Random):void
[static] Moves every element of the List to a random new position in the list using the specified random number generator.
Collections
  
singleton(object:Object):Set
[static] Answers a Set containing the specified element.
Collections
  
singletonList(object:Object):List
[static] Answers a List containing the specified element.
Collections
  
singletonMap(key:Object, value:Object):Map
[static] Answers a Map containing the specified key and value.
Collections
  
sort(list:List, comparator:Comparator):void
[static] Sorts the specified List using the specified Comparator.
Collections
  
sort2(list:List):void
[static] Sorts the specified List in ascending order.
Collections
  
swap(list:List, index1:int, index2:int):void
[static] Swaps the elements of List list at indices index1 and index2
Collections
  
[static] Answers a wrapper on the specified Collection which synchronizes all access to the Collection.
Collections
  
[static] Answers a wrapper on the specified List which synchronizes all access to the List.
Collections
  
[static] Answers a wrapper on the specified Map which synchronizes all access to the Map.
Collections
  
[static] Answers a wrapper on the specified Set which synchronizes all access to the Set.
Collections
  
[static] Answers a wrapper on the specified SortedMap which synchronizes all access to the SortedMap.
Collections
  
[static] Answers a wrapper on the specified SortedSet which synchronizes all access to the SortedSet.
Collections
  
[static] Answers a wrapper on the specified Collection which throws an UnsupportedOperationException whenever an attempt is made to modify the Collection.
Collections
  
[static] Answers a wrapper on the specified List which throws an UnsupportedOperationException whenever an attempt is made to modify the List.
Collections
  
[static] Answers a wrapper on the specified Map which throws an UnsupportedOperationException whenever an attempt is made to modify the Map.
Collections
  
[static] Answers a wrapper on the specified Set which throws an UnsupportedOperationException whenever an attempt is made to modify the Set.
Collections
  
[static] Answers a wrapper on the specified SortedMap which throws an UnsupportedOperationException whenever an attempt is made to modify the SortedMap.
Collections
  
[static] Answers a wrapper on the specified SortedSet which throws an UnsupportedOperationException whenever an attempt is made to modify the SortedSet.
Collections
Public Constants
 ConstantDefined By
  EMPTY_LIST : List
[static] An immutable, serializable, empty List.
Collections
  EMPTY_MAP : Map
[static] An immutable, serializable, empty Map.
Collections
  EMPTY_SET : Set
[static] An immutable, serializable, empty Set.
Collections
Constructor Detail
Collections()Constructor
public function Collections(init:Boolean = true)



Parameters
init:Boolean (default = true)
Method Detail
addAll()method
public static function addAll(c:Collection, a:Vector.<Object>):Boolean

Adds all the specified elements to the specified collection

Parameters

c:Collection — the collection the elements are to be inserted into
 
a:Vector.<Object> — the elements to insert

Returns
Boolean — true if the collection changed during insertion

Throws
flash.errors:IllegalOperationError — when the method is not supported
 
ReferenceError — when c or elements is null, or elements contains one or more null elements and c doesn't support null elements
binarySearch()method 
public static function binarySearch(list:List, object:Object):int

Performs a binary search for the specified element in the specified sorted List.

Parameters

list:List — the sorted List to search
 
object:Object — the element to find

Returns
int — the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted

Throws
TypeError — when an element in the List or the search element does not implement Comparable, or cannot be compared to each other
binarySearchWithComparator()method 
public static function binarySearchWithComparator(list:List, object:Object, comparator:Comparator):int

Performs a binary search for the specified element in the specified sorted List using the specified Comparator.

Parameters

list:List — the sorted List to search
 
object:Object — the element to find
 
comparator:Comparator — the Comparator. If the comparator is null then the search uses the objects' natural ordering.

Returns
int — the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted

Throws
TypeError — when an element in the list and the searched element cannot be compared to each other using the Comparator
copy()method 
public static function copy(destination:List, source:List):void

Copies the elements from the source list to the destination list.

Parameters

destination:List
 
source:List


Throws
RangeError — when the destination List is smaller than the source List
 
flash.errors:IllegalOperationError — when replacing an element in the destination list is not supported
disjoint()method 
public static function disjoint(c1:Collection, c2:Collection):Boolean

Returns true if the collections have no elements in common

Parameters

c1:Collection — the first collection
 
c2:Collection — the second collection

Returns
Boolean — true if the collections have no elements in common

Throws
ReferenceError — if one of the collections is null
emptyList()method 
public static function emptyList():List

Returns a type-safe empty, immutable com.yworks.bridge.util.List.

Returns
List — An empty com.yworks.bridge.util.List.

See also

emptyMap()method 
public static function emptyMap():Map

Returns a type-safe empty, immutable com.yworks.bridge.util.Map.

Returns
Map — An empty com.yworks.bridge.util.Map.

See also

emptySet()method 
public static function emptySet():Set

Returns a type-safe empty, immutable com.yworks.bridge.util.Set.

Returns
Set — An empty com.yworks.bridge.util.Set.

See also

fill()method 
public static function fill(list:List, object:Object):void

Fills the specified List with the specified element.

Parameters

list:List — the List to fill
 
object:Object — the fill element


Throws
flash.errors:IllegalOperationError — when replacing an element in the List is not supported
frequency()method 
public static function frequency(c:Collection, o:Object):int

Returns the number of elements in the Collection that match the Object passed. If the Object is null, then the number of null elements is returned.

Parameters

c:Collection — The Collection to search.
 
o:Object — The Object to search for.

Returns
int — The number of matching elements.

Throws
ReferenceError — if the Collection parameter is null.
getClass()method 
override public function getClass():Class

Returns
Class
indexOfSubList()method 
public static function indexOfSubList(list:List, sublist:List):int

Searches the list for sublist and answers the beginning index of the first occurrence.

-1 is returned if the sublist does not exist in list.

Parameters

list:List — the List to search sublist in
 
sublist:List — the List to search in list

Returns
int — the beginning index of the first occurrence of sublist in list, or -1
lastIndexOfSubList()method 
public static function lastIndexOfSubList(list:List, sublist:List):int

Searches the list for sublist and answers the beginning index of the last occurrence.

-1 is returned if the sublist does not exist in list.

Parameters

list:List — the List to search sublist in
 
sublist:List — the List to search in list

Returns
int — the beginning index of the last occurrence of sublist in list, or -1
max()method 
public static function max(collection:Collection):Object

Searches the specified Collection for the maximum element.

Parameters

collection:Collection — the Collection to search

Returns
Object — the maximum element in the Collection

Throws
TypeError — when an element in the Collection does not implement Comparable or elements cannot be compared to each other
max2()method 
public static function max2(collection:Collection, comparator:Comparator):Object

Searches the specified Collection for the maximum element using the specified Comparator.

Parameters

collection:Collection — the Collection to search
 
comparator:Comparator — the Comparator

Returns
Object — the maximum element in the Collection

Throws
TypeError — when elements in the Collection cannot be compared to each other using the Comparator
min()method 
public static function min(collection:Collection):Object

Searches the specified Collection for the minimum element.

Parameters

collection:Collection — the Collection to search

Returns
Object — the minimum element in the Collection

Throws
TypeError — when an element in the Collection does not implement Comparable or elements cannot be compared to each other
min2()method 
public static function min2(collection:Collection, comparator:Comparator):Object

Searches the specified Collection for the minimum element using the specified Comparator.

Parameters

collection:Collection — the Collection to search
 
comparator:Comparator — the Comparator

Returns
Object — the minimum element in the Collection

Throws
TypeError — when elements in the Collection cannot be compared to each other using the Comparator
nCopies()method 
public static function nCopies(length:int, object:Object):List

Answers a List containing the specified number of the specified element. The list cannot be modified.

Parameters

length:int — the size of the returned List
 
object:Object — the element

Returns
List — a List containing length copies of the element

Throws
IllegalArgumentException — when length < 0
replaceAll()method 
public static function replaceAll(list:List, obj:Object, obj2:Object):Boolean

Replaces all occurrences of Object obj in list with newObj. If the obj is null, then all occurrences of null is replaced with newObj.

Parameters

list:List — the List to modify
 
obj:Object — the Object to find and replace occurrences of.
 
obj2:Object — the Object to replace all occurrences of obj in list

Returns
Boolean — true, if at least one occurrence of obj has been found in list

Throws
flash.errors:IllegalOperationError — if the list does not support setting elements
reverse()method 
public static function reverse(list:List):void

Returns the supplied List with the order of its contained elements reversed.

Parameters

list:List — the List to reverse


Throws
flash.errors:IllegalOperationError — when replacing an element in the List is not supported
reverseOrder()method 
public static function reverseOrder():Comparator

A Comparator which reverses the natural order of the elements.

Returns
Comparator — A Comparator instance.

See also

reverseOrder2()method 
public static function reverseOrder2(c:Comparator):Comparator

Returns a Comparator that reverses the order of the Comparator passed. If the Comparator passed is null, then this method is equivalent to reverseOrder().

The Comparator that's returned is java.io.Serializable if the Comparator passed is serializable or null.

Parameters

c:Comparator — The Comparator to reverse or null.

Returns
Comparator — A Comparator instance.

See also

Comparator
reverseOrder()
java.io.Serializable
rotate()method 
public static function rotate(lst:List, dist:int):void

Rotates the elements in List list by the distance dist.

E.g. for a given list with elements [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], calling rotate(list, 3) or rotate(list, -7) would modify the list to look like this: [8, 9, 0, 1, 2, 3, 4, 5, 6, 7].

Parameters

lst:List
 
dist:int — It can be any integer: 0, positive, negative, larger than the list size

shuffle()method 
public static function shuffle(list:List):void

Moves every element of the List to a random new position in the list.

Parameters

list:List — the List to shuffle


Throws
flash.errors:IllegalOperationError — when replacing an element in the List is not supported
shuffle2()method 
public static function shuffle2(list:List, random:Random):void

Moves every element of the List to a random new position in the list using the specified random number generator.

Parameters

list:List — the List to shuffle
 
random:Random — the random number generator


Throws
flash.errors:IllegalOperationError — when replacing an element in the List is not supported
singleton()method 
public static function singleton(object:Object):Set

Answers a Set containing the specified element. The set cannot be modified.

Parameters

object:Object — the element

Returns
Set — a Set containing the element
singletonList()method 
public static function singletonList(object:Object):List

Answers a List containing the specified element. The list cannot be modified.

Parameters

object:Object — the element

Returns
List — a List containing the element
singletonMap()method 
public static function singletonMap(key:Object, value:Object):Map

Answers a Map containing the specified key and value. The map cannot be modified.

Parameters

key:Object — the key
 
value:Object — the value

Returns
Map — a Map containing the key and value
sort()method 
public static function sort(list:List, comparator:Comparator):void

Sorts the specified List using the specified Comparator.

Parameters

list:List — the List to be sorted
 
comparator:Comparator — the Comparator


Throws
TypeError — when elements in the List cannot be compared to each other using the Comparator
sort2()method 
public static function sort2(list:List):void

Sorts the specified List in ascending order.

Parameters

list:List — the List to be sorted


Throws
TypeError — when an element in the List does not implement Comparable or elements cannot be compared to each other
swap()method 
public static function swap(list:List, index1:int, index2:int):void

Swaps the elements of List list at indices index1 and index2

Parameters

list:List — the List to manipulate on
 
index1:int — int position of the first element to swap with the element in index2
 
index2:int — int position of the other element


Throws
RangeError — if index1 or index2 is out of range of this list
synchronizedCollection()method 
public static function synchronizedCollection(collection:Collection):Collection

Answers a wrapper on the specified Collection which synchronizes all access to the Collection.

Parameters

collection:Collection — the Collection

Returns
Collection — a synchronized Collection
synchronizedList()method 
public static function synchronizedList(list:List):List

Answers a wrapper on the specified List which synchronizes all access to the List.

Parameters

list:List — the List

Returns
List — a synchronized List
synchronizedMap()method 
public static function synchronizedMap(map:Map):Map

Answers a wrapper on the specified Map which synchronizes all access to the Map.

Parameters

map:Map — the Map

Returns
Map — a synchronized Map
synchronizedSet()method 
public static function synchronizedSet(_set:Set):Set

Answers a wrapper on the specified Set which synchronizes all access to the Set.

Parameters

_set:Set — the Set

Returns
Set — a synchronized Set
synchronizedSortedMap()method 
public static function synchronizedSortedMap(map:SortedMap):SortedMap

Answers a wrapper on the specified SortedMap which synchronizes all access to the SortedMap.

Parameters

map:SortedMap — the SortedMap

Returns
SortedMap — a synchronized SortedMap
synchronizedSortedSet()method 
public static function synchronizedSortedSet(_set:SortedSet):SortedSet

Answers a wrapper on the specified SortedSet which synchronizes all access to the SortedSet.

Parameters

_set:SortedSet — the SortedSet

Returns
SortedSet — a synchronized SortedSet
unmodifiableCollection()method 
public static function unmodifiableCollection(collection:Collection):Collection

Answers a wrapper on the specified Collection which throws an UnsupportedOperationException whenever an attempt is made to modify the Collection.

Parameters

collection:Collection — the Collection

Returns
Collection — an unmodifiable Collection
unmodifiableList()method 
public static function unmodifiableList(list:List):List

Answers a wrapper on the specified List which throws an UnsupportedOperationException whenever an attempt is made to modify the List.

Parameters

list:List — the List

Returns
List — an unmodifiable List
unmodifiableMap()method 
public static function unmodifiableMap(map:Map):Map

Answers a wrapper on the specified Map which throws an UnsupportedOperationException whenever an attempt is made to modify the Map.

Parameters

map:Map — the Map

Returns
Map — a unmodifiable Map
unmodifiableSet()method 
public static function unmodifiableSet(_set:Set):Set

Answers a wrapper on the specified Set which throws an UnsupportedOperationException whenever an attempt is made to modify the Set.

Parameters

_set:Set — the Set

Returns
Set — a unmodifiable Set
unmodifiableSortedMap()method 
public static function unmodifiableSortedMap(map:SortedMap):SortedMap

Answers a wrapper on the specified SortedMap which throws an UnsupportedOperationException whenever an attempt is made to modify the SortedMap.

Parameters

map:SortedMap — the SortedMap

Returns
SortedMap — a unmodifiable SortedMap
unmodifiableSortedSet()method 
public static function unmodifiableSortedSet(_set:SortedSet):SortedSet

Answers a wrapper on the specified SortedSet which throws an UnsupportedOperationException whenever an attempt is made to modify the SortedSet.

Parameters

_set:SortedSet — the SortedSet

Returns
SortedSet — a unmodifiable SortedSet
Constant Detail
EMPTY_LISTConstant
public static const EMPTY_LIST:List

An immutable, serializable, empty List.

See also

EMPTY_MAPConstant 
public static const EMPTY_MAP:Map

An immutable, serializable, empty Map.

See also

EMPTY_SETConstant 
public static const EMPTY_SET:Set

An immutable, serializable, empty Set.

See also