8e81eaa82d589997d2f980362f7eaa96157ec02f
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / event / lookup / TmfCallsite.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.core.event.lookup;
14
15 import java.util.Objects;
16
17 import org.eclipse.jdt.annotation.NonNull;
18
19 /**
20 * TMF call site information for source code lookup.
21 *
22 * @author Bernd Hufmann
23 */
24 public class TmfCallsite implements ITmfCallsite {
25
26 // ------------------------------------------------------------------------
27 // Attributes
28 // ------------------------------------------------------------------------
29
30 /** The file name string. */
31 private final @NonNull String fFileName;
32
33 /** The function name. */
34 private final String fFunctionName;
35
36 /** The line number. */
37 private final long fLineNumber;
38
39 // ------------------------------------------------------------------------
40 // Constructors
41 // ------------------------------------------------------------------------
42
43 /**
44 * Default constructor.
45 *
46 * @param fileName
47 * - a file name
48 * @param functionName
49 * - a function name
50 * @param lineNumber
51 * - a line number
52 */
53 public TmfCallsite(String fileName, String functionName, long lineNumber) {
54 if (fileName == null) {
55 throw new IllegalArgumentException();
56 }
57 fFileName = fileName;
58 fFunctionName = functionName;
59 fLineNumber = lineNumber;
60 }
61
62 /**
63 * Copy Constructor.
64 *
65 * @param other
66 * - An other call site implementation
67 */
68 public TmfCallsite(ITmfCallsite other) {
69 if (other == null) {
70 throw new IllegalArgumentException();
71 }
72 fFileName = other.getFileName();
73 fFunctionName = other.getFunctionName();
74 fLineNumber = other.getLineNumber();
75 }
76
77 // ------------------------------------------------------------------------
78 // Accessors
79 // ------------------------------------------------------------------------
80
81 @Override
82 public @NonNull String getFileName() {
83 return fFileName;
84 }
85
86 @Override
87 public String getFunctionName() {
88 return fFunctionName;
89 }
90
91 @Override
92 public long getLineNumber() {
93 return fLineNumber;
94 }
95
96 // ------------------------------------------------------------------------
97 // Operations
98 // ------------------------------------------------------------------------
99
100 @Override
101 public int hashCode() {
102 final int prime = 31;
103 int result = 1;
104 // fFileName cannot be null!
105 result = prime * result + fFileName.hashCode();
106 result = prime * result + ((fFunctionName == null) ? 0 : fFunctionName.hashCode());
107 result = prime * result + (int) (fLineNumber ^ (fLineNumber >>> 32));
108 return result;
109 }
110
111 @Override
112 public boolean equals(Object obj) {
113 if (this == obj) {
114 return true;
115 }
116 if (obj == null) {
117 return false;
118 }
119 if (getClass() != obj.getClass()) {
120 return false;
121 }
122 TmfCallsite other = (TmfCallsite) obj;
123
124 // fFileName cannot be null!
125 if (!fFileName.equals(other.fFileName)) {
126 return false;
127 }
128
129 if (!Objects.equals(fFunctionName, other.fFunctionName)) {
130 return false;
131 }
132 if (fLineNumber != other.fLineNumber) {
133 return false;
134 }
135 return true;
136 }
137
138 @Override
139 public String toString() {
140 StringBuilder builder = new StringBuilder();
141 builder.append(fFileName).append(':');
142 builder.append(Long.toString(fLineNumber));
143 if (fFunctionName != null) {
144 builder.append(' ');
145 builder.append(fFunctionName).append("()"); //$NON-NLS-1$
146 }
147 return builder.toString();
148 }
149 }
This page took 0.052836 seconds and 4 git commands to generate.