model
Class tape<T>

java.lang.Object
  extended by model.tape<T>
All Implemented Interfaces:
java.io.Serializable

public class tape<T>
extends java.lang.Object
implements java.io.Serializable

A simple reimplementation of an array doubling with two direction movements null represent the empty symbol of the alphabet Copyright (C) 2011 Federico "MrModd" Cosentino (http://mrmodd.it/)

See Also:
Serialized Form

Field Summary
private  java.util.List<T> Left
           
private  java.util.List<T> Right
           
private static long serialVersionUID
           
private  T zero
           
 
Constructor Summary
tape()
          Create a tape the initial dimension is 3 for Left and Right lists
tape(int dim)
          Create a tape
 
Method Summary
 void erase()
          Clear all the elements in the tape
 T get(int index)
          Get the symbol at the index position
 boolean isEmpty()
          Check if the tape contains some symbols
 boolean putLeft(T e)
          Add an element to the Left list
 boolean putRight(T e)
          Add an element to the Right list
 void set(int index, T e)
          Set a symbol on the specified index of the tape.
 int size()
          Get the dimension of the written tape
 int sizeLeft()
          Get the dimension of the Left array
 int sizeRight()
          Get the dimension of the Right array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

Left

private java.util.List<T> Left

Right

private java.util.List<T> Right

zero

private T zero
Constructor Detail

tape

public tape()
Create a tape the initial dimension is 3 for Left and Right lists


tape

public tape(int dim)
Create a tape

Parameters:
dim - initial dimension for the Left and Right lists
Method Detail

putLeft

public boolean putLeft(T e)
Add an element to the Left list

Parameters:
e - the element to add
Returns:
true if the element was added

putRight

public boolean putRight(T e)
Add an element to the Right list

Parameters:
e - the element to add
Returns:
true if the element was added

set

public void set(int index,
                T e)
         throws java.lang.IllegalArgumentException
Set a symbol on the specified index of the tape. If the position is the last of the written tape and the symbol is null, then that element of the list is removed.

Parameters:
index - could be positive or negative
e - symbol to write in at the specified position
Throws:
java.lang.IllegalArgumentException - if index is far more than one step from the end of the written string (the TM could not move more than one step from his current location)

get

public T get(int index)
Get the symbol at the index position

Parameters:
index - could be positive or negative
Returns:
the selected symbol or null if there's no symbol written

isEmpty

public boolean isEmpty()
Check if the tape contains some symbols

Returns:
true if tape is empty

size

public int size()
Get the dimension of the written tape

Returns:
an int representing the length of the tape

sizeLeft

public int sizeLeft()
Get the dimension of the Left array

Returns:
an int representing the length of the Left array

sizeRight

public int sizeRight()
Get the dimension of the Right array

Returns:
an int representing the length of the Right array

erase

public void erase()
Clear all the elements in the tape