1 19 20 package org.chateverywhere; 21 22 import java.util.*; 23 24 public class InputStack 25 { 26 private int max_elements_in_stack = 30; 27 private int input_stack_pos; 28 private Vector input_stack; 29 30 public InputStack() 31 { 32 input_stack = new Vector(max_elements_in_stack); 33 input_stack_pos = 0; 34 } 35 36 public InputStack(int max) 37 { 38 max_elements_in_stack = max; 39 } 40 41 42 public void add(String entry) 43 { 44 if(input_stack.size() == max_elements_in_stack) 45 input_stack.removeElementAt(max_elements_in_stack - 1); 46 47 input_stack.insertElementAt(entry, 0); 48 input_stack_pos = 0; 49 } 50 51 52 53 public String up() 54 { 55 if(input_stack_pos < input_stack.size()) 56 return (String ) input_stack.elementAt(input_stack_pos++); 57 58 return (String ) input_stack.elementAt(input_stack_pos - 1); 59 } 60 61 62 public String down() 63 { 64 if(input_stack_pos == 0) { 65 return null; 66 } else if(input_stack_pos == 1) { 67 input_stack_pos = 0; 68 return ""; 69 } 70 71 return (String ) input_stack.elementAt(--input_stack_pos - 1); 72 } 73 } 74 | Popular Tags |