import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
* @throws IllegalArgumentException
* If 'name' is null, or if 'fields' has duplicate field names.
*/
- public TmfEventField(@NonNull String name, @Nullable Object value, @Nullable ITmfEventField[] fields) {
+ public TmfEventField(@NonNull String name, @Nullable Object value, ITmfEventField @Nullable [] fields) {
fName = name;
fValue = value;
if (fields == null) {
- fFields = checkNotNull(ImmutableMap.<String, ITmfEventField> of());
+ fFields = ImmutableMap.of();
} else {
- /* Java 8 streams will make this even more simple! */
ImmutableMap.Builder<String, ITmfEventField> mapBuilder = new ImmutableMap.Builder<>();
- for (ITmfEventField field : fields) {
- final String curName = field.getName();
- mapBuilder.put(curName, field);
- }
- fFields = checkNotNull(mapBuilder.build());
+ Arrays.stream(fields).forEach(t -> mapBuilder.put(t.getName(), t));
+ fFields = mapBuilder.build();
}
}
@Override
public final Collection<String> getFieldNames() {
- return checkNotNull(fFields.keySet());
+ return fFields.keySet();
}
@Override
public final Collection<ITmfEventField> getFields() {
- return checkNotNull(fFields.values());
+ return fFields.values();
}
@Override
* @param labels the list of labels
* @return the (flat) root list
*/
- public static final ITmfEventField makeRoot(final String[] labels) {
+ public static final @NonNull ITmfEventField makeRoot(final String[] labels) {
final ITmfEventField[] fields = new ITmfEventField[labels.length];
for (int i = 0; i < labels.length; i++) {
String label = checkNotNull(labels[i]);