1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 Ericsson
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
10 * Alexandre Montplaisir - Initial API and implementation
11 * Patrick Tasse - Renamed from TmfEventFieldAspect and support subfield array
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
;
16 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
18 import java
.util
.Arrays
;
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
;
25 * Event aspect representing a single field of an event's content.
27 * @author Alexandre Montplaisir
29 public class TmfContentFieldAspect
implements ITmfEventAspect
{
31 private final String fAspectName
;
32 private final String
[] fFieldPath
;
33 private final String fHelpText
;
39 * The name of the aspect. Should be localized.
41 * The field name or absolute field path array to look for in the
42 * event content. Should *not* be localized!
44 public TmfContentFieldAspect(String aspectName
, String
... fieldPath
) {
45 this(aspectName
, EMPTY_STRING
, fieldPath
);
48 private TmfContentFieldAspect(String aspectName
, String helpText
, String
... fieldPath
) {
49 fAspectName
= aspectName
;
50 fFieldPath
= checkNotNull(Arrays
.copyOf(fieldPath
, fieldPath
.length
));
55 * Creates a new instance of this aspect with the specified name, help text,
59 * The name of the aspect. Should be localized.
63 * The field name or absolute field path array to look for in the
64 * event content. Should *not* be localized!
65 * @return the new aspect
68 public static TmfContentFieldAspect
create(String aspectName
, String helpText
, String
... fieldPath
) {
69 return new TmfContentFieldAspect(aspectName
, helpText
, fieldPath
);
73 public String
getName() {
78 public String
getHelpText() {
83 public @Nullable Object
resolve(ITmfEvent event
) {
84 ITmfEventField field
= event
.getContent().getField(fFieldPath
);
88 return field
.getValue();
91 // ------------------------------------------------------------------------
93 // Typically we want identical field aspects to be merged together.
94 // ------------------------------------------------------------------------
97 public int hashCode() {
100 result
= prime
* result
+ fAspectName
.hashCode();
101 result
= prime
* result
+ Arrays
.hashCode(fFieldPath
);
102 result
= prime
* result
+ fHelpText
.hashCode();
107 public boolean equals(@Nullable Object obj
) {
114 if (!this.getClass().equals(obj
.getClass())) {
117 TmfContentFieldAspect other
= (TmfContentFieldAspect
) obj
;
118 if (!fAspectName
.equals(other
.fAspectName
)) {
121 if (!Arrays
.equals(fFieldPath
, other
.fFieldPath
)) {
124 if (!fHelpText
.equals(other
.fHelpText
)) {