Package ptolemy.domains.modal.kernel
Class RelationList
 java.lang.Object

 ptolemy.domains.modal.kernel.RelationList

public class RelationList extends java.lang.Object
A RelationList object contains a list of relations of a guard expression. Relations are comparison operations, for example "x ≥ 10", where x is a variable. This class provides facilities for measuring how far the expression is from the threshold; for example, if x = 7, then the distance to the threshold is 3. Moreover, it provides a mechanism for recording the current distance (via a "commit") and then later accessing that distance and comparing it against the current distance. The information includes relation type and the difference information. (SeeParseTreeEvaluatorForGuardExpression
for the detailed explanation of relation type and difference.) This attribute is nonpersistent and will not be exported into MoML.This class is designed to be used with ParseTreeEvaluatorForGuardExpression. The common usage would be like:
Construct a relation list for a transition with the first argument of the constructor as that transition.
_relationList = new RelationList();
Associate the relation list with the an object of ParseTreeEvaluatorForGuardExpression
_parseTreeEvaluator = new ParseTreeEvaluatorForGuardExpression(_relationList, getErrorTolerance());
See
Transition
for the detailed usage. Since:
 Ptolemy II 8.0
 Version:
 $Id$
 Author:
 Haiyang Zheng
 Pt.AcceptedRating:
 Red (hyzheng)
 Pt.ProposedRating:
 Yellow (hyzheng)


Constructor Summary
Constructors Constructor Description RelationList()
Construct a relation list.

Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRelation(int type, double difference)
Construct a relation node with the given type and difference information of a relation, and add it to the end of the relation list.void
commitRelationValues()
Record the current relation values so that when getPreviousMaximumDistance() is called, these recorded values are used.void
destroy()
Destroy the relation list by deleting all the contained elements.double
getMaximumDifference()
Return the maximum current difference of all the relations by iterating the relation list.double
getPreviousMaximumDistance()
Return the previous difference of the relation that has the maximum current difference.boolean
hasEvent()
Return true if there exists an event caused by the type change of any relation.boolean
isEmpty()
Return true if the relation list is empty.int
length()
Return the number of relations in the relation list.void
resetRelationList()
Reset the relation list by resetting each relation node.void
setRelation(int relationIndex, int type, double difference)
Update the relation in the relation list referred by the relation index argument with the given type and difference information.



Method Detail

addRelation
public void addRelation(int type, double difference)
Construct a relation node with the given type and difference information of a relation, and add it to the end of the relation list. Parameters:
type
 The relation type of the relation.difference
 The difference of the relation.

resetRelationList
public void resetRelationList()
Reset the relation list by resetting each relation node.

commitRelationValues
public void commitRelationValues()
Record the current relation values so that when getPreviousMaximumDistance() is called, these recorded values are used. See Also:
getPreviousMaximumDistance()

destroy
public void destroy()
Destroy the relation list by deleting all the contained elements.

getPreviousMaximumDistance
public double getPreviousMaximumDistance()
Return the previous difference of the relation that has the maximum current difference. This is the value as of the last call to commitRelationValues(). Returns:
 The previous distance of a relation.
 See Also:
commitRelationValues()

hasEvent
public boolean hasEvent()
Return true if there exists an event caused by the type change of any relation. Returns:
 True If there exits an event.

isEmpty
public boolean isEmpty()
Return true if the relation list is empty. Returns:
 True If the relation list is empty.

length
public int length()
Return the number of relations in the relation list. Returns:
 the number of relations in the relation list.

getMaximumDifference
public double getMaximumDifference()
Return the maximum current difference of all the relations by iterating the relation list. Returns:
 maximumDistance The maximum current distance.

setRelation
public void setRelation(int relationIndex, int type, double difference)
Update the relation in the relation list referred by the relation index argument with the given type and difference information. Parameters:
relationIndex
 The position of the relation in the relation list.type
 The current type of the relation.difference
 The current difference of the relation.

