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