All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jason.asSemantics.QueryCacheSimple Maven / Gradle / Ivy

Go to download

Jason is a fully-fledged interpreter for an extended version of AgentSpeak, a BDI agent-oriented logic programming language.

There is a newer version: 2.3
Show newest version
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);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy