The asdk.algorithm.Filtering
class provides several static functions for filtering elements out of a collection.
The primary functions of the Filtering class enable excluding items, including items, and maintaining uniqueness within collections.
The example below demonstrates each of these features by operating on an ArrayList.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
var groceryCart:asdk.Collection = new asdk.ArrayList(); |
The UnaryCondition that is instantiated on line 7 is used to filter the groceryCart collection. When the include method is invoke (line 9) any item that is equal to "oranges" is included in the returned collection. When the exclude method is invoked (line 13), the "oranges" items are excluded from the returned collection. The unique method invocation (line 16) simply returns a set that does not contain any duplicates.
Although this example deals with a homogeneous collection (all the elements are of type String), a collection could be heterogeneous. If there are multiple types of objects stored in a collection these objects can be filtered as well by using an asdk.condition.InstanceOf unary condition to filter out certain objects based on their type.