📄 twothreepcursoruos.java
字号:
/* TwoThreeCursorUos.java
* ---------------------------------------------
* Copyright (c) 2001 University of Saskatchewan
* All Rights Reserved
* --------------------------------------------- */
package dslib.dictionary.twothreetree;
import dslib.base.*;
import dslib.exception.NoCurrentItemUosException;
/** A cursor for the two-three tree data structures. */
public class TwoThreePCursorUos implements KeyedCursorUos
{
/** The current node*/
protected TwoThreePLeafUos node;
/** Is the cursor after the last item?. */
protected boolean after;
/** Create a new cursor. <br>
Analysis: Time = O(1)
@param leaf the leaf we are starting at
@param isAfter are we after the list? */
public TwoThreePCursorUos(TwoThreePLeafUos leaf, boolean isAfter)
{
after = isAfter;
node = leaf;
}
/** Is there a current item?. <br>
Analysis: Time = O(1) */
public boolean itemExists()
{
return node!=null;
}
/** The key of the current item. <br>
Analysis: Time = O(1) <br>
PRECONDITION: <br>
<ul>
itemExists()
</ul> */
public Comparable itemKey() throws NoCurrentItemUosException
{
if (!itemExists())
throw new NoCurrentItemUosException("No Item");
return node.key();
}
/** The current item. <br>
Analysis: Time = O(1) <br>
PRECONDITION: <br>
<ul>
itemExists()
</ul>*/
public Object item() throws NoCurrentItemUosException
{
if (!itemExists())
throw new NoCurrentItemUosException("No Item");
return node;
}
/** The current key-item pair. <br>
PRECONDITION: <br>
<ul>
itemExists()
</ul> */
public PairUos keyItemPair() throws NoCurrentItemUosException
{
if (!itemExists())
throw new NoCurrentItemUosException("No Item");
return new PairUos(itemKey(), item());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -