.. - .. * #%L .. * IsisFish .. * .. * $Id$ .. * $HeadURL$ .. * %% .. * Copyright (C) 1999 - 2010 Ifremer, Code Lutin .. * %% .. * This program is free software: you can redistribute it and/or modify .. * it under the terms of the GNU General Public License as .. * published by the Free Software Foundation, either version 3 of the .. * License, or (at your option) any later version. .. * .. * This program is distributed in the hope that it will be useful, .. * but WITHOUT ANY WARRANTY; without even the implied warranty of .. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .. * GNU General Public License for more details. .. * .. * You should have received a copy of the GNU General Public .. * License along with this program. If not, see .. * . .. * #L% .. - Tutorial for the use of APIs ========================== Before you start… First, don’t panic! You need to know that all the values entered in the interface by users are stored in corresponding ISIS objects. To modify those values, that is to say, the attributes of the objects, you need to know their nature and structure, how to access and modify them. To do so, the dependency between objects must be understood. The architecture of the database is available here ( `Modele ISIS-Fish`_ ) but also reflected by the architecture of the tree in the input interface. To know how to pass from an object to another you need to find the corresponding method in the API. Remark: Start by getting to know the various Java objects (double, boolean, string, integer, equation, matrix,...)(cf tutoriaux JAVA). Here is an example « step by step » in the case where you want to modify the natural mortality equation (in a simulation plan for instance). We want to replace temporarily the equation in the database with another one. You need to create an object equation. First start by creating an object String containing the new equation:: String mortalitenaturelle = "if (groupe.getId() == 0) return 1.5; else return 0.2;" Then ask yourself: "In the database where is natural mortality?" ------------------------------------------------------------------------------------- Answer: In the input interface, in the branch for "population" and the equation tab. (here the name of the tab inform on the type of objects listed here, most likely equations). In English, you would say, in population, get the equation for natural mortality which is filled with a string. Open API pages ----------------------- On the left, under « all classes », look for th entity « population » (the one in italic), clic on it. Available methods ------------------------ All the methods available for an object of type « population » appear in a table. The second column tells the method name and arguments it takes, the first column tells the type of object the method returns. The code you will write should look like this:: Type_of_object_returned_by_the_method_on_left_side objectName = population.method(method arguments); There are mostly 2 kinds of methods : * methods "get" : get an object * methods "set" : set the value of an object. In our example we eventually want to change a value, so “set”. Look for a method dealing with natural mortality ---------------------------------------------------------- You find getNaturalDeathRate() which returns an equation (it is the object equation which contains the value of the equation of natural mortality filled by the user in the interface) and setNaturalDeathRate(Equation naturalDeathRate) which receives as argument an equation. (Note: a clic on the method name gives you further information on the method) setNaturalDeathRate() seems appropriate... However the method takes an equation as argument and not a String, we thus cannot write:: pop.setNaturalDeathRate(mortalitenaturelle); Create an equation ------------------ So next step, how to transform a string into an equation. Clic on « equation » on the API page, you are re-directed toward the pages of methods for equations. You will find a method .setContent(String ) which takes a string as argument and returns an equation. So that means that applied to an equation this method changes the value of the equation according to what’s written in the string. We know how to GET the equation we want to change:: Equation eqMortalite = pop.getNaturalDeathRate(); Then to change its content:: eqMortalite.setContent(mortalitenaturelle); Voilà ! Note it could also be done in a single line:: pop.getNaturalDeathRate().setContent(mortalitenaturelle); Note too that even if the equation is stored in another object with a new name (eqMortalite) the original equation in the database is modified. So be careful if you want to work on equations or matrices from the database without changing them, start by making copies and work on the copy, not on the original object. Exercise: ------------ How do you change the selectivity of the gear used by métier métier for population POP? Ans:: métier.getGear().getPopulationSelectivity(POP).getEquation() .setContent(«return 1 ; ») How to change the proportion of effort spent by strategy str on métier met in september to 0.1? Ans:: str.getStrategyMonthInfo(Month.SEPTEMBER).setProportionMetier(met,0.1); .. _Modele ISIS-Fish: ../isisFishModel.html