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
.NonNull
;
21 import org
.eclipse
.jdt
.annotation
.Nullable
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
26 * Event aspect representing a single field of an event's content.
28 * @author Alexandre Montplaisir
30 public class TmfContentFieldAspect
implements ITmfEventAspect
{
32 private final String fAspectName
;
33 private final String
[] fFieldPath
;
34 private final String fHelpText
;
40 * The name of the aspect. Should be localized.
42 * The field name or absolute field path array to look for in the
43 * event content. Should *not* be localized!
45 public TmfContentFieldAspect(String aspectName
, @NonNull String
... fieldPath
) {
46 this(aspectName
, EMPTY_STRING
, fieldPath
);
49 private TmfContentFieldAspect(String aspectName
, String helpText
, @NonNull String
... fieldPath
) {
50 fAspectName
= aspectName
;
51 fFieldPath
= checkNotNull(Arrays
.copyOf(fieldPath
, fieldPath
.length
));
56 * Creates a new instance of this aspect with the specified name, help text,
60 * The name of the aspect. Should be localized.
64 * The field name or absolute field path array to look for in the
65 * event content. Should *not* be localized!
66 * @return the new aspect
69 public static TmfContentFieldAspect
create(String aspectName
, String helpText
, @NonNull String
... fieldPath
) {
70 return new TmfContentFieldAspect(aspectName
, helpText
, fieldPath
);
74 public String
getName() {
79 public String
getHelpText() {
84 public @Nullable Object
resolve(ITmfEvent event
) {
85 ITmfEventField field
= event
.getContent().getField(fFieldPath
);
89 return field
.getValue();
92 // ------------------------------------------------------------------------
94 // Typically we want identical field aspects to be merged together.
95 // ------------------------------------------------------------------------
98 public int hashCode() {
101 result
= prime
* result
+ fAspectName
.hashCode();
102 result
= prime
* result
+ Arrays
.hashCode(fFieldPath
);
103 result
= prime
* result
+ fHelpText
.hashCode();
108 public boolean equals(@Nullable Object obj
) {
115 if (!this.getClass().equals(obj
.getClass())) {
118 TmfContentFieldAspect other
= (TmfContentFieldAspect
) obj
;
119 if (!fAspectName
.equals(other
.fAspectName
)) {
122 if (!Arrays
.equals(fFieldPath
, other
.fFieldPath
)) {
125 if (!fHelpText
.equals(other
.fHelpText
)) {