From 66647c0e908354cb7ce39dfe425a109b2c13f6c8 Mon Sep 17 00:00:00 2001 From: Tamino Dauth Date: Tue, 7 May 2019 13:34:11 +0200 Subject: [PATCH] Allow storing possible actions per state #34 --- .../de/retest/guistatemachine/api/State.scala | 15 +++++++++++++++ .../guistatemachine/api/impl/StateImpl.scala | 16 +++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/scala/de/retest/guistatemachine/api/State.scala b/src/main/scala/de/retest/guistatemachine/api/State.scala index b199f37..0483216 100644 --- a/src/main/scala/de/retest/guistatemachine/api/State.scala +++ b/src/main/scala/de/retest/guistatemachine/api/State.scala @@ -23,6 +23,21 @@ trait State { */ def getIncomingActionTransitions: Map[ActionIdentifier, ActionTransitions] + /** + * @groupname possibleactions Possible Actions + * The set of possible actions has to be restricted for certain action types like ChangeValueAction. The set should always be the same for the same elements per state. It can be used for exploration strategies. + * + * @param possibleActions The possible actions of the state. + * @group possibleactions + */ + def setPossibleActions(possibleActions: Set[ActionIdentifier]) + + /** + * @return The possible actions of the state. + * @group possibleactions + */ + def getPossibleActions: Set[ActionIdentifier] + /** * Overriding this method is required to allow the usage of a set of states. * Comparing the descriptors should check for the equality of all root elements which compares the identifying attributes and the contained components diff --git a/src/main/scala/de/retest/guistatemachine/api/impl/StateImpl.scala b/src/main/scala/de/retest/guistatemachine/api/impl/StateImpl.scala index 91a9f14..aba16f8 100644 --- a/src/main/scala/de/retest/guistatemachine/api/impl/StateImpl.scala +++ b/src/main/scala/de/retest/guistatemachine/api/impl/StateImpl.scala @@ -2,7 +2,7 @@ package de.retest.guistatemachine.api.impl import de.retest.guistatemachine.api.{ActionIdentifier, ActionTransitions, State, SutStateIdentifier} -import scala.collection.immutable.HashMap +import scala.collection.immutable.{HashMap, HashSet} @SerialVersionUID(1L) case class StateImpl(sutState: SutStateIdentifier) extends State with Serializable { @@ -18,9 +18,19 @@ case class StateImpl(sutState: SutStateIdentifier) extends State with Serializab */ private var incomingActionTransitions = HashMap[ActionIdentifier, ActionTransitions]() + private var possibleActions: Set[ActionIdentifier] = HashSet[ActionIdentifier]() + override def getSutStateIdentifier: SutStateIdentifier = this.synchronized { sutState } - override def getOutgoingActionTransitions: Map[ActionIdentifier, ActionTransitions] = this.synchronized { outgoingActionTransitions } - override def getIncomingActionTransitions: Map[ActionIdentifier, ActionTransitions] = this.synchronized { incomingActionTransitions } + override def getOutgoingActionTransitions: Map[ActionIdentifier, ActionTransitions] = this.synchronized { + outgoingActionTransitions + } + override def getIncomingActionTransitions: Map[ActionIdentifier, ActionTransitions] = this.synchronized { + incomingActionTransitions + } + override def setPossibleActions(possibleActions: Set[ActionIdentifier]): Unit = this.synchronized { + this.possibleActions = possibleActions + } + override def getPossibleActions: Set[ActionIdentifier] = this.synchronized { possibleActions } private[api] override def addTransition(a: ActionIdentifier, to: State): Int = { val executionCounter = this.synchronized {