Fix bugs for interfaces. \n\nFor methods declared in interfaces, there always need...
[IRC.git] / Robust / src / ClassLibrary / MGC / gnu / TreeSubMap.java
1 public final class TreeSubMap
2 {
3   TreeMap map;
4   /**
5    * The lower range of this view, inclusive, or nil for unbounded.
6    * Package visible for use by nested classes.
7    */
8   final Object minKey;
9
10   /**
11    * The upper range of this view, exclusive, or nil for unbounded.
12    * Package visible for use by nested classes.
13    */
14   final Object maxKey;
15
16   /**
17    * Create a SubMap representing the elements between minKey (inclusive)
18    * and maxKey (exclusive). If minKey is nil, SubMap has no lower bound
19    * (headMap). If maxKey is nil, the SubMap has no upper bound (tailMap).
20    *
21    * @param minKey the lower bound
22    * @param maxKey the upper bound
23    * @throws IllegalArgumentException if minKey > maxKey
24    */
25   TreeSubMap(TreeMap map, Object minKey, Object maxKey)
26   {
27     this.map = map;
28     if (minKey != TreeMap.nil && maxKey != TreeMap.nil && map.compare(minKey, maxKey) > 0)
29       throw new /*IllegalArgument*/Exception("IllegalArgumentException: fromKey > toKey");
30     this.minKey = minKey;
31     this.maxKey = maxKey;
32     System.out.println("TreeSubMap() " + (String)this.minKey + " " + (String)this.maxKey);
33   }
34
35   public int size()
36   {
37     System.out.println("TreeSubMap.size() " + (String)this.minKey + " " + (String)this.maxKey);
38     TreeNode node = map.lowestGreaterThan(minKey, true);
39     TreeNode max = map.lowestGreaterThan(maxKey, false);
40     System.out.println((String)node.key);
41     System.out.println((String)max.key);
42     int count = 0;
43     while (node != max)
44     {
45       count++;
46       node = map.successor(node);
47     }
48     return count;
49   }
50   
51   /* 0=keys, 1=values, 2=entities */
52   public Iterator iterator(int type) {
53     TreeNode node = map.lowestGreaterThan(minKey, true);
54     TreeNode max = map.lowestGreaterThan(maxKey, false);
55     return (Iterator)(new TreeMapIterator(this.map, type, node, max));
56   }
57 } // class SubMap