|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcontrol.Controller
public class Controller
The controller of the Turing Machine. It implements the state, symbol and movement domains as String Accepted movements are "Left", "Right" and "Stop" Copyright (C) 2011 Federico "MrModd" Cosentino (http://mrmodd.it/)
Field Summary | |
---|---|
private static Controller |
controller
|
private java.lang.String |
currentState
|
private java.lang.Integer |
indexOfT
|
private java.lang.String |
initialState
|
private static boolean |
instanced
|
private InstructionSet<java.lang.String,java.lang.String> |
instructions
|
private java.lang.String |
nullSymbol
|
private static long |
serialVersionUID
|
private java.lang.Integer |
steps
|
private tape<java.lang.String> |
T
|
Constructor Summary | |
---|---|
private |
Controller()
Use the getController() method to instance this object |
Method Summary | |
---|---|
void |
clearProgram()
Delete all the instructions on the program set |
void |
clearTape()
Delete all the symbol on the tape |
static void |
deserialize(java.lang.String file)
Load the state of the controller from a file |
int |
getActualPosition()
Get the position of the head on the tape |
static Controller |
getController()
Because this class is a singleton this method should be called to get an instance of it. |
java.lang.String |
getNullSymbol()
Get the symbol that in the actual program represent the null symbol of the tape |
java.lang.String[] |
getProgram()
Get a formatted array of String representing all the instruction of the program loaded |
int |
getSteps()
Get how many steps are executed from the program starts |
java.lang.String |
getTapeSymbol(int index)
Get the symbol written on the specified position |
void |
loadProgram(java.lang.String file)
Read the program from a file |
void |
nextStep()
Execute a single step according with the current state of the machine and the symbol on the tape |
void |
resetSteps()
Reset the steps count |
void |
rewindState()
Return on the initial state of the program |
static void |
serialize(java.lang.String file)
Save the state of the controller on a file |
void |
setTape(int index,
java.lang.String s)
Set a symbol on the selected position |
void |
startGUI()
Start the graphic interface |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final long serialVersionUID
private static boolean instanced
private static Controller controller
private tape<java.lang.String> T
private java.lang.String initialState
private java.lang.String currentState
private java.lang.Integer indexOfT
private java.lang.Integer steps
private java.lang.String nullSymbol
private InstructionSet<java.lang.String,java.lang.String> instructions
Constructor Detail |
---|
private Controller()
Method Detail |
---|
public static Controller getController()
public void startGUI()
public void loadProgram(java.lang.String file) throws java.io.IOException, ProgramFileSyntaxException
file
- the path of the file to read
java.io.IOException
- if something goes wrong with the reading of file
ProgramFileSyntaxException
- if the file does not contain a valid programpublic java.lang.String getNullSymbol()
public int getSteps()
public int getActualPosition()
public void nextStep() throws ProgramHaltedException
ProgramHaltedException
- if the execution of the program reach the endpublic java.lang.String getTapeSymbol(int index)
index
- the position of the tape
public java.lang.String[] getProgram()
public void setTape(int index, java.lang.String s) throws java.lang.IllegalArgumentException
index
- the position of the tapes
- the symbol to write
java.lang.IllegalArgumentException
- if the position isn't validpublic void clearTape()
public void rewindState()
public void resetSteps()
public void clearProgram()
public static void serialize(java.lang.String file) throws java.io.IOException
file
- where to save the state
java.io.IOException
- if something goes wrong while savingpublic static void deserialize(java.lang.String file) throws java.lang.ClassNotFoundException, java.io.IOException
file
- where to find the state
java.lang.ClassNotFoundException
- if the file isn't valid
java.io.IOException
- if something goes wrong while reading the file
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |