tmf: add events field analysis requirement class and test
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / trace / TmfEventTypeCollectionHelper.java
CommitLineData
409bea20 1/*******************************************************************************
897eaeb5 2 * Copyright (c) 2014, 2016 Ericsson
409bea20
GB
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made 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 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
2bdf0193 13package org.eclipse.tracecompass.tmf.core.trace;
409bea20 14
897eaeb5 15import java.util.Collection;
409bea20
GB
16import java.util.HashSet;
17import java.util.Set;
18
df2597e0 19import org.eclipse.jdt.annotation.NonNull;
2bdf0193 20import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
409bea20 21
897eaeb5
BH
22import com.google.common.collect.HashMultimap;
23import com.google.common.collect.Multimap;
24
409bea20
GB
25/**
26 * Set Helper for sets of ITmfTraceType
27 *
28 * TODO Remove once Java 8 is used (replace with Streams)
29 *
30 * @author Matthew Khouzam
409bea20
GB
31 */
32public final class TmfEventTypeCollectionHelper {
33
34 private TmfEventTypeCollectionHelper() {
35 }
36
37 /**
38 * Gets the event names from a collection of event types
39 *
40 * @param eventTypes
41 * an iterable collection of ITmfEventTypes
42 * @return a set of the names of these events, if some names are clashing
43 * they will only appear once
44 */
df2597e0
AM
45 public static Set<@NonNull String> getEventNames(Iterable<@NonNull ? extends ITmfEventType> eventTypes) {
46 Set<@NonNull String> retSet = new HashSet<>();
409bea20
GB
47 for (ITmfEventType eventType : eventTypes) {
48 retSet.add(eventType.getName());
49 }
50 return retSet;
51 }
897eaeb5
BH
52
53 /**
54 * Gets a map from event name to a collection of field names from a
55 * collection of event types
56 *
57 * @param eventTypes
58 * an iterable collection of ITmfEventTypes
59 * @return a set of the names of these events, if some event names are
60 * clashing they will only appear once
61 * @since 2.0
62 */
63 public static Multimap<@NonNull String, @NonNull String> getEventFieldNames(Iterable<@NonNull ? extends ITmfEventType> eventTypes) {
64 Multimap<@NonNull String, @NonNull String> retMap = HashMultimap.create();
65 eventTypes.forEach(eventType -> {
66 Collection<String> collection = eventType.getFieldNames();
67 if (collection != null) {
68 collection.forEach(field -> {
69 if (field != null) {
70 retMap.put(eventType.getName(), field);
71 }
72 });
73 }
74 });
75 return retMap;
76 }
77
409bea20 78}
This page took 0.064667 seconds and 5 git commands to generate.