Changes to MGC class library and fix a bug regarding nested inline class declaration
[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   }
33
34   public int size()
35   {
36     TreeNode node = map.lowestGreaterThan(minKey, true);
37     TreeNode max = map.lowestGreaterThan(maxKey, false);
38     int count = 0;
39     while (node != max)
40     {
41       count++;
42       node = map.successor(node);
43     }
44     return count;
45   }
46   
47   /* 0=keys, 1=values, 2=entities */
48   public Iterator iterator(int type) {
49     TreeNode node = map.lowestGreaterThan(minKey, true);
50     TreeNode max = map.lowestGreaterThan(maxKey, false);
51     return (Iterator)(new TreeMapIterator(this.map, type, node, max));
52   }
53 } // class SubMap