jill/src/main/java/io/github/agentsoz/jill/core/beliefbase/abs/ABeliefStore.java
@Override
  public Set<Belief> query(int agentid, String key) throws BeliefBaseException {
    // Get the cached query if we have seen it before, else parse it
    AQuery query = null;
    if (queries.containsKey(key)) {
      query = queries.get(key);
    } else {
      // Valid queries have the following syntax
      // beliefset.field OP value
      // where OP is one of =, !=, <, or >
      if (key == null) {
        throw new BeliefBaseException(logsuffix(agentid) + "'null' query");
      }
      Pattern pattern = Pattern.compile("(\\w+)\\.(\\w+)\\s*([=<>(!=)])\\s*(.+)");
      Matcher matcher = pattern.matcher(key);
      if (!matcher.matches()) {
        throw new BeliefBaseException(logsuffix(agentid) + "invalid query '" + key
            + "' : syntax not of the form beliefset.field <op> value");
      }
      String strBeliefset = matcher.group(1);
      String strField = matcher.group(2);
      String strOp = matcher.group(3);
      String strVal = matcher.group(4);
      try {
        query = parseQuery(agentid, strBeliefset, strField, strOp, strVal);
        queries.put(key, query);
      } catch (BeliefBaseException e) {
        throw new BeliefBaseException(logsuffix(agentid) + "could not parse query: " + key, e);
      }
    }
    // Get the cached results if they exist,
    // else perform the query and cache the results
    Set<Belief> results = null;
    if (cachedresults.containsKey(key)) {
      results = cachedresults.get(key);
    } else {
      results = performQuery(query, beliefs);
      cachedresults.put(key, results);
    }

    // Finally, filter the results for this agent
    Set<Belief> matches = filterResultsForAgent(agentid, results);
    Log.debug("Agent " + agentid + " found " + matches.size() + " matches for the query");

    return matches;
  }
@Override
  public Set<Belief> query(int agentid, String key) throws BeliefBaseException {
    // Get the cached query if we have seen it before, else parse it
    AQuery query = null;
    if (queries.containsKey(key)) {
      query = queries.get(key);
    } else {
      // Valid queries have the following syntax
      // beliefset.field OP value
      // where OP is one of =, !=, <, or >
      if (key == null) {
        throw new BeliefBaseException(logsuffix(agentid) + "'null' query");
      }
      Pattern pattern = Pattern.compile("(\\w+)\\.(\\w+)\\s*([=<>(!=)])\\s*(.+)");
      Matcher matcher = pattern.matcher(key);
      if (!matcher.matches()) {
        throw new BeliefBaseException(logsuffix(agentid) + "invalid query '" + key
            + "' : syntax not of the form beliefset.field <op> value");
      }
      String strBeliefset = matcher.group(1);
      String strField = matcher.group(2);
      String strOp = matcher.group(3);
      String strVal = matcher.group(4);
      try {
        query = parseQuery(agentid, strBeliefset, strField, strOp, strVal);
        queries.put(key, query);
      } catch (BeliefBaseException e) {
        throw new BeliefBaseException(logsuffix(agentid) + "could not parse query: " + key, e);
      }
    }
    // Get the cached results if they exist,
    // else perform the query and cache the results
    Set<Belief> results = null;
    if (cachedresults.containsKey(key)) {
      results = cachedresults.get(key);
    } else {
      results = performQuery(query, beliefs);
      cachedresults.put(key, results);
    }

    // Finally, filter the results for this agent
    Set<Belief> matches = filterResultsForAgent(agentid, results);
    Log.debug("Agent " + agentid + " found " + matches.size() + " matches for the query");

    return matches;
  }
@ Override public Set < Belief > query ( int agentid , String key ) throws BeliefBaseException { // Get the cached query if we have seen it before, else parse it AQuery query = null ; if ( queries . containsKey ( key ) ) { query = queries . get ( key ) ; } else { // Valid queries have the following syntax // beliefset.field OP value // where OP is one of =, !=, <, or > if ( key == null ) { throw new BeliefBaseException ( logsuffix ( agentid ) + "'null' query" ) ; } Pattern pattern = Pattern . compile ( "(\\w+)\\.(\\w+)\\s*([=<>(!=)])\\s*(.+)" ) ; Matcher matcher = pattern . matcher ( key ) ; if ( ! matcher . matches ( ) ) { throw new BeliefBaseException ( logsuffix ( agentid ) + "invalid query '" + key + "' : syntax not of the form beliefset.field <op> value" ) ; } String strBeliefset = matcher . group ( 1 ) ; String strField = matcher . group ( 2 ) ; String strOp = matcher . group ( 3 ) ; String strVal = matcher . group ( 4 ) ; try { query = parseQuery ( agentid , strBeliefset , strField , strOp , strVal ) ; queries . put ( key , query ) ; } catch ( BeliefBaseException e ) { throw new BeliefBaseException ( logsuffix ( agentid ) + "could not parse query: " + key , e ) ; } } // Get the cached results if they exist, // else perform the query and cache the results Set < Belief > results = null ; if ( cachedresults . containsKey ( key ) ) { results = cachedresults . get ( key ) ; } else { results = performQuery ( query , beliefs ) ; cachedresults . put ( key , results ) ; } // Finally, filter the results for this agent Set < Belief > matches = filterResultsForAgent ( agentid , results ) ; Log . debug ( "Agent " + agentid + " found " + matches . size ( ) + " matches for the query" ) ; return matches ; }
{@inheritDoc}.
{