Fix latest batch of null warnings
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / event / aspect / TmfContentFieldAspect.java
CommitLineData
40dfafb3
PT
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
14package org.eclipse.tracecompass.tmf.core.event.aspect;
15
16import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
17
18import java.util.Arrays;
19
367e2932 20import org.eclipse.jdt.annotation.NonNull;
40dfafb3
PT
21import org.eclipse.jdt.annotation.Nullable;
22import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
23import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
24
25/**
26 * Event aspect representing a single field of an event's content.
27 *
28 * @author Alexandre Montplaisir
29 */
30public class TmfContentFieldAspect implements ITmfEventAspect {
31
32 private final String fAspectName;
33 private final String[] fFieldPath;
760d0231 34 private final String fHelpText;
40dfafb3
PT
35
36 /**
37 * Constructor
38 *
39 * @param aspectName
40 * The name of the aspect. Should be localized.
41 * @param fieldPath
42 * The field name or absolute field path array to look for in the
43 * event content. Should *not* be localized!
44 */
367e2932 45 public TmfContentFieldAspect(String aspectName, @NonNull String... fieldPath) {
760d0231
PT
46 this(aspectName, EMPTY_STRING, fieldPath);
47 }
48
367e2932 49 private TmfContentFieldAspect(String aspectName, String helpText, @NonNull String... fieldPath) {
40dfafb3
PT
50 fAspectName = aspectName;
51 fFieldPath = checkNotNull(Arrays.copyOf(fieldPath, fieldPath.length));
760d0231
PT
52 fHelpText = helpText;
53 }
54
55 /**
56 * Creates a new instance of this aspect with the specified name, help text,
57 * and field path.
58 *
59 * @param aspectName
60 * The name of the aspect. Should be localized.
61 * @param helpText
62 * The help text.
63 * @param fieldPath
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
dbc7991d 67 * @since 1.0
760d0231 68 */
367e2932 69 public static TmfContentFieldAspect create(String aspectName, String helpText, @NonNull String... fieldPath) {
760d0231 70 return new TmfContentFieldAspect(aspectName, helpText, fieldPath);
40dfafb3
PT
71 }
72
73 @Override
74 public String getName() {
75 return fAspectName;
76 }
77
78 @Override
79 public String getHelpText() {
760d0231 80 return fHelpText;
40dfafb3
PT
81 }
82
83 @Override
84 public @Nullable Object resolve(ITmfEvent event) {
85 ITmfEventField field = event.getContent().getField(fFieldPath);
86 if (field == null) {
87 return null;
88 }
89 return field.getValue();
90 }
91
92 // ------------------------------------------------------------------------
93 // hashCode/equals
94 // Typically we want identical field aspects to be merged together.
95 // ------------------------------------------------------------------------
96
97 @Override
98 public int hashCode() {
99 final int prime = 31;
100 int result = 1;
101 result = prime * result + fAspectName.hashCode();
102 result = prime * result + Arrays.hashCode(fFieldPath);
760d0231 103 result = prime * result + fHelpText.hashCode();
40dfafb3
PT
104 return result;
105 }
106
107 @Override
108 public boolean equals(@Nullable Object obj) {
109 if (this == obj) {
110 return true;
111 }
112 if (obj == null) {
113 return false;
114 }
115 if (!this.getClass().equals(obj.getClass())) {
116 return false;
117 }
118 TmfContentFieldAspect other = (TmfContentFieldAspect) obj;
119 if (!fAspectName.equals(other.fAspectName)) {
120 return false;
121 }
122 if (!Arrays.equals(fFieldPath, other.fFieldPath)) {
123 return false;
124 }
760d0231
PT
125 if (!fHelpText.equals(other.fHelpText)) {
126 return false;
127 }
40dfafb3
PT
128 return true;
129 }
130}
This page took 0.055735 seconds and 5 git commands to generate.