1 package org.opentrafficsim.kpi.sampling.meta;
2
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.Iterator;
6 import java.util.Map;
7 import java.util.Map.Entry;
8 import java.util.Set;
9
10 import org.djutils.exceptions.Throw;
11 import org.djutils.immutablecollections.ImmutableIterator;
12
13
14
15
16
17
18
19
20
21
22
23
24
25 public class MetaDataSet
26 {
27
28
29 private final Map<MetaDataType<?>, Set<?>> metaDataMap = new HashMap<>();
30
31
32
33
34 public MetaDataSet()
35 {
36
37 }
38
39
40
41
42 public MetaDataSet(final MetaDataSet metaDataSet)
43 {
44 Throw.whenNull(metaDataSet, "Meta data set may not be null.");
45 for (MetaDataType<?> metaDataType : metaDataSet.metaDataMap.keySet())
46 {
47 this.metaDataMap.put(metaDataType, metaDataSet.metaDataMap.get(metaDataType));
48 }
49 }
50
51
52
53
54
55
56 public final <T> void put(final MetaDataType<T> metaDataType, final Set<T> values)
57 {
58 Throw.whenNull(metaDataType, "Meta data type may not be null.");
59 Throw.whenNull(values, "Values may not be null.");
60 this.metaDataMap.put(metaDataType, values);
61 }
62
63
64
65
66
67 public final boolean contains(final MetaDataType<?> metaDataType)
68 {
69 return this.metaDataMap.containsKey(metaDataType);
70 }
71
72
73
74
75
76
77 @SuppressWarnings("unchecked")
78 public final <T> Set<T> get(final MetaDataType<T> metaDataType)
79 {
80 return (Set<T>) this.metaDataMap.get(metaDataType);
81 }
82
83
84
85
86 public final Set<MetaDataType<?>> getMetaDataTypes()
87 {
88 return new HashSet<>(this.metaDataMap.keySet());
89 }
90
91
92
93
94 public final int size()
95 {
96 return this.metaDataMap.size();
97 }
98
99
100
101
102 public final Iterator<Entry<MetaDataType<?>, Set<?>>> getMetaDataSetIterator()
103 {
104 return new ImmutableIterator<>(this.metaDataMap.entrySet().iterator());
105 }
106
107
108 @Override
109 public final int hashCode()
110 {
111 final int prime = 31;
112 int result = 1;
113 result = prime * result + ((this.metaDataMap == null) ? 0 : this.metaDataMap.hashCode());
114 return result;
115 }
116
117
118 @Override
119 public final boolean equals(final Object obj)
120 {
121 if (this == obj)
122 {
123 return true;
124 }
125 if (obj == null)
126 {
127 return false;
128 }
129 if (getClass() != obj.getClass())
130 {
131 return false;
132 }
133 MetaDataSet other = (MetaDataSet) obj;
134 if (this.metaDataMap == null)
135 {
136 if (other.metaDataMap != null)
137 {
138 return false;
139 }
140 }
141 else if (!this.metaDataMap.equals(other.metaDataMap))
142 {
143 return false;
144 }
145 return true;
146 }
147
148
149 @Override
150 public final String toString()
151 {
152 return "MetaDataSet [metaDataMap=" + this.metaDataMap + "]";
153 }
154
155 }