/[projects]/dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/util/DeduplicateHelper.java
ViewVC logotype

Contents of /dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/util/DeduplicateHelper.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2838 - (show annotations) (download)
Sun Jan 24 21:48:55 2016 UTC (8 years, 4 months ago) by torben
File size: 651 byte(s)
Add first working edition
1 package dk.daoas.adressevedligehold.util;
2
3 import java.util.HashMap;
4
5 public class DeduplicateHelper<T> {
6 private HashMap<T,T> cache;
7
8 public DeduplicateHelper() {
9 cache = new HashMap<T,T>();
10 }
11
12 public DeduplicateHelper(int initialCapacity) {
13 cache = new HashMap<T,T>(initialCapacity);
14 }
15
16
17
18 public T getInstance(T newT) {
19 if (newT == null) {
20 return null;
21 }
22
23 T cachedT = cache.get(newT);
24 if ( cachedT == null ) {
25 cachedT = newT;
26 cache.put(newT, newT);
27 }
28 return cachedT;
29 }
30
31 public int size() {
32 return cache.size();
33 }
34
35 public void clear() {
36 cache.clear();
37 }
38
39 }

  ViewVC Help
Powered by ViewVC 1.1.20