FileDocCategorySizeDatePackage
PTIteratorImpl.javaAPI DocphoneME MR2 API (J2ME)6579Wed May 02 18:00:22 BST 2007com.sun.midp.chameleon.input

PTIteratorImpl

public class PTIteratorImpl extends Object implements PTIterator
Implements PTIterator using machine-dependent KNI interface.

Fields Summary
static final int
MAX_STRING
Internal array size to hold KNI word completion
private byte[]
entry
Internal array to hold KNI word completion
private int
handle
current handle
Constructors Summary
public PTIteratorImpl(int dictionary)
create a new iterator

param
dictionary dictionary id

    
                   
       
        entry = new byte[MAX_STRING];
        handle = ptNewIterator0(dictionary);
    
Methods Summary
public booleanhasNext()
Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

return
true if the iterator has more elements.

        boolean ret = false;
        if (isValid()) {
            ret = ptHasCompletionOption0(handle);
        }
        return ret;
    
public booleanisValid()
check if current handle is valid

return
true is valid, false otherwise

        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
            Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
                "isValid = " + (handle != 0));
        }
        return handle > 0;
    
public java.lang.Stringnext()
Returns the next element in the iteration.

return
next element in the iteration.
exception
NoSuchElementException iteration has no more elements.

        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
            Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
                "[iter.nextCompletionOption] >>");
        }
        String ret = null;

        if (isValid()) {
            ret = ptNextCompletionOption0(handle, entry.length);
        }

        if (ret == null)
            ret = "";

        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
            Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
                "[iter.nextCompletionOption] : " + ret);
        }

        return ret;
    
public voidnextLevel(int keyCode)
Adds a key to current completion string

param
keyCode char in the range '0'-'9', '#', or '*'

        if (isValid()) {
            ptAddKey0(handle, keyCode);
        }
    
public voidprevLevel()
Backspace on key in current completion string.

        if (isValid()) {
            ptDeleteKey0(handle);
        }
    
private static native booleanptAddKey0(int handle, int keyCode)
Advances the predictive text iterator using the next key code

param
handle the handle of the iterator
param
keyCode the next key ('0'-'9')
return
true if key code has been added successfully otherwise false

private static native booleanptClear0(int handle)
Clear all text from the predictive text iterator

param
handle the handle of the iterator
return
true if iterator has been cleared successfully otherwise false.

private static native booleanptDeleteKey0(int handle)
Backspace the iterator one key

param
handle the handle of the iterator
return
true if key has been deleted successfully otherwise false.

private static native booleanptHasCompletionOption0(int handle)
see if exist further completion options for the current predictive text entry

param
handle the handle of the iterator
return
true if more completion options exist, false otherwise

private static native intptNewIterator0(int dictionary)
Create a new iterator instance

param
dictionary library handle
return
handle of new iterator.

private static native java.lang.StringptNextCompletionOption0(int handle, int outMaxSize)
return the current predictive text completion option

param
handle the handle of the iterator
param
outMaxSize max size of the outArray
return
next element in the iteration

private static native booleanptRenewCompletionOptions0(int handle)
reset completion options for for the current predictive text entry After this call, ptNextCompletionOption() will return all completion options starting from 1st one.

param
handle the handle of the iterator
return
true if iterator has been reset successfully otherwise false.

public voidreset()
create a new handle and clear completion state by calling ptNewIterator0()

        ptClear0(handle);
    
public voidresetNext()
Reverts to first possible completion. If next() has been called uptil hasNext() returns false, then after calling reviewCompletionOptions(), calling next() will return the 1st completion

        if (isValid()) {
            ptRenewCompletionOptions0(handle);
        }