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

com.massisframework.massis.ai.sposh.senses.MessageReceived Maven / Gradle / Ivy

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.massisframework.massis.ai.sposh.senses;

import java.util.Map;

import com.massisframework.massis.ai.sposh.SimulationContext;
import cz.cuni.amis.pogamut.sposh.executor.Param;
import cz.cuni.amis.pogamut.sposh.executor.PrimitiveInfo;
import java.util.HashMap;
import com.massisframework.massis.ai.sposh.SPOSHLogicProperty;

/**
 * Returns if a specific message was received
 *
 * @author rpax
 */
@PrimitiveInfo(name = "Message Received", description = "Returns if a specific message was received")
public class MessageReceived extends SimulationSense {

    public MessageReceived(SimulationContext ctx)
    {
        super(ctx);
    }

    public Boolean query(
            @Param("$message") String message,
            @Param("$from") String from)
    {

        final HashMap mentalState = this.ctx.getMentalState();
        if (mentalState.containsKey(SPOSHLogicProperty.MESSAGES.toString()))
        {
            Map messages = (Map) mentalState.get(
                    SPOSHLogicProperty.MESSAGES.toString());

            SimulationContext senderCtx = messages.remove(message);
            if (senderCtx == null)
            {
                return false;
            } else
            {
                HashMap senderMS = senderCtx.getMentalState();
                String type = (String)
                        senderMS.get(SPOSHLogicProperty.TYPE.toString());
                if (SPOSHLogicProperty.ANY.toString().equals(type)
                        || from.equals(type))
                {
                    return true;
                }

            }
        }
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy