protected boolean beginExecution(final IScope scope) throws GamaRuntimeException {
   final IAgent agent = scope.getAgentScope();
   if (scope.interrupted()) {
     return false;
   }
   final Boolean enter = (Boolean) agent.getAttribute(ENTER);
   Map<String, Object> memory = (Map) agent.getAttribute(STATE_MEMORY);
   if (enter || memory == null) {
     memory = new THashMap();
     agent.setAttribute(STATE_MEMORY, memory);
   } else {
     for (final Map.Entry<String, Object> entry : memory.entrySet()) {
       scope.addVarWithValue(entry.getKey(), entry.getValue());
     }
   }
   if (enter) {
     if (enterActions != null) {
       enterActions.executeOn(scope);
     }
     if (agent.dead()) {
       return false;
     }
     agent.setAttribute(ENTER, false);
   }
   return true;
 }
 @Override
 public IList<ISpecies> getMicroSpecies() {
   final IList<ISpecies> retVal = GamaListFactory.create(Types.SPECIES);
   retVal.addAll(microSpecies.values());
   final ISpecies parentSpecies = this.getParentSpecies();
   if (parentSpecies != null) {
     retVal.addAll(parentSpecies.getMicroSpecies());
   }
   return retVal;
 }
 /**
  * Returns a micro-species with the specified name or null otherwise.
  *
  * @param microSpeciesName
  * @return a species or null
  */
 @Override
 public ISpecies getMicroSpecies(final String microSpeciesName) {
   final ISpecies retVal = microSpecies.get(microSpeciesName);
   if (retVal != null) {
     return retVal;
   }
   final ISpecies parentSpecies = this.getParentSpecies();
   if (parentSpecies != null) {
     return parentSpecies.getMicroSpecies(microSpeciesName);
   }
   return null;
 }
 @Override
 public void setChildren(final List<? extends ISymbol> children) {
   // First we verify the control architecture
   final IArchitecture control = getArchitecture();
   if (control == null) {
     throw GamaRuntimeException.error(
         "The control of species " + description.getName() + " cannot be computed");
   }
   // Then we classify the children in their categories
   for (final ISymbol s : children) {
     if (s instanceof ISpecies) {
       final ISpecies oneMicroSpecies = (ISpecies) s;
       oneMicroSpecies.setMacroSpecies(this);
       microSpecies.put(oneMicroSpecies.getName(), oneMicroSpecies);
     } else if (s instanceof IVariable) {
       variables.put(s.getName(), (IVariable) s);
     } else if (s instanceof AspectStatement) {
       aspects.put(s.getName(), (AspectStatement) s);
     } else if (s instanceof ActionStatement) {
       if (!s.getDescription().isBuiltIn()) {
         String name = s.getName();
         if (name.equals(initActionName)) {
           isInitOverriden = true;
         } else if (name.equals(stepActionName)) {
           isStepOverriden = true;
         }
       }
       actions.put(s.getName(), (ActionStatement) s);
     } else if (s instanceof UserCommandStatement) {
       userCommands.put(s.getName(), (UserCommandStatement) s);
     } else if (s instanceof IStatement) {
       behaviors.add((IStatement) s); // reflexes, states or tasks
     }
   }
   control.setChildren(behaviors);
   control.verifyBehaviors(this);
 }
 @Override
 public void dispose() {
   super.dispose();
   for (final IVariable v : variables.values()) {
     v.dispose();
   }
   variables.clear();
   for (final AspectStatement ac : aspects.values()) {
     ac.dispose();
   }
   aspects.clear();
   for (final ActionStatement ac : actions.values()) {
     ac.dispose();
   }
   actions.clear();
   for (final IStatement c : behaviors) {
     c.dispose();
   }
   behaviors.clear();
   macroSpecies = null;
   parentSpecies = null;
   // TODO dispose micro_species first???
   microSpecies.clear();
 }
 @Override
 public Collection<String> getMicroSpeciesNames() {
   return microSpecies.keySet();
 }
 @Override
 public Collection<UserCommandStatement> getUserCommands() {
   return userCommands.values();
 }
 @Override
 public Collection<? extends IExecutable> getAspects() {
   return aspects.values();
 }
 @Override
 public List<String> getAspectNames() {
   return new ArrayList<String>(aspects.keySet());
 }
Example #10
0
 @Override
 public boolean hasAspect(final String n) {
   return aspects.containsKey(n);
 }
Example #11
0
 @Override
 public IExecutable getAspect(final String n) {
   return aspects.get(n);
 }
Example #12
0
 @Override
 public WithArgs getAction(final String name) {
   return actions.get(name);
 }
Example #13
0
 @Override
 public Collection<ActionStatement> getActions() {
   return actions.values();
 }
Example #14
0
 @Override
 public boolean containMicroSpecies(final ISpecies species) {
   final ISpecies parentSpecies = this.getParentSpecies();
   return microSpecies.values().contains(species)
       || (parentSpecies != null ? parentSpecies.containMicroSpecies(species) : false);
 }
Example #15
0
 @Override
 public Collection<IVariable> getVars() {
   return variables.values();
 }
Example #16
0
 @Override
 public boolean hasVar(final String name) {
   return variables.containsKey(name);
 }
Example #17
0
 @Override
 public IVariable getVar(final String n) {
   return variables.get(n);
 }
Example #18
0
 @Override
 public boolean hasMicroSpecies() {
   final ISpecies parentSpecies = this.getParentSpecies();
   return !microSpecies.isEmpty()
       || (parentSpecies != null ? parentSpecies.hasMicroSpecies() : false);
 }