1 11 package org.eclipse.jface.text; 12 13 import org.eclipse.core.runtime.Assert; 14 15 16 37 public class Position { 38 39 40 public int offset; 41 42 public int length; 43 44 public boolean isDeleted; 45 46 51 public Position(int offset) { 52 this(offset, 0); 53 } 54 55 61 public Position(int offset, int length) { 62 Assert.isTrue(offset >= 0); 63 Assert.isTrue(length >= 0); 64 this.offset= offset; 65 this.length= length; 66 } 67 68 71 protected Position() { 72 } 73 74 77 public int hashCode() { 78 int deleted= isDeleted ? 0 : 1; 79 return (offset << 24) | (length << 16) | deleted; 80 } 81 82 85 public void delete() { 86 isDeleted= true; 87 } 88 89 94 public void undelete() { 95 isDeleted= false; 96 } 97 98 101 public boolean equals(Object other) { 102 if (other instanceof Position) { 103 Position rp= (Position) other; 104 return (rp.offset == offset) && (rp.length == length); 105 } 106 return super.equals(other); 107 } 108 109 114 public int getLength() { 115 return length; 116 } 117 118 123 public int getOffset() { 124 return offset; 125 } 126 127 134 public boolean includes(int index) { 135 136 if (isDeleted) 137 return false; 138 139 return (this.offset <= index) && (index < this.offset + length); 140 } 141 142 151 public boolean overlapsWith(int rangeOffset, int rangeLength) { 152 153 if (isDeleted) 154 return false; 155 156 int end= rangeOffset + rangeLength; 157 int thisEnd= this.offset + this.length; 158 159 if (rangeLength > 0) { 160 if (this.length > 0) 161 return this.offset < end && rangeOffset < thisEnd; 162 return rangeOffset <= this.offset && this.offset < end; 163 } 164 165 if (this.length > 0) 166 return this.offset <= rangeOffset && rangeOffset < thisEnd; 167 return this.offset == rangeOffset; 168 } 169 170 175 public boolean isDeleted() { 176 return isDeleted; 177 } 178 179 184 public void setLength(int length) { 185 Assert.isTrue(length >= 0); 186 this.length= length; 187 } 188 189 194 public void setOffset(int offset) { 195 Assert.isTrue(offset >= 0); 196 this.offset= offset; 197 } 198 } 199 | Popular Tags |