UnaryAnd

The asdk.condition.UnaryAnd class is used to add and logic to two UnaryConditions. It provides an implementation of the UnaryCondition interface that allows for more than one unary condition objects to be combined returning true only if all the unary conditions are true. One common case for using the UnaryAnd condition is to test whether collection is both non-null and not empty before processing its elements. The example below combines the asdk.condition.NotNull and asdk.condition.PositiveNumber conditions to verify the contents of an ArrayList using a UnaryAnd object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import asdk.*;
import asdk.condition.*;

var nullList : ArrayList;
var emptyList : ArrayList = new ArrayList();
var arrayList : ArrayList = new ArrayList();
arrayList.addItem( "item1" );

var notNull:UnaryCondition = new NotNull();
var positiveNumber:UnaryCondition = new PositiveNumber();
var andCondition:UnaryCondition = new UnaryAnd( notNull, positiveNumber );

var nullListHasElements = andCondition.execute( nullList.getSize() );
trace("nullListHasElements: " + nullListHasElements );
//displays nullListHasElements: false in output window

var emptyListHasElements = andCondition.execute( emptyList.getSize() );
trace("emptyListHasElements: " + emptyListHasElements );
//displays emptyListHasElements: false in output window

var arrayListHasElements = andCondition.execute( arrayList.getSize() );
trace("arrayListHasElements: " + arrayListHasElements );
//displays arrayListHasElements: true in output window

This example combines the functionality of both NotNull and PositiveNumber to only return true if the value passed to the execute method is both not null and positive. This kind of combination allows for encapsulating the logic of a non-empty collection into a single UnaryAnd object.