| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2014, 2016 Ericsson |
| 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 | |
| 13 | package org.eclipse.tracecompass.tmf.core.trace; |
| 14 | |
| 15 | import java.util.Collection; |
| 16 | import java.util.HashSet; |
| 17 | import java.util.Set; |
| 18 | |
| 19 | import org.eclipse.jdt.annotation.NonNull; |
| 20 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventType; |
| 21 | |
| 22 | import com.google.common.collect.HashMultimap; |
| 23 | import com.google.common.collect.Multimap; |
| 24 | |
| 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 |
| 31 | */ |
| 32 | public 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 | */ |
| 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()); |
| 49 | } |
| 50 | return retSet; |
| 51 | } |
| 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 | |
| 78 | } |