Package jade.util.leap

Examples of jade.util.leap.Iterator


  reply.setInReplyTo(request.getReplyWith());
  //set the protocol
  reply.setProtocol(request.getProtocol());
  //set the receivers
  if (!reply.getAllReceiver().hasNext()) {
      Iterator it = request.getAllReplyTo();
      int r = 0;
      while (it.hasNext()) {
    reply.addReceiver((AID)it.next());
    r++;
      }
      if (r == 0) {
    reply.addReceiver(request.getSender());
      }
View Full Code Here


  protected abstract void clean();

  public List search(Object template, int maxResults) {
    List result = new ArrayList();
      Iterator it = facts.values().iterator();
    int found = 0;
      while(it.hasNext() && ((maxResults < 0) || (found < maxResults)) ) {
          Object fact = it.next();
        if(match(template, fact)){
        result.add(fact);
        found ++;
        }
        }
View Full Code Here

          if((factName == null) || (!templateName.equalsIgnoreCase(factName)))
          return false;
      }

      // Match the address sequence. See 'FIPA Agent Management Specification, Sect. 6.4.2.1'
      Iterator itTemplate = template.getAllAddresses();
      Iterator itFact = fact.getAllAddresses();

      // All the elements in the template sequence must appear in the
      // fact sequence, in the same order
      while(itTemplate.hasNext()) {
          String templateAddr = (String)itTemplate.next();

          // Search 'templateAddr' into the remaining part of the fact sequence
          boolean found = false;
          while(!found && itFact.hasNext()) {
              String factAddr = (String)itFact.next();
            found = templateAddr.equalsIgnoreCase(factAddr);
          }
          if(!found) // An element of the template does not appear in the fact sequence
        return false;
       }

      // Match the resolvers sequence. See 'FIPA Agent Management Specification, Sect. 6.4.2.1'
      itTemplate = template.getAllResolvers();
      itFact = fact.getAllResolvers();

      while(itTemplate.hasNext()) {
        AID templateRes = (AID)itTemplate.next();

        // Search 'templateRes' into the remaining part of the fact sequence
        boolean found = false;
        while(!found && itFact.hasNext()) {
      AID factRes = (AID)itFact.next();
      found = matchAID(templateRes, factRes); // Recursive call
        }
        if(!found) // An element of the template does not appear in the fact sequence
        return false;
      }
View Full Code Here

   */
  protected void clean(){

    if (entriesToDelete) {
      ArrayList toBeRemoved = new ArrayList();
      Iterator iter = facts.values().iterator();   
      while(iter.hasNext()){
        DFAgentDescription dfd = (DFAgentDescription) iter.next();
        if(dfd.checkLeaseTimeExpired()) {
          toBeRemoved.add(dfd.getName());
        }
      }
      iter = toBeRemoved.iterator();
      while (iter.hasNext()) {
        facts.remove((AID) iter.next());
      }
    }
  }
View Full Code Here

        if((id2 == null) || (!matchAID(id1, id2)))
          return false;
      }

      // Match protocol set
      Iterator itTemplate = templateDesc.getAllProtocols();
      while(itTemplate.hasNext()) {
        String templateProto = (String)itTemplate.next();
        boolean found = false;
        Iterator itFact = factDesc.getAllProtocols();
        while(!found && itFact.hasNext()) {
          String factProto = (String)itFact.next();
          found = templateProto.equalsIgnoreCase(factProto);
        }
        if(!found)
          return false;
      }

      // Match ontologies set
      itTemplate = templateDesc.getAllOntologies();
      while(itTemplate.hasNext()) {
        String templateOnto = (String)itTemplate.next();
        boolean found = false;
        Iterator itFact = factDesc.getAllOntologies();
        while(!found && itFact.hasNext()) {
          String factOnto = (String)itFact.next();
          found = templateOnto.equalsIgnoreCase(factOnto);
        }
        if(!found)
          return false;
      }

      // Match languages set
      itTemplate = templateDesc.getAllLanguages();
      while(itTemplate.hasNext()) {
        String templateLang = (String)itTemplate.next();
        boolean found = false;
        Iterator itFact = factDesc.getAllLanguages();
        while(!found && itFact.hasNext()) {
          String factLang = (String)itFact.next();
          found = templateLang.equalsIgnoreCase(factLang);
        }
        if(!found)
          return false;
      }

      // Match services set
      itTemplate = templateDesc.getAllServices();
      while(itTemplate.hasNext()) {
        ServiceDescription templateSvc = (ServiceDescription)itTemplate.next();
        boolean found = false;
        Iterator itFact = factDesc.getAllServices();
        while(!found && itFact.hasNext()) {
          ServiceDescription factSvc = (ServiceDescription)itFact.next();
          found = compareServiceDesc(templateSvc, factSvc);
        }
        if(!found)
          return false;
      }
