Copyright header update, 2015 edition
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / event / aspect / TmfEventFieldAspect.java
1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 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 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.core.event.aspect;
14
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
17 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
18
19 /**
20 * Event aspect representing a single field of an event.
21 *
22 * @author Alexandre Montplaisir
23 */
24 public class TmfEventFieldAspect implements ITmfEventAspect {
25
26 private final String fAspectName;
27 private final String fFieldName;
28
29 /**
30 * Constructor
31 *
32 * @param aspectName
33 * The name of the aspect. Should be localized.
34 * @param fieldName
35 * The name of the field to look for in the trace. Should *not*
36 * be localized!
37 */
38 public TmfEventFieldAspect(String aspectName, String fieldName) {
39 fAspectName = aspectName;
40 fFieldName = fieldName;
41 }
42
43 @Override
44 public String getName() {
45 return fAspectName;
46 }
47
48 @Override
49 public String getHelpText() {
50 return EMPTY_STRING;
51 }
52
53 @Override
54 public @Nullable String resolve(ITmfEvent event) {
55 ITmfEventField field = event.getContent().getField(fFieldName);
56 if (field == null) {
57 return null;
58 }
59 return field.getFormattedValue();
60 }
61
62 // ------------------------------------------------------------------------
63 // hashCode/equals
64 // Typically we want identical field aspects to be merged together.
65 // ------------------------------------------------------------------------
66
67 @Override
68 public int hashCode() {
69 final int prime = 31;
70 int result = 1;
71 result = prime * result + fAspectName.hashCode();
72 result = prime * result + fFieldName.hashCode();
73 return result;
74 }
75
76 @Override
77 public boolean equals(@Nullable Object obj) {
78 if (this == obj) {
79 return true;
80 }
81 if (!(obj instanceof TmfEventFieldAspect)) {
82 return false;
83 }
84 TmfEventFieldAspect other = (TmfEventFieldAspect) obj;
85 if (!fAspectName.equals(other.fAspectName)) {
86 return false;
87 }
88 if (!fFieldName.equals(other.fFieldName)) {
89 return false;
90 }
91 return true;
92 }
93 }
This page took 0.032806 seconds and 5 git commands to generate.