|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
LocationImpl.java | 83.3% | 96.4% | 100% | 93.9% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.hivemind.impl;
|
|
16 |
|
|
17 |
import org.apache.hivemind.Location;
|
|
18 |
import org.apache.hivemind.Resource;
|
|
19 |
|
|
20 |
/**
|
|
21 |
* Implementation of the {@link org.apache.hivemind.Location} interface.
|
|
22 |
*
|
|
23 |
* @author Howard Lewis Ship
|
|
24 |
*/
|
|
25 |
public final class LocationImpl implements Location |
|
26 |
{ |
|
27 |
private Resource _resource;
|
|
28 |
private int _lineNumber = -1; |
|
29 |
private int _columnNumber = -1; |
|
30 |
|
|
31 | 34515 |
public LocationImpl(Resource resource)
|
32 |
{ |
|
33 | 34515 |
_resource = resource; |
34 |
} |
|
35 |
|
|
36 | 45 |
public LocationImpl(Resource resource, int lineNumber) |
37 |
{ |
|
38 | 45 |
this(resource);
|
39 |
|
|
40 | 45 |
_lineNumber = lineNumber; |
41 |
} |
|
42 |
|
|
43 | 34458 |
public LocationImpl(Resource resource, int lineNumber, int columnNumber) |
44 |
{ |
|
45 | 34458 |
this(resource);
|
46 |
|
|
47 | 34458 |
_lineNumber = lineNumber; |
48 | 34458 |
_columnNumber = columnNumber; |
49 |
} |
|
50 |
|
|
51 | 30 |
public Resource getResource()
|
52 |
{ |
|
53 | 30 |
return _resource;
|
54 |
} |
|
55 |
|
|
56 | 26 |
public int getLineNumber() |
57 |
{ |
|
58 | 26 |
return _lineNumber;
|
59 |
} |
|
60 |
|
|
61 | 20 |
public int getColumnNumber() |
62 |
{ |
|
63 | 20 |
return _columnNumber;
|
64 |
} |
|
65 |
|
|
66 | 6 |
public int hashCode() |
67 |
{ |
|
68 | 6 |
return ((237 + _resource.hashCode()) << 3 + _lineNumber) << 3 + _columnNumber;
|
69 |
} |
|
70 |
|
|
71 | 23 |
public boolean equals(Object other) |
72 |
{ |
|
73 | 23 |
if (!(other instanceof Location)) |
74 | 0 |
return false; |
75 |
|
|
76 | 23 |
Location l = (Location) other; |
77 |
|
|
78 | 23 |
if (_lineNumber != l.getLineNumber())
|
79 | 5 |
return false; |
80 |
|
|
81 | 18 |
if (_columnNumber != l.getColumnNumber())
|
82 | 2 |
return false; |
83 |
|
|
84 | 16 |
return _resource.equals(l.getResource());
|
85 |
} |
|
86 |
|
|
87 | 64 |
public String toString()
|
88 |
{ |
|
89 | 64 |
if (_lineNumber <= 0 && _columnNumber <= 0)
|
90 | 7 |
return _resource.toString();
|
91 |
|
|
92 | 57 |
StringBuffer buffer = new StringBuffer(_resource.toString());
|
93 |
|
|
94 | 57 |
if (_lineNumber > 0)
|
95 |
{ |
|
96 | 57 |
buffer.append(", line ");
|
97 | 57 |
buffer.append(_lineNumber); |
98 |
} |
|
99 |
|
|
100 | 57 |
if (_columnNumber > 0)
|
101 |
{ |
|
102 | 39 |
buffer.append(", column ");
|
103 | 39 |
buffer.append(_columnNumber); |
104 |
} |
|
105 |
|
|
106 | 57 |
return buffer.toString();
|
107 |
} |
|
108 |
} |
|
109 |
|
|