Collection iteration

When retrieving information from a model, very often there is a need to access data stored in collections, and then iterate over these collections. MQL's dotted notation performs these tasks for you.

For example, in Java we would need to iterate over all classes, then iterate over all of their features, and then collect the feature names.

/*--------------- JAVA code ---------------*/
// Getting all the feature names of all the classes in the current model
com.sodius.mdw.core.model.Model uml = ...; 
java.util.List featureNames = new java.util.ArrayList();

// Iterates on all classes in the current model
for (java.util.Iterator classes = uml.getInstances("Class").iterator(); i.hasNext(); ) {
    Class myClass = (Class) classes.next(); 
    
    // Iterates on features of each class
    for (Iterator i = myClass.getFeature().iterator(); i.hasNext(); ) {
        Feature feature = (Feature) i.next();
        featureNames.add(feature.getName());
    }
}

In MQL this becomes a simple line.

/*--------------- MQL code ---------------*/
// Returns a list containing the name of each feature of each class
var featureNames = uml.getInstances("Class").feature.name