edu.rice.cs.drjava.model
Class DocumentRegion

java.lang.Object
  extended by edu.rice.cs.drjava.model.DocumentRegion
All Implemented Interfaces:
IDocumentRegion, OrderedDocumentRegion, Region, Comparable<OrderedDocumentRegion>
Direct Known Subclasses:
MovingDocumentRegion

public class DocumentRegion
extends Object
implements OrderedDocumentRegion

Class for a simple document region that only records region offsets, not positions. Instances of this class represent dummy regions used in searching SortSets of DocumentRegions. Hence, getLineStart() and getLineEnd() should never be called. WARNING: this class overrides the equals method but does not override the hashCode method to maintain consistency. Hence, instances can only be used as keys in identity based hash tables. NOTE: since class instances are mutable, a hashCode method consistent with equals WOULD NOT WORK anyway.

Version:
$Id$

Field Summary
protected  OpenDefinitionsDocument _doc
           
protected  int _end
           
protected  int _start
           
 
Constructor Summary
DocumentRegion(OpenDefinitionsDocument doc, int start, int end)
          Create a new simple document region with a bona fide document
 
Method Summary
 int compareTo(OrderedDocumentRegion r)
          Totally orders regions lexicographically based on (_doc, endOffset, startOffset).
 boolean equals(Object o)
          Defines the equality relation on DocumentRegions.
 OpenDefinitionsDocument getDocument()
           
 int getEndOffset()
           
 int getLineEndOffset()
          Throws exception indicating that getLineEnd() is not supported.
 int getLineStartOffset()
          Throws exception indicating that getLineStart() is not supported.
 int getStartOffset()
           
 String getString()
          Throws exception indicating that getString() is not supported.
 boolean isEmpty()
           
 String toString()
           
 void update()
          Throws exception indicating that getString() is not supported.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_doc

protected final OpenDefinitionsDocument _doc

_start

protected volatile int _start

_end

protected volatile int _end
Constructor Detail

DocumentRegion

public DocumentRegion(OpenDefinitionsDocument doc,
                      int start,
                      int end)
Create a new simple document region with a bona fide document

Method Detail

equals

public final boolean equals(Object o)
Defines the equality relation on DocumentRegions. This equivalence relation is consistent with the equivalence relation induced by the compareTo method.

Overrides:
equals in class Object

compareTo

public int compareTo(OrderedDocumentRegion r)
Totally orders regions lexicographically based on (_doc, endOffset, startOffset). This method is typically applied to regions within the same document.

Specified by:
compareTo in interface Comparable<OrderedDocumentRegion>

getDocument

public OpenDefinitionsDocument getDocument()
Specified by:
getDocument in interface IDocumentRegion
Returns:
the document, or null if it hasn't been established yet

getStartOffset

public int getStartOffset()
Specified by:
getStartOffset in interface Region
Returns:
the start offset

getEndOffset

public int getEndOffset()
Specified by:
getEndOffset in interface Region
Returns:
the end offset

getLineStartOffset

public int getLineStartOffset()
Throws exception indicating that getLineStart() is not supported.

Specified by:
getLineStartOffset in interface OrderedDocumentRegion

getLineEndOffset

public int getLineEndOffset()
Throws exception indicating that getLineEnd() is not supported.

Specified by:
getLineEndOffset in interface OrderedDocumentRegion

getString

public String getString()
Throws exception indicating that getString() is not supported.

Specified by:
getString in interface OrderedDocumentRegion

update

public void update()
Throws exception indicating that getString() is not supported.

Specified by:
update in interface OrderedDocumentRegion

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface OrderedDocumentRegion

toString

public String toString()
Overrides:
toString in class Object