1 19 package org.netbeans.api.gsf; 20 21 22 32 public class OffsetRange { 33 public static final OffsetRange NONE = new OffsetRange(0, 0); 34 private final int start; 35 private final int end; 36 37 38 public OffsetRange(int start, int end) { 39 assert start >= 0; 40 assert end >= start; 41 42 this.start = start; 43 this.end = end; 44 } 45 46 47 public int getStart() { 48 return start; 49 } 50 51 52 public int getEnd() { 53 return end; 54 } 55 56 57 public int getLength() { 58 return end-start; 59 } 60 61 public String toString() { 62 if (this == NONE) { 63 return "OffsetRange[NONE]"; 64 } else { 65 return "OffsetRange[" + start + "," + end + ">"; } 67 } 68 69 public boolean equals(Object o) { 70 if (o == null) { 71 return false; 72 } 73 74 if (getClass() != o.getClass()) { 75 return false; 76 } 77 78 final OffsetRange test = (OffsetRange)o; 79 80 if (this.start != test.start) { 81 return false; 82 } 83 84 if (this.end != test.end) { 85 return false; 86 } 87 88 return true; 89 } 90 91 public int hashCode() { 92 int hash = 7; 93 94 hash = (23 * hash) + this.start; 95 hash = (23 * hash) + this.end; 96 97 return hash; 98 } 99 100 101 public boolean containsInclusive(int offset) { 102 if (this == NONE) { 103 return false; 104 } 105 106 return (offset >= start) && (offset <= end); 107 } 108 } 109 | Popular Tags |