ubc.cs.JLog.Foundation
Class jGoalStack

java.lang.Object
  extended by ubc.cs.JLog.Foundation.jGoalStack
All Implemented Interfaces:
iGoalStack
Direct Known Subclasses:
jDebugGoalStack

public class jGoalStack
extends java.lang.Object
implements iGoalStack

jGoalStack is the default goal stack implementation. It is efficient, with a super-efficient cut operation. The design purpose of this class is purely efficiency.

Author:
Glendon Holst

Field Summary
protected  jGoal head
           
 
Constructor Summary
jGoalStack()
           
 
Method Summary
 jGoal cut(jGoal item)
          Removes all goals above the specified item.
 boolean empty()
          Determines if the stack does not contain goals.
 jGoal peek()
          Returns the top goal of the stack, without removing that goal.
 jGoal peekn(int n)
          Returns the nth goal on the stack, without removing that goal.
 jGoal pop()
          Returns and removes the top goal of the stack.
 jGoal push(jGoal item)
          Places the provided goal item as the top element of the stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

head

protected jGoal head
Constructor Detail

jGoalStack

public jGoalStack()
Method Detail

empty

public boolean empty()
Description copied from interface: iGoalStack
Determines if the stack does not contain goals.

Specified by:
empty in interface iGoalStack
Returns:
true if the stack is empty, false otherwise.

pop

public jGoal pop()
Description copied from interface: iGoalStack
Returns and removes the top goal of the stack. Do not pop an empty stack.

Specified by:
pop in interface iGoalStack
Returns:
the top jGoal of the stack.

peek

public jGoal peek()
Description copied from interface: iGoalStack
Returns the top goal of the stack, without removing that goal. Do not peek an empty stack.

Specified by:
peek in interface iGoalStack
Returns:
the top jGoal of the stack.

peekn

public jGoal peekn(int n)
Description copied from interface: iGoalStack
Returns the nth goal on the stack, without removing that goal. Do not peek an empty stack. 0 is the top element.

Specified by:
peekn in interface iGoalStack
Returns:
the nth jGoal of the stack.

push

public jGoal push(jGoal item)
Description copied from interface: iGoalStack
Places the provided goal item as the top element of the stack.

Specified by:
push in interface iGoalStack
Parameters:
item - the goal to add to the stack top.
Returns:
the top jGoal of the stack, which is the provided item.

cut

public jGoal cut(jGoal item)
Description copied from interface: iGoalStack
Removes all goals above the specified item. item becomes the top goal.

Specified by:
cut in interface iGoalStack
Parameters:
item - the goal to truncate the stack at. item becomes the stack top. item must be in this stack instance.
Returns:
the top jGoal of the stack, which is the provided item.