KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * _BaseTreeSetImpl_SubMap_entrySet.java
3  * $Id: _BaseTreeMap_SubMap_entrySet.java,v 1.7 2003/11/27 15:55:11 leomekenkamp 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 import java.util.Map JavaDoc;
54
55 /**
56  * <p>DO NOT USE THIS CLASS DIRECTLY.</p>
57  * This should be an anonymous inner class; ozone will probably never support
58  * these as being seperate ozone objects, so we have to resort to this hack.</p>
59  */

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