jline

Class SimpleCompletor

Implemented Interfaces:
Cloneable, Completor
Known Direct Subclasses:
ClassNameCompletor

public class SimpleCompletor
extends java.lang.Object
implements Completor, Cloneable

A simple Completor implementation that handles a pre-defined list of completion words.

Example usage:

  myConsoleReader.addCompletor (new SimpleCompletor (new String [] { "now", "yesterday", "tomorrow" }));
  
Author:
Marc Prud'hommeaux

Nested Class Summary

static class
SimpleCompletor.NoOpFilter
static interface
SimpleCompletor.SimpleCompletorFilter
Filter for elements in the completor.

Field Summary

(package private) SortedSet
candidates
The list of candidates that will be completed.
(package private) String
delimiter
A delimiter to use to qualify completions.
(package private) SimpleCompletor.SimpleCompletorFilter
filter

Constructor Summary

SimpleCompletor(InputStream in)
Complete candidates using the whitespearated values in read from the specified Reader.
SimpleCompletor(Reader reader)
Complete candidates using the contents of the specified Reader.
SimpleCompletor(String candidateString)
Create a new SimpleCompletor with a single possible completion values.
SimpleCompletor(String[] candidateStrings)
Create a new SimpleCompletor with a list of possible completion values.
SimpleCompletor(String[] strings, SimpleCompletor.SimpleCompletorFilter filter)

Method Summary

void
addCandidateString(String candidateString)
Object
clone()
int
complete(String buffer, int cursor, List clist)
Populates candidates with a list of possible completions for the buffer.
SortedSet
getCandidates()
String
getDelimiter()
private static String[]
getStrings(Reader in)
void
setCandidateStrings(String[] strings)
void
setCandidates(SortedSet candidates)
void
setDelimiter(String delimiter)

Field Details

candidates

(package private)  SortedSet candidates
The list of candidates that will be completed.

delimiter

(package private)  String delimiter
A delimiter to use to qualify completions.

filter

(package private) final SimpleCompletor.SimpleCompletorFilter filter

Constructor Details

SimpleCompletor

public SimpleCompletor(InputStream in)
            throws IOException
Complete candidates using the whitespearated values in read from the specified Reader.

SimpleCompletor

public SimpleCompletor(Reader reader)
            throws IOException
Complete candidates using the contents of the specified Reader.

SimpleCompletor

public SimpleCompletor(String candidateString)
Create a new SimpleCompletor with a single possible completion values.

SimpleCompletor

public SimpleCompletor(String[] candidateStrings)
Create a new SimpleCompletor with a list of possible completion values.

SimpleCompletor

public SimpleCompletor(String[] strings,
                       SimpleCompletor.SimpleCompletorFilter filter)

Method Details

addCandidateString

public void addCandidateString(String candidateString)

clone

public Object clone()
            throws CloneNotSupportedException

complete

public int complete(String buffer,
                    int cursor,
                    List clist)
Populates candidates with a list of possible completions for the buffer. The candidates list will not be sorted before being displayed to the user: thus, the complete method should sort the List before returning.
Specified by:
complete in interface Completor
Parameters:
buffer - the buffer
Returns:
the index of the buffer for which the completion will be relative

getCandidates

public SortedSet getCandidates()

getDelimiter

public String getDelimiter()

getStrings

private static String[] getStrings(Reader in)
            throws IOException

setCandidateStrings

public void setCandidateStrings(String[] strings)

setCandidates

public void setCandidates(SortedSet candidates)

setDelimiter

public void setDelimiter(String delimiter)