1 33 34 package edu.rice.cs.drjava.model; 35 36 import java.io.File ; 37 import java.lang.ref.WeakReference ; 38 import javax.swing.text.Position ; 39 40 44 public class MovingDocumentRegion implements DocumentRegion { 45 protected final OpenDefinitionsDocument _doc; 46 protected final File _file; 47 protected final Position _startPosition; 48 protected final Position _endPosition; 49 protected final String _string; 50 51 52 public MovingDocumentRegion(OpenDefinitionsDocument doc, File file, Position sp, Position ep, String s) { 53 _doc = doc; 54 _file = file; 55 _startPosition = sp; 56 _endPosition = ep; 57 _string = s; 58 } 59 60 61 public OpenDefinitionsDocument getDocument() { return _doc; } 62 63 64 public File getFile() { return _file; } 65 66 67 public int getStartOffset() { 68 return 69 (_doc == null || _doc.getLength() >= _startPosition.getOffset()) ? _startPosition.getOffset() : _doc.getLength(); 70 } 71 72 73 public int getEndOffset() { 74 return (_doc == null || _doc.getLength() >= _endPosition.getOffset()) ? _endPosition.getOffset() : _doc.getLength(); 75 } 76 77 78 public String getString() { 79 return _string; 80 } 81 82 83 public boolean equals(Object other) { 84 if ((other == null) || ! (other instanceof MovingDocumentRegion)) return false; 85 MovingDocumentRegion o = (MovingDocumentRegion)other; 86 return (((_doc == null && o._doc == null) || _doc.equals(o._doc)) && 87 ((_file == null && o._file == null) || _file.equals(o._file)) && 88 _startPosition.getOffset() == o._startPosition.getOffset() && 89 _endPosition.getOffset() == o._endPosition.getOffset() && 90 _string.equals(o._string)); 91 } 92 93 public String toString() { 94 return 95 (_doc != null ? _doc.toString() : "null") + " " + _startPosition.getOffset() + " .. " + _endPosition.getOffset(); 96 } 97 } 98 | Popular Tags |