1 15 package org.apache.hivemind.impl; 16 17 import org.apache.hivemind.Location; 18 import org.apache.hivemind.Resource; 19 20 26 public final class LocationImpl implements Location 27 { 28 private Resource _resource; 29 private int _lineNumber = -1; 30 private int _columnNumber = -1; 31 32 public LocationImpl(Resource resource) 33 { 34 _resource = resource; 35 } 36 37 public LocationImpl(Resource resource, int lineNumber) 38 { 39 this(resource); 40 41 _lineNumber = lineNumber; 42 } 43 44 public LocationImpl(Resource resource, int lineNumber, int columnNumber) 45 { 46 this(resource); 47 48 _lineNumber = lineNumber; 49 _columnNumber = columnNumber; 50 } 51 52 public Resource getResource() 53 { 54 return _resource; 55 } 56 57 public int getLineNumber() 58 { 59 return _lineNumber; 60 } 61 62 public int getColumnNumber() 63 { 64 return _columnNumber; 65 } 66 67 public int hashCode() 68 { 69 return ((237 + _resource.hashCode()) << 3 + _lineNumber) << 3 + _columnNumber; 70 } 71 72 public boolean equals(Object other) 73 { 74 if (!(other instanceof LocationImpl)) 75 return false; 76 77 LocationImpl l = (LocationImpl) other; 78 79 if (_lineNumber != l.getLineNumber()) 80 return false; 81 82 if (_columnNumber != l.getColumnNumber()) 83 return false; 84 85 return _resource.equals(l.getResource()); 86 } 87 88 93 public String getPosition() 94 { 95 String result = ""; 96 97 if (_lineNumber > 0) 98 { 99 result += "line " + _lineNumber; 100 } 101 102 if (_columnNumber > 0) 103 { 104 if (result.length() > 0) { 105 result += ", "; 106 } 107 result += "column " + _columnNumber; 108 } 109 110 return result; 111 } 112 113 public String toString() 114 { 115 StringBuffer buffer = new StringBuffer (_resource.toString()); 116 String position = getPosition(); 117 if (position.length() > 0) { 118 buffer.append(", "); 119 buffer.append(position); 120 } 121 122 return buffer.toString(); 123 } 124 125 } 126 | Popular Tags |