com.massisframework.massis.ai.sposh.senses.MessageReceived Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of massis-ai-sposh Show documentation
Show all versions of massis-ai-sposh Show documentation
SPOSH High Level Controller
/*
* 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;
}
}