de.dfki.lt.tools.tokenizer.annotate
Interface AnnotatedString

All Superinterfaces:
java.text.CharacterIterator, java.lang.Cloneable
All Known Implementing Classes:
FastAnnotatedString

public interface AnnotatedString
extends java.text.CharacterIterator

AnnotatedString is an interface for annotating strings and working on them. It merges the functionality of java.text.AttributedCharacterIterator and java.text.AttributedString. An AnnotatedString allows iteration through both text and related annotation information. An annotation is a key/value pair, identified by the key. No two annotations on a given character can have the same key. A run with respect to an annotation is a maximum text range for which: - the annotation is undefined or null for the entire range, or - the annotation value is defined and has the same non-null value for the entire range

Version:
$Id: AnnotatedString.java,v 1.4 2005/04/12 08:47:37 steffen Exp $
Author:
Joerg Steffen, DFKI

Field Summary
 
Fields inherited from interface java.text.CharacterIterator
DONE
 
Method Summary
 void annotate(java.lang.String key, java.lang.Object value, int beginIndex, int endIndex)
          Adds an annotation to a subrange of the string.
 char charAt(int charIndex)
          Returns the character from the specified position without changing the index.
 int findNextAnnotation(java.lang.String key)
          Returns the index of the first character annotated with the given annotation key following the run containing the current character with respect to the given annotation key.
 java.lang.Object getAnnotation(java.lang.String key)
          Returns the annotation value of the string at the current index for a given annotation key.
 int getRunLimit(java.lang.String key)
          Returns the index of the first character following the run with respect to the given annotation key containing the current character.
 int getRunStart(java.lang.String key)
          Returns the index of the first character of the run with respect to the given annotation key containing the current character.
 java.lang.String substring(int beginIndex, int endIndex)
          Returns the substring between the specified indices.
 java.lang.String toString()
          Returns the surface string of the annotated string.
 java.lang.String toString(java.lang.String key)
          Returns a string representation of the annotated string with the annotation for the given attribute key.
 
Methods inherited from interface java.text.CharacterIterator
clone, current, first, getBeginIndex, getEndIndex, getIndex, last, next, previous, setIndex
 

Method Detail

getRunStart

public int getRunStart(java.lang.String key)
Returns the index of the first character of the run with respect to the given annotation key containing the current character.

Parameters:
key - String with an annotation key
Returns:
an int with the index

getRunLimit

public int getRunLimit(java.lang.String key)
Returns the index of the first character following the run with respect to the given annotation key containing the current character.

Parameters:
key - String with an attribute key
Returns:
an int with the index

annotate

public void annotate(java.lang.String key,
                     java.lang.Object value,
                     int beginIndex,
                     int endIndex)
Adds an annotation to a subrange of the string.

Parameters:
key - a String with the annotation key
value - a Object with the annotation value
beginIndex - an int with the index of the first character of the range
endIndex - an int with the index of the character following the last character of the range
Throws:
java.lang.IllegalArgumentException - if beginIndex is less then 0, endIndex is greater than the length of the string, or beginIndex and endIndex together don't define a non-empty subrange of the string

getAnnotation

public java.lang.Object getAnnotation(java.lang.String key)
Returns the annotation value of the string at the current index for a given annotation key.

Parameters:
key - a String with the annotation key
Returns:
an Object with the annotation value or null if there is no annotation with the given key at that position

findNextAnnotation

public int findNextAnnotation(java.lang.String key)
Returns the index of the first character annotated with the given annotation key following the run containing the current character with respect to the given annotation key.

Parameters:
key - a String with the annotation key
Returns:
an int with the index

substring

public java.lang.String substring(int beginIndex,
                                  int endIndex)
Returns the substring between the specified indices.

Parameters:
beginIndex - an int with the index of the first character of the range
endIndex - an int with the index of the character following the last character of the range
Returns:
a String with the substring
Throws:
java.lang.IllegalArgumentException - if beginIndex is less then 0, endIndex is greater than the length of the string, or beginIndex and endIndex together don't define a non-empty subrange of the string

charAt

public char charAt(int charIndex)
Returns the character from the specified position without changing the index.

Parameters:
charIndex - the index within the text; valid values range from getBeginIndex() to getEndIndex(); an IllegalArgumentException is thrown if an invalid value is supplied
Returns:
the character at the specified position or DONE if the specified position is equal to getEndIndex()

toString

public java.lang.String toString(java.lang.String key)
Returns a string representation of the annotated string with the annotation for the given attribute key.

Parameters:
key - String with an attribute key
Returns:
a String

toString

public java.lang.String toString()
Returns the surface string of the annotated string.

Returns:
a String