cz.cuni.amis.pogamut.sposh.elements
Class Sense

Package class diagram package Sense
java.lang.Object
  extended by cz.cuni.amis.pogamut.sposh.elements.PoshElement<THIS,PARENT>
      extended by cz.cuni.amis.pogamut.sposh.elements.PoshDummyElement<THIS,PARENT>
          extended by cz.cuni.amis.pogamut.sposh.elements.NamedLapElement
              extended by cz.cuni.amis.pogamut.sposh.elements.Sense
All Implemented Interfaces:
Comparable<Sense>

public class Sense
extends NamedLapElement
implements Comparable<Sense>

Sense is basically a function in Python or Java. It is called and it returns some result. This class is representation of sense, but it can also take an argument and compare it with predicate. During execution POSH engine calls the sense and compares return value with argument by predicate. If no argument was passed, use true, if no predicate was passed, use ==.

Author:
Honza

Nested Class Summary
static class Sense.Predicate
          Various predicates used in Sense
 
Field Summary
static DataFlavor dataFlavor
           
static String psArgs
           
static String psPredicateIndex
           
static String psSenseName
           
static String psType
           
static String psValue
           
 
Fields inherited from class cz.cuni.amis.pogamut.sposh.elements.PoshDummyElement
IDENT_PATTERN
 
Constructor Summary
Sense(PrimitiveCall senseCall)
          Create sense that will evaluate based on result of called primitive some parameters
Sense(PrimitiveCall senseCall, Object operand, Sense.Predicate predicate)
           
Sense(String senseName)
          Create sense that will evaluate true based on result of called primitive.
 
