KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > collections > _BaseTreeMap_SubMap_keySet


1 /*
2  * _BaseTreeSet_SubMap_keySet.java
3  * $Id: _BaseTreeMap_SubMap_keySet.java,v 1.8 2003/11/20 23:18:41 per_nyfelt Exp $
4  * This file is based on TreeMap.java from GNU Classpath. Quote:
5
6 TreeMap.java -- a class providing a basic Red-Black Tree data structure,
7 mapping Object --> Object
8 Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
9
10 This file is part of GNU Classpath.
11
12 GNU Classpath is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
15 any later version.
16
17 GNU Classpath is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with GNU Classpath; see the file COPYING. If not, write to the
24 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 02111-1307 USA.
26
27 Linking this library statically or dynamically with other modules is
28 making a combined work based on this library. Thus, the terms and
29 conditions of the GNU General Public License cover the whole
30 combination.
31
32 As a special exception, the copyright holders of this library give you
33 permission to link this library with independent modules to produce an
34 executable, regardless of the license terms of these independent
35 modules, and to copy and distribute the resulting executable under
36 terms of your choice, provided that you also meet, for each linked
37 independent module, the terms and conditions of the license of that
38 module. An independent module is a module which is not derived from
39 or based on this library. If you modify this library, you may extend
40 this exception to your version of the library, but you are not
41 obligated to do so. If you do not wish to do so, delete this
42 exception statement from your version.
43
44  * end quote.
45  *
46  * This file is licenced under the same conditions as its original (GPL +
47  * "special exception").
48  */

49
50 package org.ozoneDB.collections;
51
52 import java.util.Iterator JavaDoc;
53
54 /**
55  * <p>DO NOT USE THIS CLASS DIRECTLY.</p>
56  * This should be an anonymous inner class; ozone will probably never support
57  * these as being seperate ozone objects, so we have to resort to this hack.</p>
58  */

59 public class _BaseTreeMap_SubMap_keySet extends AbstractOzoneSet implements OzoneSet {
60
61     private static final long serialVersionUID = 1L;
62
63     private _BaseTreeMap_SubMap owner;
64
65     /** Creates a new instance of BaseTreeMap_SubMap_keySet */
66     public _BaseTreeMap_SubMap_keySet(_BaseTreeMap_SubMap owner) {
67         this.owner = owner;
68     }
69
70
71     public int size() {
72         return owner.size();
73     }
74
75     public Iterator JavaDoc iterator() {
76         if (owner.getOwner()._org_ozoneDB_alwaysUseInternalIterator()) {
77             return _org_ozoneDB_internalIterator();
78         } else {
79             BaseTreeMap.Node first = owner.getOwner()._org_ozoneDB_lowestGreaterThan(owner.getMinKey(), true);
80             BaseTreeMap.Node max = owner.getOwner()._org_ozoneDB_lowestGreaterThan(owner.getMaxKey(), false);
81
82 // TODO: replace when FakeFactoryGenerator is ready
83
// return = BaseTreeMap_TreeIteratorFactory.getDefault.create(owner.getOwner(), BaseTreeMapImpl.KEYS, first, max);
84
return (Iterator JavaDoc) database().createObject(_BaseTreeMap_OzoneTreeIteratorImpl.class,
85                     new Class JavaDoc[] {BaseTreeMap.class, Integer.TYPE, BaseTreeMap.Node.class, BaseTreeMap.Node.class},
86                     new Object JavaDoc[] {owner.getOwner(), new Integer JavaDoc(BaseTreeMapImpl.KEYS), first, max});
87         }
88     }
89     
90     public Iterator JavaDoc _org_ozoneDB_internalIterator() {
91         BaseTreeMap.Node first = owner.getOwner()._org_ozoneDB_lowestGreaterThan(owner.getMinKey(), true);
92         BaseTreeMap.Node max = owner.getOwner()._org_ozoneDB_lowestGreaterThan(owner.getMaxKey(), false);
93         return new _BaseTreeMap_TreeIterator(owner.getOwner(), BaseTreeMapImpl.KEYS, first, max);
94     }
95
96     public void clear() {
97         owner.clear();
98     }
99
100     public boolean contains(Object JavaDoc o) {
101         if (!owner.keyInRange(o))
102             return false;
103         return !owner.getOwner()._org_ozoneDB_getNode(o).isNil();
104     }
105
106     public boolean remove(Object JavaDoc o) {
107         if (!owner.keyInRange(o))
108             return false;
109         BaseTreeMap.Node n = owner.getOwner()._org_ozoneDB_getNode(o);
110         if (!n.isNil()) {
111             owner.getOwner()._org_ozoneDB_removeNode(n);
112             return true;
113         }
114         return false;
115     }
116
117 }
Popular Tags