-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapFactory.java
More file actions
42 lines (33 loc) · 1.09 KB
/
Copy pathMapFactory.java
File metadata and controls
42 lines (33 loc) · 1.09 KB
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
package com.rutgers.util;
import java.util.*;
import java.io.Serializable;
/**
* The MapFactory is a mechanism for specifying what kind of map is to be used
* by some object. For example, if you want a Counter which is backed by an
* IdentityHashMap instead of the defaul HashMap, you can pass in an
* IdentityHashMapFactory.
*/
public abstract class MapFactory<K,V> implements Serializable {
private static final long serialVersionUID = 5724671156522771657L;
public static class HashMapFactory<K,V> extends MapFactory<K,V> {
public Map<K,V> buildMap() {
return new HashMap<K,V>();
}
}
public static class IdentityHashMapFactory<K,V> extends MapFactory<K,V> {
public Map<K,V> buildMap() {
return new IdentityHashMap<K,V>();
}
}
public static class TreeMapFactory<K,V> extends MapFactory<K,V> {
public Map<K,V> buildMap() {
return new TreeMap<K,V>();
}
}
public static class WeakHashMapFactory<K,V> extends MapFactory<K,V> {
public Map<K,V> buildMap() {
return new WeakHashMap<K,V>();
}
}
public abstract Map<K,V> buildMap();
}