1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package de.fu_berlin.ties.util;
23
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.Map;
27 import java.util.TreeMap;
28 import java.util.TreeSet;
29
30 /***
31 * A {@link de.fu_berlin.ties.util.MultiValueMap} that sorts the values
32 * stored for each key, discarding duplicates. For this purpose,
33 * {@link java.util.TreeSet}s are used for inner collections.
34 *
35 * By default, the keys are sorted as well, by wrapping a
36 * {@link java.util.TreeMap}. This can be changed by specifying a different kind
37 * of map to wrap in the constructor.
38 *
39 * @author Christian Siefkes
40 * @version $Revision: 1.1 $, $Date: 2004/11/05 12:16:16 $, $Author: siefkes $
41 */
42 public class SortedMultiValueMap<K, V> extends MultiValueMap<K, V> {
43
44 /***
45 * Creates a new instance, wrapping a {@link TreeMap}.
46 */
47 public SortedMultiValueMap() {
48 this(new TreeMap<K, Collection<V>>());
49 }
50
51 /***
52 * Creates a new instance.
53 *
54 * @param wrappedMap wrapped map used as storage, e.g. a {@link HashMap} or
55 * a {@link java.util.TreeMap}
56 */
57 public SortedMultiValueMap(Map<K, Collection<V>> wrappedMap) {
58 super(wrappedMap);
59 }
60
61 /***
62 * {@inheritDoc}
63 * This implementation returns a {@link TreeSet}.
64 */
65 protected Collection<V> createCollection(
66 final Collection<? extends V> coll) {
67 if (coll == null) {
68 return new TreeSet<V>();
69 } else {
70 return new TreeSet<V>(coll);
71 }
72 }
73
74 }