1 22 23 package client; 24 25 26 34 public final class CommandHistory extends java.util.LinkedList { 35 38 private static int MAX_SIZE; 39 40 43 private static int current; 44 45 CommandHistory(int s) { 46 super(); 47 MAX_SIZE = s; 48 current = -1; 49 } 50 51 57 public void add(String s) { 58 addFirst(s); 59 if (size() > MAX_SIZE) { 60 removeLast(); 61 } 62 current = -1; 63 } 64 65 71 public String getUp() { 72 if (size() == 0) return null; 73 if (current+1 >= size()) 74 return null; 75 current++; 76 return (String ) get(current); 77 } 78 79 85 public String getDown() { 86 if (size() == 0) return null; 87 if (current > 0) { 88 current--; 89 return (String ) get(current); 90 } else if (current == 0) { 91 current--; 92 return ""; 93 } 94 return null; 95 } 96 } 97 | Popular Tags |