cz.cuni.amis.pogamut.sposh.executor
Class ParamsSense<CONTEXT extends Context,RETURN>

Package class diagram package ParamsSense
java.lang.Object
  extended by cz.cuni.amis.pogamut.sposh.executor.StateSense<CONTEXT,RETURN>
      extended by cz.cuni.amis.pogamut.sposh.executor.ParamsSense<CONTEXT,RETURN>
Type Parameters:
RETURN - Return type of query.
All Implemented Interfaces:
ISense<RETURN>

public abstract class ParamsSense<CONTEXT extends Context,RETURN>
extends StateSense<CONTEXT,RETURN>

Create new parametrized sense using reflection. The senses created by subclassing this class will have access to the desired parameters directly from method parameters. In order to create new parametrized sense, subclass this class and create method public RETURN query. RETURN is same type as passed to the generics. All parameters of the query method must be annotated by the Param and must be one types supported by POSH (currently String, Double, Boolean and Integer). If you so desire, no parameters are necessary, thus to create parameterless sense simply use public RETURN query() {...} method, but it is not very useful, it is better to directly subclass StateSense that forces you to implement ISense.query(cz.cuni.amis.pogamut.sposh.engine.VariableContext) method. NOTE: interfaces and other mechanisms of Java are not capable to ensure the presence of parametrized query method at compile time. The presence of method will be checked at the moment of instantiation. Example:

 public class FlagIsOnGround extends FlagSense<AttackbotContext, Boolean> {

    public FlagIsOnGround(AttackbotContext ctx) {
        super(ctx, Boolean.class);
    }

    public Boolean query(&064;Param("$teamname") String teamName) {

 

Author:
Honza Havlicek
See Also:
ParamsAction

Field Summary
 
Fields inherited from class cz.cuni.amis.pogamut.sposh.executor.StateSense
ctx
 
Constructor Summary
protected ParamsSense(CONTEXT ctx)
           
protected ParamsSense(CONTEXT ctx, Class<RETURN> returnCls)
          Create new parametrized sense.
 
Method Summary
 RETURN query(VariableContext params)
          Query current value of sense.
 
Methods inherited from class cz.cuni.amis.pogamut.sposh.executor.StateSense
getCtx, getName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParamsSense

protected ParamsSense(CONTEXT ctx,
                      Class<RETURN> returnCls)
Create new parametrized sense.

Parameters:
ctx - Shared info of bot + tools for manipulating the world.
returnCls - Class of RETURN type. Required by reflection for finding the correct query method (generic types are erased during compile time). Currently only String.class, Double.TYPE and Integer.TYPE return values are supported.

ParamsSense

protected ParamsSense(CONTEXT ctx)
Method Detail

query

public final RETURN query(VariableContext params)
Description copied from interface: ISense
Query current value of sense.

Parameters:
params - Variable context passed from posh plan to sense. Could be used for things like threshold and so on.
Returns:
what is sense currently sensing, e.g. number of friends in FOV


Copyright © 2014 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.