Method Summary
 int compareTo(Sense o)
           
 Arguments getArguments()
           
 DataFlavor getDataFlavor()
          Get data flavour of posh plan element,used during DnD from palette to PoshScene.
 List<PoshElement> getChildDataNodes()
          Get list of children of this node.
 String getName()
          Get name of the element.
 Object getOperand()
          Get operand that should be used for evaluating this sense.
 Sense.Predicate getPredicate()
           
 Integer getPredicateIndex()
           
 String getRepresentation()
          Get human readable representation of this sense.
 String getRepresentation(String name)
          Get string representation of the sense, i.e. sensecall predicate value, but instead of sense name, use the passed name.
 PrimitiveCall getSenseCall()
          Get param
 String getSenseName()
           
 Trigger<?> getTrigger()
          Get Trigger this sense is part of.
 LapType getType()
          Get type of the element.
 String getValueString()
          Used in Node.Properties XXX: Do more properly with custom editor
 void changeTo(Sense other)
          Take other sense and change all attributes in the sense to be same as in other sense.
 boolean moveChild(int newIndex, PoshElement child)
          Move child to the @newIndex.
 void parseSense(String input)
          TODO: Correctly document, changed in hurry.
 void removeFromParent()
          This is a common method for removing the sense from its parent.
 void setArguments(Arguments newArguments)
           
 void setOperand(Object newValue)
          Set value of argument (as class, e.g.
 void setPredicate(Sense.Predicate newPredicate)
          Set the predicate in the sense.
 void setPredicateIndex(Integer newPredicateIndex)
          Set predicate, use index to array Predicate.values()[index]
 void setSenseName(String newSenseName)
          Set new sense name if new name matches IDENT_PATTERN, name will be trimmed.
 String toString()
          Return text representation in posh friendly manner.
 
Methods inherited from class cz.cuni.amis.pogamut.sposh.elements.PoshDummyElement
getUnusedName, isUsedName, moveChildInList
 
Methods inherited from class cz.cuni.amis.pogamut.sposh.elements.PoshElement
addElementListener, emitChildDeleted, emitChildMove, emitChildNode, firePropertyChange, getElementListeners, getNumberOfChildInstances, getParent, getRootNode, isChildOfParent, removeElementListener, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

psSenseName

public static final String psSenseName
See Also:
Constant Field Values

psArgs

public static final String psArgs
See Also:
Constant Field Values

psPredicateIndex

public static final String psPredicateIndex
See Also:
Constant Field Values

psValue

public static final String psValue
See Also:
Constant Field Values

psType

public static final String psType
See Also:
Constant Field Values

dataFlavor

public static final DataFlavor dataFlavor
Constructor Detail

Sense

public Sense(String senseName)
Create sense that will evaluate true based on result of called primitive. The primitive has no parameters.

Parameters:
senseName - name of primitive

Sense

public Sense(PrimitiveCall senseCall)
Create sense that will evaluate based on result of called primitive some parameters

Parameters:
senseCall - details of call primitive

Sense

public Sense(PrimitiveCall senseCall,
             Object operand,
             Sense.Predicate predicate)
Parameters:
senseCall -
operand - operand that will be parsed and changed into proper object
predicate -
Method Detail

getSenseName

public String getSenseName()

getSenseCall

public PrimitiveCall getSenseCall()
Get param


setSenseName

public void setSenseName(String newSenseName)
                  throws InvalidNameException
Set new sense name if new name matches IDENT_PATTERN, name will be trimmed.

Parameters:
newSenseName -
Throws:
InvalidNameException

getValueString

public String getValueString()
Used in Node.Properties XXX: Do more properly with custom editor

Returns:

getOperand

public Object getOperand()
Get operand that should be used for evaluating this sense. Default value of operand is true.

Returns:
Object representing operand, true, false, string, int, double, even null is valid operand.

setOperand

public void setOperand(Object newValue)
Set value of argument (as class, e.g. Boolean, String, Integer...).

Parameters:
newValue - number, string or nil

getPredicateIndex

public Integer getPredicateIndex()

getPredicate

public Sense.Predicate getPredicate()

setPredicate

public void setPredicate(Sense.Predicate newPredicate)
Set the predicate in the sense. If set to DEFAULT predicate, it won't be shown.

Parameters:
newPredicate - non null

setPredicateIndex

public void setPredicateIndex(Integer newPredicateIndex)
Set predicate, use index to array Predicate.values()[index]

Parameters:
newPredicateIndex - index to new predicate

getArguments

public Arguments getArguments()

setArguments

public void setArguments(Arguments newArguments)

parseSense

public void parseSense(String input)
                throws ParseException
TODO: Correctly document, changed in hurry. This is not correct,. we just call PoshParser Take the input that represents the sense in one way or another and set this sense to the values found in the input. Possible inputs: senseName (e.g. 'cz.cuni.Health') | senseName value (e.g. 'cz.cuni.BadlyHurt True') | senseName predicate value (e.g. 'cz.cuni.Health < 90'). In the second case, the default predicate is equality. Value can be bool, number or string in double quotes(it will be properly unescaped).

Parameters:
input -
Throws:
InvalidNameException - When name of the sense is not valid.
InvalidFormatException - When wrong number of tokens in the input.
ParseException

changeTo

public void changeTo(Sense other)
              throws InvalidNameException
Take other sense and change all attributes in the sense to be same as in other sense.

Parameters:
other -
Throws:
InvalidNameException

toString

public String toString()
Return text representation in posh friendly manner. Examples: (senseName) (senseName 2 !=) (senseName "Ahoj")

Overrides:
toString in class Object
Returns:

getName

public String getName()
Description copied from class: NamedLapElement
Get name of the element. The actual name, not display name (e.g. action can have FQN of class, but display name would be derived fromk annotations of the class) or representation (e.g. sense name "health" is different from actual condition of sense "health > 90").

Specified by:
getName in class NamedLapElement
Returns:
Name of the element

getChildDataNodes

public List<PoshElement> getChildDataNodes()
Description copied from class: PoshElement
Get list of children of this node. Most likely auto generated every time this method is called.

Specified by:
getChildDataNodes in class PoshElement
Returns:
List of all children of this node.

moveChild

public boolean moveChild(int newIndex,
                         PoshElement child)
Description copied from class: PoshElement
Move child to the @newIndex. After child was moved (if it was moved), notify listeners.

Specified by:
moveChild in class PoshElement
Returns:
if node succesfully moved

getDataFlavor

public DataFlavor getDataFlavor()
Description copied from class: PoshElement
Get data flavour of posh plan element,used during DnD from palette to PoshScene.

Specified by:
getDataFlavor in class PoshElement
Returns:
dataFlavour of posh plan element, never null.

getType

public LapType getType()
Description copied from class: PoshElement
Get type of the element.

Specified by:
getType in class PoshElement
Returns:
Type of element.

getRepresentation

public String getRepresentation()
Get human readable representation of this sense. Examples: 'working', 'cz.Health > 10', 'cz.Distance("ArmyBot", $cutoff=12) < 10'

Returns:
Human readable representation of the sense.

getRepresentation

public String getRepresentation(String name)
Get string representation of the sense, i.e. sensecall predicate value, but instead of sense name, use the passed name. Examples: 'working', 'cz.Health > 10', 'cz.Distance("ArmyBot", $cutoff=12) < 10'

Parameters:
name - Name that is used instead of name in the PrimitiveCall
Returns:
Human readable representation of the sense.

compareTo

public int compareTo(Sense o)
Specified by:
compareTo in interface Comparable<Sense>

getTrigger

public Trigger<?> getTrigger()
Get Trigger this sense is part of. Trigger by itself is not a PoshElement, but it is part of some other element (e.g. DriveCollection or CompetenceElement)

Returns:
The trigger this sense belongs
Throws:
IllegalArgumentException - If parent is null or I forgot some possible parent.

removeFromParent

public void removeFromParent()
This is a common method for removing the sense from its parent. There are multiple possible parents (DC, CE, DE or no parent) and this method will handle them all. Once the method is finished, this sense is no longer child of its original parent and its parent is null. When calling this method, parent must not be null.



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