1 package com.stateofflow.eclipse.metrics.location;
2
3 public final class NamedLineNumber implements Comparable<NamedLineNumber> {
4 private String name;
5 private int lineNumber;
6
7 public NamedLineNumber(final String name, final int lineNumber) {
8 setName(name);
9 setLineNumber(lineNumber);
10 }
11
12 public int compareTo(final NamedLineNumber that) {
13 final int comparison = name.compareTo(that.name);
14 return comparison != 0 ? comparison : lineNumber - that.lineNumber;
15 }
16
17 @Override
18 public boolean equals(final Object obj) {
19 if (obj == this) {
20 return true;
21 }
22
23 if (obj == null || obj.getClass() != getClass()) {
24 return false;
25 }
26
27 final NamedLineNumber that = (NamedLineNumber) obj;
28 return getLineNumber() == that.getLineNumber() && getName().equals(that.getName());
29 }
30
31 public int getLineNumber() {
32 return lineNumber;
33 }
34
35 public String getName() {
36 return name;
37 }
38
39 @Override
40 public int hashCode() {
41 return getName().hashCode() ^ getLineNumber();
42 }
43
44 private void setLineNumber(final int newLineNumber) {
45 lineNumber = newLineNumber;
46 }
47
48 private void setName(final String newName) {
49 name = newName;
50 }
51
52 @Override
53 public String toString() {
54 return name + ", lineNumber=" + lineNumber;
55 }
56 }