tmf: Make TmfEventFieldAspect independent of event content
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / event / aspect / TmfContentFieldAspect.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 * Patrick Tasse - Renamed from TmfEventFieldAspect and support subfield array
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.tmf.core.event.aspect;
15
16 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
17
18 import java.util.Arrays;
19
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
22 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
23
24 /**
25 * Event aspect representing a single field of an event's content.
26 *
27 * @author Alexandre Montplaisir
28 */
29 public class TmfContentFieldAspect implements ITmfEventAspect {
30
31 private final String fAspectName;
32 private final String[] fFieldPath;
33
34 /**
35 * Constructor
36 *
37 * @param aspectName
38 * The name of the aspect. Should be localized.
39 * @param fieldPath
40 * The field name or absolute field path array to look for in the
41 * event content. Should *not* be localized!
42 */
43 public TmfContentFieldAspect(String aspectName, String... fieldPath) {
44 fAspectName = aspectName;
45 fFieldPath = checkNotNull(Arrays.copyOf(fieldPath, fieldPath.length));
46 }
47
48 @Override
49 public String getName() {
50 return fAspectName;
51 }
52
53 @Override
54 public String getHelpText() {
55 return EMPTY_STRING;
56 }
57
58 @Override
59 public @Nullable Object resolve(ITmfEvent event) {
60 ITmfEventField field = event.getContent().getField(fFieldPath);
61 if (field == null) {
62 return null;
63 }
64 return field.getValue();
65 }
66
67 // ------------------------------------------------------------------------
68 // hashCode/equals
69 // Typically we want identical field aspects to be merged together.
70 // ------------------------------------------------------------------------
71
72 @Override
73 public int hashCode() {
74 final int prime = 31;
75 int result = 1;
76 result = prime * result + fAspectName.hashCode();
77 result = prime * result + Arrays.hashCode(fFieldPath);
78 return result;
79 }
80
81 @Override
82 public boolean equals(@Nullable Object obj) {
83 if (this == obj) {
84 return true;
85 }
86 if (obj == null) {
87 return false;
88 }
89 if (!this.getClass().equals(obj.getClass())) {
90 return false;
91 }
92 TmfContentFieldAspect other = (TmfContentFieldAspect) obj;
93 if (!fAspectName.equals(other.fAspectName)) {
94 return false;
95 }
96 if (!Arrays.equals(fFieldPath, other.fFieldPath)) {
97 return false;
98 }
99 return true;
100 }
101 }
This page took 0.032962 seconds and 5 git commands to generate.