org.foray.ps
Class PsStack<T>

java.lang.Object
  extended by org.foray.ps.PsStack<T>
Type Parameters:
T - The class of objects in this stack.
Direct Known Subclasses:
PsDictionaryStack, PsExecutionStack, PsGraphicsStateStack, PsOperandStack

public abstract class PsStack<T>
extends Object

The PSStack represents a PostScript stack.


Field Summary
protected static int DEFAULT_STACK_SIZE
          Constant indicating the default number of entries in a stack.
 
Method Summary
protected abstract  T filterPush(T objectToPush)
          A hook for subclasses to filter the content of items being pushed onto the stack.
 PsInterpreter4a getInterpreter()
          Returns the internal list.
protected  List<T> getList()
          Returns the internal list.
abstract  int getMinimumStackSize()
          Returns the minumum size that this stack can be.
abstract  PsError getUnderflowError()
          Returns the appropriate PS error that should be used for an underflow condition in this stack.
 T peek()
          Returns the top element from the stack, but leaves it on the stack.
 T peek(int indexFromTop)
          Returns a stack item without removing it or anything else from the stack.
 T pop()
          Discards and returns the top element at the request of the interpreter, that is, with no known operation triggering the pop.
 T pop(PsOperator operatorCode)
          Discards and returns the top element from the stack.
 int size()
          Returns the size of the stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_STACK_SIZE

protected static final int DEFAULT_STACK_SIZE
Constant indicating the default number of entries in a stack.

See Also:
Constant Field Values
Method Detail

pop

public T pop(PsOperator operatorCode)
      throws PsOperatorException
Discards and returns the top element from the stack.

Parameters:
operatorCode - The operator requesting the pop. This is used in user messages.
Returns:
The top item from the stack, which was just discarded.
Throws:
PsOperatorException - For PostScript stackunderflow errors.

getMinimumStackSize

public abstract int getMinimumStackSize()
Returns the minumum size that this stack can be. Attempts to pop an item off the stack that would violate this constraint will result in an underflow error.

Returns:
The minimum size that this stack can be.

getUnderflowError

public abstract PsError getUnderflowError()
Returns the appropriate PS error that should be used for an underflow condition in this stack.

Returns:
The PS underflow error for this stack.

pop

public T pop()
      throws PsOperatorException
Discards and returns the top element at the request of the interpreter, that is, with no known operation triggering the pop.

Returns:
The top item from the stack, which was just discarded.
Throws:
PsOperatorException - For PostScript stackunderflow errors.

peek

public T peek()
Returns the top element from the stack, but leaves it on the stack.

Returns:
The top item from the stack.

peek

public T peek(int indexFromTop)
Returns a stack item without removing it or anything else from the stack.

Parameters:
indexFromTop - The number of items deep in the stack the desired element is. To get the top element, set to 0. To get the next element down, set to 1, etc.
Returns:
The nth item down the stack, where n is indexFromTop.

size

public int size()
Returns the size of the stack.

Returns:
The number of items in the stack.

getList

protected List<T> getList()
Returns the internal list.

Returns:
The internal list.

getInterpreter

public PsInterpreter4a getInterpreter()
Returns the internal list.

Returns:
The internal list.

filterPush

protected abstract T filterPush(T objectToPush)
A hook for subclasses to filter the content of items being pushed onto the stack.

Parameters:
objectToPush - The nominal object being pushed onto the stack.
Returns:
The object that should actually be pushed onto the stack. This can be the same as objectToPush, but is not required to be so.


Copyright © 2017. All rights reserved.