edu.northwestern.at.wordhoard.model.text
Class TextLocation

java.lang.Object
  extended by edu.northwestern.at.wordhoard.model.text.TextLocation
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public class TextLocation
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

A text location.

A location is a line index plus a character offset within the line.

The line index is -1 if the location is above the first line, or Integer.MAX_VALUE if the location is below the last line.

The character offset is 0 if the location is above the first line or below the last line.

The character offset is -1 if the location is to the left of a line.

The character offset is Integer.MAX_VALUE if the the location is to the right of a line.

For a line of length n, offset 0 is the location preceding the first character of the line (the beginning of the line). Offset n is the location following the last character of the line (the end of the line).

See Also:
Serialized Form

Constructor Summary
TextLocation()
          Creates a new empty location.
TextLocation(int index, int offset)
          Creates a new location.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this location with another location.
 boolean equals(java.lang.Object o)
          Returns true if this location is equal to another location.
 int getIndex()
          Gets the line index.
 int getOffset()
          Gets the character offset in the line.
 boolean isInText()
          Returns true if the location is within the text.
 void setIndex(int index)
          Sets the line index.
 void setOffset(int offset)
          Sets the character offset in the line.
 java.lang.String toString()
          Returns a string representation of the location.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TextLocation

public TextLocation()
Creates a new empty location.


TextLocation

public TextLocation(int index,
                    int offset)
Creates a new location.

Parameters:
index - Line index.
offset - Character offset in line.
Method Detail

getIndex

public int getIndex()
Gets the line index.

Returns:
The line index.

setIndex

public void setIndex(int index)
Sets the line index.

Parameters:
index - Line index.

getOffset

public int getOffset()
Gets the character offset in the line.

Returns:
The character offset in the line.

setOffset

public void setOffset(int offset)
Sets the character offset in the line.

Parameters:
offset - The character offset in the line.

isInText

public boolean isInText()
Returns true if the location is within the text.

The location is "within the text" if neither the line index nor the character offset is -1 or Integer.MAX_VALUE.

Returns:
True if location is within the text.

compareTo

public int compareTo(java.lang.Object o)
Compares this location with another location.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - The other location.
Returns:
A negative integer, zero, or a positive integer as this location is less than, equal to, or greater than the other location.

equals

public boolean equals(java.lang.Object o)
Returns true if this location is equal to another location.

Overrides:
equals in class java.lang.Object
Parameters:
o - The other location.
Returns:
True if this location equals the other location.

toString

public java.lang.String toString()
Returns a string representation of the location.

Overrides:
toString in class java.lang.Object
Returns:
The string representation.