/
Dataset.java
104 lines (86 loc) · 2.39 KB
/
Dataset.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Contributor(s): Contributors are attributed in the source code
* where applicable.
*
* The Original Code is "Stamdata".
*
* The Initial Developer of the Original Code is Trifork Public A/S.
*
* Portions created for the Original Code are Copyright 2011,
* Lægemiddelstyrelsen. All Rights Reserved.
*
* Portions created for the FMKi Project are Copyright 2011,
* National Board of e-Health (NSI). All Rights Reserved.
*/
package com.trifork.stamdata.importer.persistence;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.trifork.stamdata.Entities;
import com.trifork.stamdata.models.TemporalEntity;
/**
* @author Rune Skou Larsen <rsj@trifork.com>
*/
@Deprecated
public class Dataset<T extends TemporalEntity>
{
private static final Logger logger = LoggerFactory.getLogger(Dataset.class);
private final Map<Object, T> entities = new HashMap<Object, T>();
private final Class<T> type;
public Dataset(Class<T> type)
{
this.type = type;
}
public Dataset(List<T> records, Class<T> type)
{
this(type);
for (T record : records)
{
add(record);
}
}
public int size()
{
return getEntities().size();
}
public Collection<T> getEntities()
{
return entities.values();
}
public T getEntityById(Object id)
{
return entities.get(id);
}
public boolean containsKey(Object id)
{
return entities.containsKey(id);
}
public Class<T> getType()
{
return type;
}
public void add(T entity)
{
Object id = Entities.getEntityID(entity);
Object previousValue = entities.put(id, entity);
if (previousValue != null)
{
// FIXME: This is actually and error, but it has always been this way.
// Double keys should not happen.
logger.warn("Two entries in a single import contains the same id. type={}, id={}", type.getSimpleName(), id);
}
}
}