/
AnnotationModel.java
69 lines (62 loc) · 2.18 KB
/
AnnotationModel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**********************************************************************
* Copyright (c) 2019 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.tracecompass.tmf.core.model.annotations;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
/**
* Data provider annotation model
*
* @author Simon Delisle
* @since 8.2
*/
public class AnnotationModel {
private final Map<String, Collection<Annotation>> fAnnotations;
/**
* Constructor
*
* @param annotations
* Map of annotations per category
*/
public AnnotationModel(Map<String, Collection<Annotation>> annotations) {
fAnnotations = annotations;
}
/**
* Annotations for the model
*
* @return Map of annotations per category
*/
public Map<String, Collection<Annotation>> getAnnotations() {
return fAnnotations;
}
/**
* Creates a new aggregated {@link AnnotationModel} from an array of
* {@link AnnotationModel}. Categories will be combined.
*
* @param models
* array of {@link AnnotationModel}
* @return a new aggregated {@link AnnotationModel}
*/
public static AnnotationModel of(AnnotationModel... models) {
Map<String, Collection<Annotation>> annotations = new LinkedHashMap<>();
for (AnnotationModel annotationModel : models) {
if (annotationModel != null) {
for (Entry<String, Collection<Annotation>> annotation: annotationModel.getAnnotations().entrySet()) {
Collection<Annotation> elements = annotations.computeIfAbsent(annotation.getKey(), unused -> new ArrayList<>());
elements.addAll(annotation.getValue());
}
}
}
return new AnnotationModel(annotations);
}
}