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