View Full Code Here

 
  // Helper method for persistence service
  public synchronized Behaviour[] getBehaviours() {
   
    Behaviour[] result = new Behaviour[blockedBehaviours.size() + readyBehaviours.size()];
    Iterator itReady = readyBehaviours.iterator();
    Iterator itBlocked = blockedBehaviours.iterator();
    for(int i = 0; i < result.length; i++) {
      Behaviour b = null;
      if(itReady.hasNext()) {
        b = (Behaviour)itReady.next();
      }
      else {
        b = (Behaviour)itBlocked.next();
      }
     
      result[i] = b;
     
    }
View Full Code Here

      if((o2 == null) || (!o1.equalsIgnoreCase(o2)))
        return false;
    }

    // Match ontologies set
    Iterator itTemplate = template.getAllOntologies();
    while(itTemplate.hasNext()) {
      String templateOnto = (String)itTemplate.next();
      boolean found = false;
      Iterator itFact = fact.getAllOntologies();
      while(!found && itFact.hasNext()) {
        String factOnto = (String)itFact.next();
        found = templateOnto.equalsIgnoreCase(factOnto);
      }
      if(!found)
        return false;
    }

    // Match languages set
    itTemplate = template.getAllLanguages();
    while(itTemplate.hasNext()) {
      String templateLang = (String)itTemplate.next();
      boolean found = false;
      Iterator itFact = fact.getAllLanguages();
      while(!found && itFact.hasNext()) {
        String factLang = (String)itFact.next();
        found = templateLang.equalsIgnoreCase(factLang);
      }
      if(!found)
        return false;
    }

    // Match protocols set
    itTemplate = template.getAllProtocols();
    while(itTemplate.hasNext()) {
      String templateProto = (String)itTemplate.next();
      boolean found = false;
      Iterator itFact = fact.getAllProtocols();
      while(!found && itFact.hasNext()) {
        String factProto = (String)itFact.next();
        found = templateProto.equalsIgnoreCase(factProto);
      }
      if(!found)
        return false;
    }

    // Match properties set
    itTemplate = template.getAllProperties();
    while(itTemplate.hasNext()) {
      Property templateProp = (Property)itTemplate.next();
      boolean found = false;
      Iterator itFact = fact.getAllProperties();
      while(!found && itFact.hasNext()) {
        Property factProp = (Property)itFact.next();
        found = templateProp.match(factProp);
        /*if (templateProp.getName().equals(factProp.getName())) {
          // The property name matches. Check the value
          Object templateValue = templateProp.getValue();
          if (templateValue == null) {
View Full Code Here

    return entries.size();
  }

  public synchronized ContainerID[] names() {
    ContainerID[] result = new ContainerID[entries.size()];
    Iterator it = entries.keySet().iterator();
    int i = 0;
    while(it.hasNext()) {
      result[i++] = (ContainerID) it.next();
    }
    return result;
  }
View Full Code Here

  private void saveAID(AID aid) throws SQLException {
    String name = aid.getName();
    PreparedStatements pss = getPreparedStatements();

    // Addresses
    Iterator iter = aid.getAllAddresses();
    if (iter.hasNext()) {
      pss.stm_insAgentAddress.clearBatch();
      while( iter.hasNext()){
        pss.stm_insAgentAddress.setString(1, getGUID());
        pss.stm_insAgentAddress.setString(2, name);
        pss.stm_insAgentAddress.setString(3, (String)iter.next());
        pss.stm_insAgentAddress.addBatch();
      }
      pss.stm_insAgentAddress.executeBatch();
    }
   
   
    // User defined slots
    Properties props = aid.getAllUserDefinedSlot();
    if (props.size() > 0) {
      pss.stm_insAgentUserDefSlot.clearBatch();
      java.util.Iterator pIter = props.entrySet().iterator();
      while (pIter.hasNext()) {
        Map.Entry entry = (Map.Entry)pIter.next();
        pss.stm_insAgentUserDefSlot.setString(1, getGUID());
        pss.stm_insAgentUserDefSlot.setString(2, name);
        pss.stm_insAgentUserDefSlot.setString(3, (String)entry.getKey());
        pss.stm_insAgentUserDefSlot.setString(4, (String)entry.getValue());
        pss.stm_insAgentUserDefSlot.addBatch();
      }
      pss.stm_insAgentUserDefSlot.executeBatch();
    }
   
    // Resolvers
    iter = aid.getAllResolvers();
    if (iter.hasNext()) {
      pss.stm_insAgentResolverAID.clearBatch();
      while(iter.hasNext()){
        AID resolverAID = (AID)iter.next();
        saveResolverAID(aid, resolverAID);
     
      pss.stm_insAgentResolverAID.executeBatch();
    }
  }
View Full Code Here

        pss.stm_insService.setString(4, service.getType());
        pss.stm_insService.setString(5, service.getOwnership());
        pss.stm_insService.addBatch();
       
        // Service - Protocols
        Iterator iterS = service.getAllProtocols();
        while(iterS.hasNext()){
          pss.stm_insServiceProtocol.setString(1, serviceId);
          pss.stm_insServiceProtocol.setString(2, (String)iterS.next());
          pss.stm_insServiceProtocol.addBatch();
          executeProtocolsBatch = true;
        }
       
        // Service - Ontologies
        iterS = service.getAllOntologies();
        while(iterS.hasNext()){
          pss.stm_insServiceOntology.setString(1, serviceId);
          pss.stm_insServiceOntology.setString(2, (String)iterS.next());
          pss.stm_insServiceOntology.addBatch();
          executeOntologiesBatch = true;
        }
       
        // Service - Languages
        iterS = service.getAllLanguages();
        while(iterS.hasNext()){
          pss.stm_insServiceLanguage.setString(1, serviceId);
          pss.stm_insServiceLanguage.setString(2, (String)iterS.next());
          pss.stm_insServiceLanguage.addBatch();
          executeLanguagesBatch = true;
        }
       
        // Service - Properties
        iterS = service.getAllProperties();
        while(iterS.hasNext()){
         
          Property prop = (Property)iterS.next();
          try {
            pss.stm_insServiceProperty.setString(1, serviceId);
            pss.stm_insServiceProperty.setString(2, prop.getName());
           
            // serialize value to a string and calcualte
View Full Code Here

TOP

Related Classes of jade.util.leap.Iterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.