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
;
38 * The name of the aspect. Should be localized.
40 * The field name or absolute field path array to look for in the
41 * event content. Should *not* be localized!
43 public TmfContentFieldAspect(String aspectName
, String
... fieldPath
) {
44 fAspectName
= aspectName
;
45 fFieldPath
= checkNotNull(Arrays
.copyOf(fieldPath
, fieldPath
.length
));
49 public String
getName() {
54 public String
getHelpText() {
59 public @Nullable Object
resolve(ITmfEvent event
) {
60 ITmfEventField field
= event
.getContent().getField(fFieldPath
);
64 return field
.getValue();
67 // ------------------------------------------------------------------------
69 // Typically we want identical field aspects to be merged together.
70 // ------------------------------------------------------------------------
73 public int hashCode() {
76 result
= prime
* result
+ fAspectName
.hashCode();
77 result
= prime
* result
+ Arrays
.hashCode(fFieldPath
);
82 public boolean equals(@Nullable Object obj
) {
89 if (!this.getClass().equals(obj
.getClass())) {
92 TmfContentFieldAspect other
= (TmfContentFieldAspect
) obj
;
93 if (!fAspectName
.equals(other
.fAspectName
)) {
96 if (!Arrays
.equals(fFieldPath
, other
.fFieldPath
)) {