1 16 17 package org.cojen.classfile; 18 19 23 public class LocationRangeImpl implements LocationRange { 24 private final Location mStart; 25 private final Location mEnd; 26 27 public LocationRangeImpl(Location a, Location b) { 28 if (a.compareTo(b) <= 0) { 29 mStart = a; 30 mEnd = b; 31 } else { 32 mStart = b; 33 mEnd = a; 34 } 35 } 36 37 public LocationRangeImpl(LocationRange a, LocationRange b) { 38 mStart = (a.getStartLocation().compareTo(b.getStartLocation()) <= 0) ? 39 a.getStartLocation() : b.getStartLocation(); 40 41 mEnd = (b.getEndLocation().compareTo(a.getEndLocation()) >= 0) ? 42 b.getEndLocation() : a.getEndLocation(); 43 } 44 45 public Location getStartLocation() { 46 return mStart; 47 } 48 49 public Location getEndLocation() { 50 return mEnd; 51 } 52 53 public int hashCode() { 54 return getStartLocation().hashCode() * 31 + getEndLocation().hashCode(); 55 } 56 57 public boolean equals(Object obj) { 58 if (this == obj) { 59 return true; 60 } 61 if (obj instanceof LocationRangeImpl) { 62 LocationRangeImpl other = (LocationRangeImpl)obj; 63 return getStartLocation() == other.getStartLocation() && 64 getEndLocation() == other.getEndLocation(); 65 } 66 return false; 67 } 68 69 public String toString() { 70 int start = getStartLocation().getLocation(); 71 int end = getEndLocation().getLocation() - 1; 72 73 if (start == end) { 74 return String.valueOf(start); 75 } else { 76 return start + ".." + end; 77 } 78 } 79 } 80 | Popular Tags |