JSHOP2
Class TaskList

java.lang.Object
  extended by JSHOP2.CompileTimeObject
      extended by JSHOP2.TaskList

public class TaskList
extends CompileTimeObject

Each task list, both at compile time and at run time, is an instance of this class.

Version:
1.0.3
Author:
Okhtay Ilghami, http://www.cs.umd.edu/~okhtay

Field Summary
static TaskList empty
          This variable represents an empty task list.
private  boolean ordered
          Whether or not this is an ordered task list.
 TaskList[] subtasks
          In case this task list is not-atomic, this array represents it.
private  TaskAtom task
          In case this task list is atomic, this variable represents it.
 
Fields inherited from class JSHOP2.CompileTimeObject
endl
 
Constructor Summary
private TaskList()
          To initialize this task list as an empty one (i.e., an ordered non-atomic task list of length 0).
  TaskList(int size, boolean orderedIn)
          To initialize this task list as a non-atomic one.
  TaskList(TaskAtom taskIn)
          To initialize this task list as an atomic one.
 
Method Summary
 TaskList bind(Term[] binding)
          To bind a task list to a given binding.
 TaskList clone()
          This clone function was added so that TaskLists can be copied and passed to JSHOP2GUI.
static TaskList createTaskList(java.util.Vector<TaskList> subtasksIn, boolean orderedIn)
          To create a non-atomic task list.
 void getChildren(java.util.ArrayList<java.lang.String> childrenList)
          Returns an ArrayList of strings that represent the children of this compound task.
 java.util.LinkedList<TaskList> getFirst()
          To return a LinkedList of the task atoms we have the option to achieve right now.
private  boolean getFirstHelper(java.util.LinkedList<TaskList> res)
          The helper function to calculate a LinkedList of the task atoms we have the option to achieve right now.
 java.lang.String getInitCode(java.lang.String what)
          This function produces Java code used to create this task list either as an atomic task list or recursively, as a list of other task lists.
 TaskList[] getSubtasks()
          Returns the task list's subtasks
 TaskAtom getTask()
          To return the task atom associated with this task list.
 boolean isEmpty()
          Whether or not this task list is, or has become as result of task decomposition, an empty one.
 boolean isOrdered()
          Returns whether or not this is an ordered task list <Added 5/14/06>
 void print()
          This function is used to print this task list.
 void replace(TaskList tasksIn)
          This function replaces (i.e., decomposes) a given task atom with a task list.
 void setVarCount(int varCountIn)
          This function sets the number of variables for this task list.
 java.lang.String toCode()
          This function produces Java code to create this task list.
 java.lang.String toString()
          This function returns a printable String representation of this task list.
 void undo()
          This function undoes the decomposition of a task atom to a task list in case of a backtrack over the decision to decompose the task.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

empty

public static TaskList empty
This variable represents an empty task list. All over the code, whenever any object needs an empty task list, it will use this variable rather than create a new empty task list to save memory because functionally all the empty task lists are the same.


ordered

private boolean ordered
Whether or not this is an ordered task list.


subtasks

public TaskList[] subtasks
In case this task list is not-atomic, this array represents it. Otherwise, this variable will be null.


task

private TaskAtom task
In case this task list is atomic, this variable represents it. Otherwise, this variable will be null.

Constructor Detail

TaskList

private TaskList()
To initialize this task list as an empty one (i.e., an ordered non-atomic task list of length 0). Note that this is a private function in order to minimize its use. In case an empty task list is needed, TaskList.empty should be used to save memory.


TaskList

public TaskList(TaskAtom taskIn)
To initialize this task list as an atomic one.

Parameters:
taskIn - the task atom this task list will represent.

TaskList

public TaskList(int size,
                boolean orderedIn)
To initialize this task list as a non-atomic one.

Parameters:
size - the number of task lists in the task list this object represents.
orderedIn - whether or not this task list is ordered.
Method Detail

bind

public TaskList bind(Term[] binding)
To bind a task list to a given binding.

Parameters:
binding - the given binding
Returns:
the resulting task list.

createTaskList

public static TaskList createTaskList(java.util.Vector<TaskList> subtasksIn,
                                      boolean orderedIn)
To create a non-atomic task list. This is defined as a static function rather than a constructor because it returns TaskList.empty if the required task list is of length 0 rather than creating a new empty task list. Other than that, this function acts like a constructor.

Parameters:
subtasksIn - a Vector of subtasks the output task list will represent.
orderedIn - whether or not the output task list should be ordered.
Returns:
the resulting task list.

getFirst

public java.util.LinkedList<TaskList> getFirst()
To return a LinkedList of the task atoms we have the option to achieve right now. This list might have more than one member because of the existence of unordered task lists.

Returns:
a LinkedList of the task atoms we have the option to achieve right now.

getFirstHelper

private boolean getFirstHelper(java.util.LinkedList<TaskList> res)
The helper function to calculate a LinkedList of the task atoms we have the option to achieve right now.

Parameters:
res - this LinkedList stores the task atoms we have incrementally calculated so far.
Returns:
true if there can be no more task atoms we have the option to achieve next because we have encountered an immediate task atom, false otherwise. This return value is a sign for this function to stop calling itself recursively for more options in case an immediate task atom has been encountered.

getInitCode

public java.lang.String getInitCode(java.lang.String what)
This function produces Java code used to create this task list either as an atomic task list or recursively, as a list of other task lists.

Parameters:
what - the String name of the task list created by this piece of code.
Returns:
the Java code as a String.

getTask

public TaskAtom getTask()
To return the task atom associated with this task list.

Returns:
the task atom associated with this task list in case this is an atomic task list, null otherwise.

isEmpty

public boolean isEmpty()
Whether or not this task list is, or has become as result of task decomposition, an empty one.

Returns:
true if this task list is equivalent to an empty task list, false otherwise.

print

public void print()
This function is used to print this task list.


replace

public void replace(TaskList tasksIn)
This function replaces (i.e., decomposes) a given task atom with a task list.

Parameters:
tasksIn - the decomposition to replace the task atom.

setVarCount

public void setVarCount(int varCountIn)
This function sets the number of variables for this task list. This number is used to return bindings of the appropriate size.

Parameters:
varCountIn - the number of variables for this task list.

toCode

public java.lang.String toCode()
This function produces Java code to create this task list.

Specified by:
toCode in class CompileTimeObject
Returns:
the produced code as a String.

toString

public java.lang.String toString()
This function returns a printable String representation of this task list.

Overrides:
toString in class java.lang.Object
Returns:
the String representation.

undo

public void undo()
This function undoes the decomposition of a task atom to a task list in case of a backtrack over the decision to decompose the task.


clone

public TaskList clone()
This clone function was added so that TaskLists can be copied and passed to JSHOP2GUI. <Added 5/12/06>

Overrides:
clone in class java.lang.Object

isOrdered

public boolean isOrdered()
Returns whether or not this is an ordered task list <Added 5/14/06>


getSubtasks

public TaskList[] getSubtasks()
Returns the task list's subtasks

Returns:
A TaskList[] that represents the subtasks of this task list <Added 5/14/06>

getChildren

public void getChildren(java.util.ArrayList<java.lang.String> childrenList)
Returns an ArrayList of strings that represent the children of this compound task. Used in conjunction with with JSHOP2GUI. <Added 5/26/06>