1 52 53 package com.go.trove.classfile; 54 55 61 class LocationRangeImpl implements LocationRange { 62 private final Location mStart; 63 private final Location mEnd; 64 65 LocationRangeImpl(Location a, Location b) { 66 if (a.compareTo(b) <= 0) { 67 mStart = a; 68 mEnd = b; 69 } 70 else { 71 mStart = b; 72 mEnd = a; 73 } 74 } 75 76 LocationRangeImpl(LocationRange a, LocationRange b) { 77 mStart = (a.getStartLocation().compareTo(b.getStartLocation()) <= 0) ? 78 a.getStartLocation() : b.getStartLocation(); 79 80 mEnd = (b.getEndLocation().compareTo(a.getEndLocation()) >= 0) ? 81 b.getEndLocation() : a.getEndLocation(); 82 } 83 84 public Location getStartLocation() { 85 return mStart; 86 } 87 88 public Location getEndLocation() { 89 return mEnd; 90 } 91 92 public boolean equals(Object obj) { 93 return compareTo(obj) == 0; 94 } 95 96 public int compareTo(Object obj) { 97 if (this == obj) { 98 return 0; 99 } 100 101 LocationRange other = (LocationRange)obj; 102 103 int result = getStartLocation().compareTo(other.getStartLocation()); 104 105 if (result == 0) { 106 result = getEndLocation().compareTo(other.getEndLocation()); 107 } 108 109 return result; 110 } 111 112 public String toString() { 113 int start = getStartLocation().getLocation(); 114 int end = getEndLocation().getLocation() - 1; 115 116 if (start == end) { 117 return String.valueOf(start); 118 } 119 else { 120 return start + ".." + end; 121 } 122 } 123 } 124 | Popular Tags |