132
|
1 /*
|
|
2 File: Map.d
|
|
3
|
|
4 Originally written by Doug Lea and released into the public domain.
|
|
5 Thanks for the assistance and support of Sun Microsystems Labs, Agorics
|
|
6 Inc, Loral, and everyone contributing, testing, and using this code.
|
|
7
|
|
8 History:
|
|
9 Date Who What
|
|
10 24Sep95 dl@cs.oswego.edu Create from collections.d working file
|
|
11
|
|
12 */
|
|
13
|
|
14
|
|
15 module tango.util.collection.model.Map;
|
|
16
|
|
17 private import tango.util.collection.model.MapView,
|
|
18 tango.util.collection.model.Dispenser;
|
|
19
|
|
20
|
|
21 /**
|
|
22 *
|
|
23 *
|
|
24 * MutableMap supports standard update operations on maps.
|
|
25 *
|
|
26 *
|
|
27 author: Doug Lea
|
|
28 * @version 0.93
|
|
29 *
|
|
30 * <P> For an introduction to this package see <A HREF="index.html"> Overview </A>.
|
|
31 **/
|
|
32
|
|
33
|
|
34 public interface Map(K, T) : MapView!(K, T), Dispenser!(T)
|
|
35 {
|
|
36 /**
|
|
37 * Include the indicated pair in the Map
|
|
38 * If a different pair
|
|
39 * with the same key was previously held, it is replaced by the
|
|
40 * new pair.
|
|
41 *
|
|
42 * @param key the key for element to include
|
|
43 * @param element the element to include
|
|
44 * Returns: condition:
|
|
45 * <PRE>
|
|
46 * has(key, element) &&
|
|
47 * no spurious effects &&
|
|
48 * Version change iff !PREV(this).contains(key, element))
|
|
49 * </PRE>
|
|
50 **/
|
|
51
|
|
52 public void add (K key, T element);
|
|
53
|
|
54 /**
|
|
55 * Include the indicated pair in the Map
|
|
56 * If a different pair
|
|
57 * with the same key was previously held, it is replaced by the
|
|
58 * new pair.
|
|
59 *
|
|
60 * @param element the element to include
|
|
61 * @param key the key for element to include
|
|
62 * Returns: condition:
|
|
63 * <PRE>
|
|
64 * has(key, element) &&
|
|
65 * no spurious effects &&
|
|
66 * Version change iff !PREV(this).contains(key, element))
|
|
67 * </PRE>
|
|
68 **/
|
|
69
|
|
70 public void opIndexAssign (T element, K key);
|
|
71
|
|
72
|
|
73 /**
|
|
74 * Remove the pair with the given key
|
|
75 * @param key the key
|
|
76 * Returns: condition:
|
|
77 * <PRE>
|
|
78 * !containsKey(key)
|
|
79 * foreach (k in keys()) at(k).equals(PREV(this).at(k)) &&
|
|
80 * foreach (k in PREV(this).keys()) (!k.equals(key)) --> at(k).equals(PREV(this).at(k))
|
|
81 * (version() != PREV(this).version()) ==
|
|
82 * containsKey(key) != PREV(this).containsKey(key))
|
|
83 * </PRE>
|
|
84 **/
|
|
85
|
|
86 public void removeKey (K key);
|
|
87
|
|
88
|
|
89 /**
|
|
90 * Replace old pair with new pair with same key.
|
|
91 * No effect if pair not held. (This has the case of
|
|
92 * having no effect if the key exists but is bound to a different value.)
|
|
93 * @param key the key for the pair to remove
|
|
94 * @param oldElement the existing element
|
|
95 * @param newElement the value to replace it with
|
|
96 * Returns: condition:
|
|
97 * <PRE>
|
|
98 * !contains(key, oldElement) || contains(key, newElement);
|
|
99 * no spurious effects &&
|
|
100 * Version change iff PREV(this).contains(key, oldElement))
|
|
101 * </PRE>
|
|
102 **/
|
|
103
|
|
104 public void replacePair (K key, T oldElement, T newElement);
|
|
105 }
|
|
106
|