tmf: Use TmfFilterMatchesAspectNode's in the event table
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / event / aspect / TmfEventFieldAspect.java
1 /*******************************************************************************
2 * Copyright (c) 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 * 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 String resolve(ITmfEvent event) {
55 ITmfEventField field = event.getContent().getField(fFieldName);
56 if (field == null) {
57 return EMPTY_STRING;
58 }
59 String fieldValue = field.getFormattedValue();
60 return (fieldValue == null ? EMPTY_STRING : fieldValue);
61 }
62
63 // ------------------------------------------------------------------------
64 // hashCode/equals
65 // Typically we want identical field aspects to be merged together.
66 // ------------------------------------------------------------------------
67
68 @Override
69 public int hashCode() {
70 final int prime = 31;
71 int result = 1;
72 result = prime * result + fAspectName.hashCode();
73 result = prime * result + fFieldName.hashCode();
74 return result;
75 }
76
77 @Override
78 public boolean equals(@Nullable Object obj) {
79 if (this == obj) {
80 return true;
81 }
82 if (!(obj instanceof TmfEventFieldAspect)) {
83 return false;
84 }
85 TmfEventFieldAspect other = (TmfEventFieldAspect) obj;
86 if (!fAspectName.equals(other.fAspectName)) {
87 return false;
88 }
89 if (!fFieldName.equals(other.fFieldName)) {
90 return false;
91 }
92 return true;
93 }
94 }
This page took 0.035053 seconds and 6 git commands to generate.