1 /*******************************************************************************
2 * Copyright (c) 2014, 2016 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.trace
;
15 import java
.util
.Collection
;
16 import java
.util
.HashSet
;
19 import org
.eclipse
.jdt
.annotation
.NonNull
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventType
;
22 import com
.google
.common
.collect
.HashMultimap
;
23 import com
.google
.common
.collect
.Multimap
;
26 * Set Helper for sets of ITmfTraceType
28 * TODO Remove once Java 8 is used (replace with Streams)
30 * @author Matthew Khouzam
32 public final class TmfEventTypeCollectionHelper
{
34 private TmfEventTypeCollectionHelper() {
38 * Gets the event names from a collection of event types
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
45 public static Set
<@NonNull String
> getEventNames(Iterable
<@NonNull ?
extends ITmfEventType
> eventTypes
) {
46 Set
<@NonNull String
> retSet
= new HashSet
<>();
47 for (ITmfEventType eventType
: eventTypes
) {
48 retSet
.add(eventType
.getName());
54 * Gets a map from event name to a collection of field names from a
55 * collection of event types
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
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
-> {
70 retMap
.put(eventType
.getName(), field
);