Commit | Line | Data |
---|---|---|
bcb8c2cb PT |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012, 2014 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made 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 | * Patrick Tasse - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.core.trace.text; |
bcb8c2cb PT |
14 | |
15 | import java.util.regex.Matcher; | |
16 | ||
2bdf0193 AM |
17 | import org.eclipse.tracecompass.tmf.core.trace.TmfContext; |
18 | import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation; | |
bcb8c2cb PT |
19 | |
20 | /** | |
21 | * Implementation of a TmfContext for text traces. | |
bcb8c2cb PT |
22 | */ |
23 | public class TextTraceContext extends TmfContext { | |
24 | ||
25 | /** The Matcher object for the first line. */ | |
26 | public Matcher firstLineMatcher; | |
27 | /** The first line string */ | |
28 | public String firstLine; | |
29 | /** The location of the next line */ | |
30 | public long nextLineLocation; | |
31 | ||
32 | /** | |
33 | * Constructor | |
34 | * | |
35 | * @param location | |
36 | * Trace location | |
37 | * @param rank | |
38 | * Event rank | |
39 | */ | |
40 | public TextTraceContext(final ITmfLocation location, final long rank) { | |
41 | super(location, rank); | |
42 | } | |
43 | ||
eadf9801 BH |
44 | /** |
45 | * Copy Constructor | |
46 | * | |
47 | * @param other | |
48 | * the other TextTraceContext | |
49 | */ | |
50 | public TextTraceContext(TextTraceContext other) { | |
51 | this(other.getLocation(), other.getRank()); | |
52 | firstLine = other.firstLine; | |
53 | firstLineMatcher = other.firstLineMatcher; | |
54 | nextLineLocation = other.nextLineLocation; | |
55 | } | |
56 | ||
bcb8c2cb PT |
57 | @Override |
58 | public int hashCode() { | |
59 | final int prime = 31; | |
60 | int result = super.hashCode(); | |
61 | result = prime * result + ((firstLine == null) ? 0 : firstLine.hashCode()); | |
62 | result = prime * result + ((firstLineMatcher == null) ? 0 : firstLineMatcher.hashCode()); | |
63 | result = prime * result + (int) (nextLineLocation ^ (nextLineLocation >>> 32)); | |
64 | return result; | |
65 | } | |
66 | ||
67 | @Override | |
68 | public boolean equals(Object obj) { | |
69 | if (this == obj) { | |
70 | return true; | |
71 | } | |
72 | if (!super.equals(obj)) { | |
73 | return false; | |
74 | } | |
75 | if (getClass() != obj.getClass()) { | |
76 | return false; | |
77 | } | |
78 | TextTraceContext other = (TextTraceContext) obj; | |
79 | if (firstLine == null) { | |
80 | if (other.firstLine != null) { | |
81 | return false; | |
82 | } | |
83 | } else if (!firstLine.equals(other.firstLine)) { | |
84 | return false; | |
85 | } | |
86 | if (firstLineMatcher == null) { | |
87 | if (other.firstLineMatcher != null) { | |
88 | return false; | |
89 | } | |
90 | } else if (!firstLineMatcher.equals(other.firstLineMatcher)) { | |
91 | return false; | |
92 | } | |
93 | if (nextLineLocation != other.nextLineLocation) { | |
94 | return false; | |
95 | } | |
96 | return true; | |
97 | } | |
98 | } |