com.cburch.editor.tokens
Class TokenizerEvent<T extends BasicToken>

java.lang.Object
  extended by com.cburch.editor.tokens.TokenizerEvent<T>
Type Parameters:
T - The type of token found in the tokenizer.

public class TokenizerEvent<T extends BasicToken>
extends java.lang.Object

Describes information about a modification to the list of tokens maintained by the tokenizer. As an example of what the event describes, suppose that we had the following tokens.

    a  b  c  d  e  f  g  h
 
If the document were edited to remove d and e the surrounding spaces, we would then have
    a  b  cf  g  h
 
The TokenizerEvent describing this modification would report that there was a modification beginning at index 2 (the index of the first token removed), the list of tokens removed is {c,d,e,f}, and the list of tokens added is {cf}.

The tokenizer tries to be quite conservative in the size of the changes reported; but for each document edit, it will never produce more than one event.

Version:
0.1 2005-05-31
Author:
Carl Burch

Constructor Summary
TokenizerEvent(Tokenizer<T> source, int rangeBegin, java.util.List<T> oldTokens, java.util.List<T> newTokens)
          Constructs a description of a modification to a tokenizer's list of tokens.
 
Method Summary
 int getFromIndex()
          Returns the index of the token list where the modifications begin.
 java.util.List<T> getNewTokens()
          Returns a segment of the list of tokens, all of which were inserted to the list at the given location.
 java.util.List<T> getOldTokens()
          Returns a segment of the list of tokens, all of which were removed from the list.
 Tokenizer<T> getSource()
          Returns the tokenizer that performed the modification.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TokenizerEvent

public TokenizerEvent(Tokenizer<T> source,
                      int rangeBegin,
                      java.util.List<T> oldTokens,
                      java.util.List<T> newTokens)
Constructs a description of a modification to a tokenizer's list of tokens. Note that the two lists may be of different lengths, and quite likely neither will extend to the end of the underlying list.

Parameters:
source - the tokenizer that initiated the event.
rangeBegin - the index within the token list where the replacement began.
oldTokens - the tokens that were previously in the location.
newTokens - the tokens that are now in the location.
Method Detail

getSource

public Tokenizer<T> getSource()
Returns the tokenizer that performed the modification.

Returns:
the initiating tokenizer.

getFromIndex

public int getFromIndex()
Returns the index of the token list where the modifications begin.

Returns:
the starting index for the modifications.

getOldTokens

public java.util.List<T> getOldTokens()
Returns a segment of the list of tokens, all of which were removed from the list.

Returns:
the segment of tokens removed.

getNewTokens

public java.util.List<T> getNewTokens()
Returns a segment of the list of tokens, all of which were inserted to the list at the given location.

Returns:
the segment of tokens inserted