jason.asSemantics.QueryCacheSimple Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jason Show documentation
Show all versions of jason Show documentation
Jason is a fully-fledged interpreter for an extended version of AgentSpeak, a BDI agent-oriented logic programming language.
package jason.asSemantics;
import jason.asSyntax.Literal;
import jason.profiling.QueryProfiling;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
public class QueryCacheSimple {
private QueryProfiling prof;
private Map> cache = null;
protected Logger logger = null;
public QueryCacheSimple(Agent ag, QueryProfiling p) {
this.prof = p;
logger = Logger.getLogger(QueryCacheSimple.class.getName()+"-"+ag.getTS().getUserAgArch().getAgName());
cache = new HashMap>();
}
public void reset() {
cache.clear();
}
public Iterator getCache(final Literal f) {
List l = cache.get(f);
if (l == null)
return null;
if (prof != null)
prof.incHits();
return l.iterator();
}
public void queryFinished(Literal f, List r) {
//System.out.println("finished "+f+" with "+r);
cache.put(f, r);
}
}