1 module TreeMapDemo;
2 
3 import hunt.collection.HashMap;
4 import hunt.collection.TreeMap;
5 import hunt.collection.Map;
6 import hunt.collection.Iterator;
7 
8 import std.stdio;
9 import std.conv;
10 import std.range;
11 
12 class TreeMapDemo {
13 
14     void testBasicOperation() {
15         /* This is how to declare TreeMap */
16         TreeMap!(int, string) tmap = new TreeMap!(int, string)();
17 
18         /*Adding elements to TreeMap*/
19         tmap.put(1, "Data1");
20         tmap.put(23, "Data23");
21         tmap.put(70, "Data70");
22         tmap.put(4, "Data4");
23         tmap.put(2, "Data2");
24 
25         writeln(tmap.toString());
26         assert(tmap[70] == "Data70", tmap[70]);
27 
28         /* Display content using Iterator*/
29         //   Set!(MapEntry!(K,V)) set = tmap.entrySet();
30         //   Iterator!(MapEntry!(K,V)) iterator = set.iterator();
31         //   while(iterator.hasNext()) {
32         //      Map.Entry mentry = (Map.Entry)iterator.next();
33         //      System.out.print("key is: "+ mentry.getKey() ~ " & Value is: ");
34         //      writeln(mentry.getValue());
35         //   }
36         writeln("\nTesting TreeMap foreach1...");
37         foreach (int key, string value; tmap) {
38             writeln("key is: " ~ key.to!string ~ " & Value is: " ~ value);
39         }
40 
41         writeln("\nTesting TreeMap foreach2...");
42         foreach (MapEntry!(int, string) entry; tmap) {
43             writeln("Key is: " ~ entry.getKey().to!string ~ " & Value is: " ~ entry.getValue());
44         }
45 
46         writeln("\nTesting TreeMap byKey...");
47         foreach (size_t index, int key; tmap.byKey) {
48             writefln("Key[%d] is: %d ", index, key);
49         }
50 
51         writeln("\nTesting TreeMap byValue...");
52         foreach (size_t index, string value; tmap.byValue) {
53             writefln("value[%d] is: %s ", index, value);
54         }
55     }
56 
57     void testElementWithClass() {
58         
59     }
60 }