Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

Commit

Permalink
PROBCORE-857 tests and javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
joyheron committed Jun 24, 2015
1 parent 27cc508 commit 0a10ddf
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
13 changes: 13 additions & 0 deletions de.prob2.kernel/groovyTests/syncedTraces.groovy
Expand Up @@ -29,13 +29,26 @@ try {
}
assert thrown

thrown = false
try {
tt.iDontExist()
} catch(IllegalArgumentException e) {
thrown = true
}
assert thrown

tt1 = tt.execute(0, "new", [])
assert tt1.traces[0].getCurrentTransition().getName() == "new"
assert tt1.traces[1].getCurrentTransition().getName() == "up"
tt2 = tt1.execute(1, "down", [])
assert tt2.traces[0].getCurrentTransition().getName() == "del"
assert tt2.traces[1].getCurrentTransition().getName() == "down"

tt3 = tt.execute(0, "nr_ready", [])
assert tt3.traces[0].getCurrentTransition().getName() == "nr_ready"
assert tt3.traces[1] == t1

assert tt.toString() instanceof String

s0.animator.cli.shutdown();
s1.animator.cli.shutdown();
Expand Down
@@ -1,19 +1,36 @@
package de.prob.statespace

/**
* Defined {@link SyncedEvent}s can be used to synchronize animations with the
* {@link SyncedTraces} object.
* @author joy
*
*/
class SyncedEvent {

final String name
final Map<UUID,Event> synced

/**
* @param name is a user defined name to specify this particular event.
* @param synced is a mapping from the UUID of a Trace object to an {@link Event} object
* defining the event that should be executed on the specified trace
*/
def SyncedEvent(String name, Map<UUID, Event> synced=[:]) {
this.name = name
this.synced = synced
}

def SyncedEvent sync(Trace t, String name, List<String> parameters) {
/**
* @param trace for which this event should be synchronized
* @param name of the event to be synchronized
* @param parameters a list of String predicates defining the parameters
* @return a new {@link SyncedEvent} with this configuration added.
*/
def SyncedEvent sync(Trace trace, String name, List<String> parameters) {
def intNames = [:]
intNames.putAll(synced)
intNames[t.getUUID()] = new Event(name, parameters)
intNames[trace.getUUID()] = new Event(name, parameters)
return new SyncedEvent(this.name, intNames)
}

Expand Down
Expand Up @@ -3,19 +3,40 @@ package de.prob.statespace
import de.prob.model.representation.ModelElementList
import de.prob.statespace.SyncedEvent.Event

/**
* Provides an API to synchronize the animation of different {@link Trace}s.
* @author joy
*
*/
class SyncedTraces {
final List<Trace> traces
final ModelElementList<SyncedEvent> syncedEvents
private final ModelElementList<SyncedEvent> syncedEvents

def SyncedTraces(List<Trace> traces, List<SyncedEvent> events) {
this.traces = traces
this.syncedEvents = (events instanceof ModelElementList) ? events : new ModelElementList<SyncedEvent>(events)
}

/**
* This method has been marked as deprecated because it is only available in the class to
* enable groovy magic. Calls the {@link SyncedTraces#execute(String)} method. In a Java environment,
* call this directly.
* @param name of method
* @param args from method
*/
@Deprecated
def invokeMethod(String name, args) {
execute(name)
}


/**
* Attempts to execute a synchronized event.
* @param name of a user defined {@link SyncedEvent}
* @return a new {@link SyncedTraces} object in which all of the events defined by the
* specified {@link SyncedEvent} have been executed.
* @throws IllegalArgumentException if no synced event with that name has been defined
*/
def SyncedTraces execute(String name) {
if (!syncedEvents[name]) {
throw new IllegalArgumentException("No syncronized event is named $name")
Expand All @@ -28,6 +49,17 @@ class SyncedTraces {
return new SyncedTraces(newTraces, syncedEvents)
}

/**
* If the name and parameters for the specified {@link Trace} are defined by a {@link SyncedEvent},
* the {@link SyncedEvent} is fired. Otherwise, the name and parameters combination is executed for
* the specified {@link Trace} via the {@link Trace#execute(String,List<String>)} method.
* @param index of the {@link Trace} that is of interest
* @param name of the event to be executed
* @param parameters a list of String predicates which represent a conjunction defining the
* parameters that can be defined for this event.
* @return a new {@link SyncedTraces} object after the specified event has been executed
* @throws IllegalArgumentException if executing the specified event is not successful
*/
def SyncedTraces execute(int index, String name, List<String> parameters) {
List<Trace> newTraces = new ArrayList<Trace>(traces)
Trace t = traces[index]
Expand Down

0 comments on commit 0a10ddf

Please sign in to comment.