Overview of J sets
Purpose
J programs use sets extensively in their processing. Sets facilitate the browsing of a model and allow the easy handling of groups of objects.
The metamodel has numerous cases of n-ary associations between classes (for example, package classes, class operations or operation parameters). Their access is easily processed through sets.
Notation
Sets are defined with the "class of the elements[]" class, such as Object[], String[], Class[], and so on.
Declaration
The
following declaration is used to obtain an empty set of objects "Object":
Object[] E;
Order of the elements
Set elements are put in a certain order. The order of insertion in the set will be the order of the scanning of these elements when anonymous methods are diffused or applied. The order is very important in the metamodel.
For example, the order in which class operations are accessed in the "PartOperation" object is the order in which these operations appear in the model, as well as in the parameters of an operation (IOParameter), etc.
Assignment between sets
Sets are considered as basic classes.
The assignment between sets, therefore, copies the value of a set into
another set. The example below shows a trick used to empty a set,
given that a declared set is empty by default.
Feature[] E1;
Feature[] Emptied;
E1 = PartFeature;
...
E1 = Emptied; //
E1 becomes an empty set
Example
The example
below is used to list the names of all the parameters of all the operations of
the current class.
Firstly, an anonymous method is used, and then a diffused message
carries out the same processing.
// First case : anonymous method
PartOperation
{
IOParameter
{
StdOut.write(Name, ", ");
}
}
// Second case : message diffusion
Parameter:Print()
{
StdOut.write(Name, ", ");
}//End of "Print" method
//PartOperation
{
IOParameter.<Print();
// message diffusion "Print()"
}
Empty set
The "notVoid" service can be used to test whether or not a set is empty.
If (notVoid (mySet))
//non empty set
else
//empty set
Note: A void service, which carries out the opposite operation, also exists.