nonemptybookmarks.java
来自「书籍"Java_面向事件编程"的附带光盘代码」· Java 代码 · 共 40 行
JAVA
40 行
// a recursive data structure that stores a list of bookmarksclass NonemptyBookmarks extends EmptyBookmarks { private EmptyBookmarks rest; private Bookmark first; private int mysize; public NonemptyBookmarks(EmptyBookmarks list, Bookmark entry) { rest = list; first = entry; mysize = rest.getSize() + 1; } // if this bookmark is at the desired position, return it, // otherwise decrement the desired position and pass the call // on to the rest of the list public Bookmark getSelectedItem( int position ) { if ( position == 0 ) return first; else try { return rest.getSelectedItem( position-1); }catch (IllegalArgumentException e) { throw new IllegalArgumentException("Index "+position+" is out of range"); } } public int getSize() { return mysize; } public boolean isemtpy() { return false; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?