commandhistory.java

来自「ErGo是一个很早的Java通用围棋服务器(IGS/NNGS)客户端程序。有全部」· Java 代码 · 共 52 行

JAVA
52
字号
package ergo.util;

// $Id: CommandHistory.java,v 1.2 1999/08/13 01:20:42 sigue Exp $

/*
 *  Copyright (C) 1999  Carl L. Gay and Antranig M. Basman.
 *  See the file copyright.txt, distributed with this software,
 *  for further information.
 */

import java.util.Vector;

// Maintain a command history.  Always add new elements on the end.
public class CommandHistory {
  private Vector history = new Vector();
  private int index = -1;

  public String getCurrentElement () {
    if (history.size() == 0)
      return null;
    else
      return (String) history.elementAt(index);
  }

  public String getPreviousElement () {
    if (index < 0)
      return null;
    else
      return (String) history.elementAt(index--);
  }

  public String getNextElement () {
    if (index >= history.size() - 1)
      return null;
    else
      return (String) history.elementAt(++index);
  }

  public void addElement (String text) {
    String end = ((history.size() == 0)
		  ? ""
		  : (String) history.elementAt(history.size() - 1));
    if (!text.equals(end))
      history.addElement(text);
    goToEnd();
  }

  public void goToEnd () {
    index = history.size() - 1;
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?