Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Adapt to review #20
Browse files Browse the repository at this point in the history
  • Loading branch information
tdauth committed Mar 21, 2019
1 parent 0ca5a05 commit 854cc2a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ trait GuiStateMachineSerializer {
}

object GuiStateMachineSerializer {
def javaObjectStream(guiStateMachine: GuiStateMachine): GuiStateMachineSerializer = GuiStateMachineJavaObjectStreamSerializer(guiStateMachine)
def gml(guiStateMachine: GuiStateMachine): GuiStateMachineSerializer = GuiStateMachinGMLSerializer(guiStateMachine)
def javaObjectStream(guiStateMachine: GuiStateMachine): GuiStateMachineSerializer = new GuiStateMachineJavaObjectStreamSerializer(guiStateMachine)
def gml(guiStateMachine: GuiStateMachine): GuiStateMachineSerializer = new GuiStateMachinGMLSerializer(guiStateMachine)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import de.retest.guistatemachine.api.{GuiStateMachine, GuiStateMachineSerializer
import de.retest.recheck.ui.descriptors.SutState
import org.jgrapht.graph.DirectedPseudograph

case class GuiStateMachinGMLSerializer(guiStateMachine: GuiStateMachine) extends GuiStateMachineSerializer {
class GuiStateMachinGMLSerializer(guiStateMachine: GuiStateMachine) extends GuiStateMachineSerializer {

type GraphType = DirectedPseudograph[SutState, GraphActionEdge]

Expand All @@ -33,10 +33,10 @@ case class GuiStateMachinGMLSerializer(guiStateMachine: GuiStateMachine) extends
// write to file
val outputFile = new File(filePath)
val output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "utf-8"))
try { writer.export(output, toDraw) } finally { if (output != null) { output.close() } }
try { writer.export(output, toDraw) } finally { output.close() }
}

override def load(filePath: String): Unit = throw new RuntimeException("Loading GML is not supported.")
override def load(filePath: String): Unit = throw new UnsupportedOperationException("Loading GML is not supported.")

private def createGraph(): GraphType = {
val graph = new GraphType(classOf[GraphActionEdge])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ import java.io.{FileInputStream, FileOutputStream, ObjectInputStream, ObjectOutp
import de.retest.guistatemachine.api.impl.GuiStateMachineImpl
import de.retest.guistatemachine.api.{GuiStateMachine, GuiStateMachineSerializer}

case class GuiStateMachineJavaObjectStreamSerializer(guiStateMachine: GuiStateMachine) extends GuiStateMachineSerializer {
class GuiStateMachineJavaObjectStreamSerializer(guiStateMachine: GuiStateMachine) extends GuiStateMachineSerializer {

/**
* Stores the state machine on the disk.
* Persistence can be useful when the state machines become quite big and the generation/modification is interrupted
* and continued later.
* Stores the state machine on the disk. Persistence can be useful when the state machines become quite big and the
* generation/modification is interrupted and continued later.
*
* @param filePath The file which the state machine is stored into.
*/
override def save(filePath: String): Unit = {
val oos = new ObjectOutputStream(new FileOutputStream(filePath))
oos.writeObject(guiStateMachine)
oos.close()
try {
oos.writeObject(guiStateMachine)
} finally {
oos.close()
}
}

/**
Expand All @@ -26,10 +28,12 @@ case class GuiStateMachineJavaObjectStreamSerializer(guiStateMachine: GuiStateMa
* @param filePath The file which the state machine is loaded from.
*/
override def load(filePath: String): Unit = {
guiStateMachine.clear()
val ois = new ObjectInputStream(new FileInputStream(filePath))
val readStateMachine = ois.readObject.asInstanceOf[GuiStateMachineImpl]
ois.close()
guiStateMachine.assignFrom(readStateMachine)
try {
val readStateMachine = ois.readObject.asInstanceOf[GuiStateMachineImpl]
guiStateMachine.assignFrom(readStateMachine)
} finally {
ois.close()
}
}
}

0 comments on commit 854cc2a

Please sign in to comment.