- Author:
- Randall Britten <r.britten@auckland.ac.nz>
- Date:
- 2013-04-17 15:40:27+12:00
- Desc:
- Trivial whitespace changes, and moved import to be adjacent to peer import.
- Permanent Source URI:
- https://models.cellml.org/w/matthiaskoenig/MetabolicComponentLibrary/rawfile/38fe44af096fb53d9b250091fe0563b33b5f778f/CellML-source/CellMLTools/src/cellmlexamples/IterateElementTest.java
package cellmlexamples;
import tools.CellMLLoader;
import tools.CellMLReader;
import cellml_api.CellMLComponent;
import cellml_api.CellMLComponentIterator;
import cellml_api.CellMLComponentSet;
import cellml_api.CellMLVariable;
import cellml_api.CellMLVariableIterator;
import cellml_api.CellMLVariableSet;
import cellml_api.Connection;
import cellml_api.ConnectionIterator;
import cellml_api.ConnectionSet;
import cellml_api.MapComponents;
import cellml_api.MapVariables;
import cellml_api.MapVariablesIterator;
import cellml_api.MapVariablesSet;
import cellml_api.Model;
public class IterateElementTest {
CellMLLoader cLoader;
public IterateElementTest(){
cLoader = new CellMLLoader();
}
/** Iterate over the CellML model elements. */
private void iterateModelElements(){
// load model from URL
Model model = CellMLReader.loadFromURL(cLoader.getCellMLBootstrap(),
"http://www.cellml.org/models/hodgkin_huxley_1952_version07/download");
System.out.println("Model Name:" + model.getName() + "\n");
// get all components
CellMLComponentSet componentSet = model.getModelComponents();
CellMLComponentIterator iter = componentSet.iterateComponents();
for(int i = 0; i < componentSet.getLength(); i++){
CellMLComponent comp = iter.nextComponent();
System.out.println("Component Name:"+comp.getName());
CellMLVariableSet variableSet = comp.getVariables();
CellMLVariableIterator varIter = variableSet.iterateVariables();
for(int j = 0; j < variableSet.getLength(); j ++){
CellMLVariable variable = varIter.nextVariable();
System.out.println("Variable Name:"+variable.getName());
}
System.out.println();
}
ConnectionSet connectionSet = model.getConnections();
ConnectionIterator conIter = connectionSet.iterateConnections();
for(int i = 0; i < connectionSet.getLength(); i++){
Connection connection = conIter.nextConnection();
MapComponents mapComponent = connection.getComponentMapping();
System.out.println("Connection Component1: "+mapComponent.getFirstComponentName() +
" Component2: " + mapComponent.getSecondComponentName());
MapVariablesSet variableSet = connection.getVariableMappings();
MapVariablesIterator varIter = variableSet.iterateMapVariables();
for(int j =0; j < variableSet.getLength(); j++){
MapVariables mapVar = varIter.nextMapVariable();
System.out.println("\t Variable1: "+mapVar.getFirstVariableName() +
" Variable2: " + mapVar.getSecondVariableName());
}
System.out.println();
}
}
public static void main(String [] args ){
IterateElementTest ietest = new IterateElementTest();
ietest.iterateModelElements();
}
}