edu.rice.cs.drjava.ui.predictive
Class PredictiveInputModel<T extends Comparable<? super T>>

java.lang.Object
  extended by edu.rice.cs.drjava.ui.predictive.PredictiveInputModel<T>

public class PredictiveInputModel<T extends Comparable<? super T>>
extends Object

Model class for predictive string input.


Nested Class Summary
static class PredictiveInputModel.FragmentLineNumStrategy<X extends Comparable<? super X>>
          Matching based on string fragments, supporting line numbers.
static class PredictiveInputModel.FragmentStrategy<X extends Comparable<? super X>>
          Matching based on string fragments.
static interface PredictiveInputModel.MatchingStrategy<X extends Comparable<? super X>>
          Strategy used for matching and mask extension.
static class PredictiveInputModel.PrefixLineNumStrategy<X extends Comparable<? super X>>
          Matching based on string prefix, supporting line numbers separated by :.
static class PredictiveInputModel.PrefixStrategy<X extends Comparable<? super X>>
          Matching based on string prefix.
static class PredictiveInputModel.RegExLineNumStrategy<X extends Comparable<? super X>>
          Matching based on string regular expressions, supporting line numbers.
static class PredictiveInputModel.RegExStrategy<X extends Comparable<? super X>>
          Matching based on string regular expressions.
 
Field Summary
private  boolean _ignoreCase
          True if case should be ignored.
private  int _index
          Index of currently selected full string.
private  ArrayList<T> _items
          Array of items.
private  String _mask
          Currently entered mask.
private  ArrayList<T> _matchingItems
          Array of matching items.
private  PredictiveInputModel.MatchingStrategy<T> _strategy
          Matching strategy.
 
Constructor Summary
PredictiveInputModel(boolean ignoreCase, PredictiveInputModel.MatchingStrategy<T> strategy, Collection<T> items)
          Create a new predictive input model.
PredictiveInputModel(boolean ignoreCase, PredictiveInputModel.MatchingStrategy<T> strategy, T... items)
          Create a new predictive input model.
PredictiveInputModel(boolean ignoreCase, PredictiveInputModel<T> pim)
          Create a new predictive input model.
 
Method Summary
 void extendMask(String extension)
          Extends the mask.
 void extendSharedMask()
          Extends the mask by the shared string.
 T getCurrentItem()
          Get currently selected item.
 List<T> getItems()
          Returns a copy of the list of items.
 String getMask()
          Return the current mask.
 List<T> getMatchingItems()
          Get matching items.
 String getSharedMaskExtension()
          Returns the shared mask extension.
private  int indexOf(ArrayList<T> l, T item)
          Helper function that does indexOf with ignoreCase option.
private  void pickClosestMatch(T item)
          Select as current item the item in the list of current matches that lexicographically precedes it most closely.
 void setCurrentItem(T item)
          Set currently selected item.
 void setItems(Collection<T> items)
          Sets the list.
 void setItems(PredictiveInputModel<T> pim)
          Sets the list.
 void setItems(T... items)
          Sets the list
 void setMask(String mask)
          Set the current mask.
 void setStrategy(PredictiveInputModel.MatchingStrategy<T> strategy)
          Sets the strategy
private  void updateMatchingStrings(ArrayList<T> items)
          Update the list of matching strings and current index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_items

private volatile ArrayList<T extends Comparable<? super T>> _items
Array of items.


_index

private volatile int _index
Index of currently selected full string.


_matchingItems

private final ArrayList<T extends Comparable<? super T>> _matchingItems
Array of matching items.


_mask

private volatile String _mask
Currently entered mask.


_ignoreCase

private volatile boolean _ignoreCase
True if case should be ignored.


_strategy

private volatile PredictiveInputModel.MatchingStrategy<T extends Comparable<? super T>> _strategy
Matching strategy.

Constructor Detail

PredictiveInputModel

public PredictiveInputModel(boolean ignoreCase,
                            PredictiveInputModel<T> pim)
Create a new predictive input model.

Parameters:
ignoreCase - true if case should be ignored
pim - other predictive input model

PredictiveInputModel

public PredictiveInputModel(boolean ignoreCase,
                            PredictiveInputModel.MatchingStrategy<T> strategy,
                            Collection<T> items)
Create a new predictive input model.

Parameters:
ignoreCase - true if case should be ignored
strategy - matching strategy to use
items - list of items

PredictiveInputModel

public PredictiveInputModel(boolean ignoreCase,
                            PredictiveInputModel.MatchingStrategy<T> strategy,
                            T... items)
Create a new predictive input model.

Parameters:
ignoreCase - true if case should be ignored
strategy - matching strategy to use
items - varargs/array of items
Method Detail

setStrategy

public void setStrategy(PredictiveInputModel.MatchingStrategy<T> strategy)
Sets the strategy


getItems

public List<T> getItems()
Returns a copy of the list of items.

Returns:
list of items

setItems

public void setItems(Collection<T> items)
Sets the list.

Parameters:
items - list of items

setItems

public void setItems(T... items)
Sets the list

Parameters:
items - varargs/array of items

setItems

public void setItems(PredictiveInputModel<T> pim)
Sets the list.

Parameters:
pim - other predictive input model

getMask

public String getMask()
Return the current mask.

Returns:
current mask

setMask

public void setMask(String mask)
Set the current mask.

Parameters:
mask - new mask

indexOf

private int indexOf(ArrayList<T> l,
                    T item)
Helper function that does indexOf with ignoreCase option.

Parameters:
l - list
item - item for which the index should be retrieved
Returns:
index of item in list, or -1 if not found

updateMatchingStrings

private void updateMatchingStrings(ArrayList<T> items)
Update the list of matching strings and current index.

Parameters:
items - list of items to base the matching on

getCurrentItem

public T getCurrentItem()
Get currently selected item.

Returns:
currently selected item

setCurrentItem

public void setCurrentItem(T item)
Set currently selected item. Will select the item, or if the item does not match the mask, an item as closely preceding as possible.

Parameters:
item - currently selected item

pickClosestMatch

private void pickClosestMatch(T item)
Select as current item the item in the list of current matches that lexicographically precedes it most closely.

Parameters:
item - item for witch to find the closest match

getMatchingItems

public List<T> getMatchingItems()
Get matching items.

Returns:
list of matching items

getSharedMaskExtension

public String getSharedMaskExtension()
Returns the shared mask extension. The shared mask extension is the string that can be added to the mask such that the list of matching strings does not change.

Returns:
shared mask extension

extendMask

public void extendMask(String extension)
Extends the mask. This operation can only narrow the list of matching strings and is thus faster than setting the mask.

Parameters:
extension - string to append to mask

extendSharedMask

public void extendSharedMask()
Extends the mask by the shared string.