InstanceOf

The asdk.condition.InstanceOf class is used to test whether an object is an instance of a particular type. This implementation of the UnaryCondition interface, when executed, will determine whether objects passed to the execute method are an instance of the type that is passed in to the constructor. This allows for encapsulation of the logic for determining whether objects are actually an instance of a certain class. The example below demonstrates the use of this class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import asdk.*;
import asdk.condition.*;

var hashmap : HashMap = new HashMap();
var arraylist : ArrayList = new ArrayList();
var isHashmapCondition : UnaryCondition = new InstanceOf( HashMap );

var isHashmap = isHashmapCondition.execute( hashmap );
trace("isHashmap: " + isHashmap );
//displays isHashmap: true in output window

var isArraylist = isHashmapCondition.execute( arraylist );
trace("isArraylist: " + isArraylist );
//displays isArraylist: false in output window

In this example a HashMap and an ArrayList are created as well as a condition (line 6) that will test whether an object is actually a HashMap. When the condition is executed against the HashMap instance the result is true (lines 8-10), and false is returned when the condition is executed with the arraylist object (lines 12-14).