Source Code Cross Referenced for BTreeRangeSingle.java in  » Database-DBMS » db4o-6.4 » com » db4o » internal » btree » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db4o 6.4 » com.db4o.internal.btree 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (C) 2004 - 2007  db4objects Inc.  http://www.db4o.com
002:
003:        This file is part of the db4o open source object database.
004:
005:        db4o is free software; you can redistribute it and/or modify it under
006:        the terms of version 2 of the GNU General Public License as published
007:        by the Free Software Foundation and as clarified by db4objects' GPL 
008:        interpretation policy, available at
009:        http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010:        Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011:        Suite 350, San Mateo, CA 94403, USA.
012:
013:        db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014:        WARRANTY; without even the implied warranty of MERCHANTABILITY or
015:        FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
016:        for more details.
017:
018:        You should have received a copy of the GNU General Public License along
019:        with this program; if not, write to the Free Software Foundation, Inc.,
020:        59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */
021:        package com.db4o.internal.btree;
022:
023:        import com.db4o.foundation.*;
024:        import com.db4o.internal.*;
025:        import com.db4o.internal.btree.algebra.*;
026:
027:        /**
028:         * @exclude
029:         */
030:        public class BTreeRangeSingle implements  BTreeRange {
031:
032:            public static final Comparison4 COMPARISON = new Comparison4() {
033:                public int compare(Object x, Object y) {
034:                    BTreeRangeSingle xRange = (BTreeRangeSingle) x;
035:                    BTreeRangeSingle yRange = (BTreeRangeSingle) y;
036:                    return xRange.first().compareTo(yRange.first());
037:                }
038:            };
039:
040:            private final Transaction _transaction;
041:
042:            private final BTree _btree;
043:
044:            private final BTreePointer _first;
045:
046:            private final BTreePointer _end;
047:
048:            public BTreeRangeSingle(Transaction transaction, BTree btree,
049:                    BTreePointer first, BTreePointer end) {
050:                if (transaction == null || btree == null) {
051:                    throw new ArgumentNullException();
052:                }
053:                _transaction = transaction;
054:                _btree = btree;
055:                _first = first;
056:                _end = end;
057:            }
058:
059:            public void accept(BTreeRangeVisitor visitor) {
060:                visitor.visit(this );
061:            }
062:
063:            public boolean isEmpty() {
064:                return BTreePointer.equals(_first, _end);
065:            }
066:
067:            public int size() {
068:                if (isEmpty()) {
069:                    return 0;
070:                }
071:
072:                // TODO: This was an attempt to improve size calculation.
073:                //       Since all nodes are read, there is no improvement.        
074:
075:                //        BTreeNode currentNode = _first.node();
076:                //        int sizeOnFirst = currentNode.count() - _first.index();
077:                //
078:                //        BTreeNode endNode = _end == null ? null : _end.node();
079:                //        int substractForEnd = 
080:                //            (endNode == null) ? 0 : (endNode.count() -  _end.index());
081:                //        
082:                //        int size = sizeOnFirst - substractForEnd;
083:                //        while(! currentNode.equals(endNode)){
084:                //            currentNode = currentNode.nextNode();
085:                //            if(currentNode == null){
086:                //                break;
087:                //            }
088:                //            currentNode.prepareRead(transaction());
089:                //            size += currentNode.count(); 
090:                //        }
091:                //        return size;
092:
093:                int size = 0;
094:                final Iterator4 i = keys();
095:                while (i.moveNext()) {
096:                    ++size;
097:                }
098:                return size;
099:            }
100:
101:            public Iterator4 pointers() {
102:                return new BTreeRangePointerIterator(this );
103:            }
104:
105:            public Iterator4 keys() {
106:                return new BTreeRangeKeyIterator(this );
107:            }
108:
109:            public final BTreePointer end() {
110:                return _end;
111:            }
112:
113:            public Transaction transaction() {
114:                return _transaction;
115:            }
116:
117:            public BTreePointer first() {
118:                return _first;
119:            }
120:
121:            public BTreeRange greater() {
122:                return newBTreeRangeSingle(_end, null);
123:            }
124:
125:            public BTreeRange union(BTreeRange other) {
126:                if (null == other) {
127:                    throw new ArgumentNullException();
128:                }
129:                return new BTreeRangeSingleUnion(this ).dispatch(other);
130:            }
131:
132:            public boolean adjacent(BTreeRangeSingle range) {
133:                return BTreePointer.equals(_end, range._first)
134:                        || BTreePointer.equals(range._end, _first);
135:            }
136:
137:            public boolean overlaps(BTreeRangeSingle range) {
138:                return firstOverlaps(this , range) || firstOverlaps(range, this );
139:            }
140:
141:            private boolean firstOverlaps(BTreeRangeSingle x, BTreeRangeSingle y) {
142:                return BTreePointer.lessThan(y._first, x._end)
143:                        && BTreePointer.lessThan(x._first, y._end);
144:            }
145:
146:            public BTreeRange extendToFirst() {
147:                return newBTreeRangeSingle(firstBTreePointer(), _end);
148:            }
149:
150:            public BTreeRange extendToLast() {
151:                return newBTreeRangeSingle(_first, null);
152:            }
153:
154:            public BTreeRange smaller() {
155:                return newBTreeRangeSingle(firstBTreePointer(), _first);
156:            }
157:
158:            public BTreeRangeSingle newBTreeRangeSingle(BTreePointer first,
159:                    BTreePointer end) {
160:                return new BTreeRangeSingle(transaction(), _btree, first, end);
161:            }
162:
163:            public BTreeRange newEmptyRange() {
164:                return newBTreeRangeSingle(null, null);
165:            }
166:
167:            private BTreePointer firstBTreePointer() {
168:                return btree().firstPointer(transaction());
169:            }
170:
171:            private BTree btree() {
172:                return _btree;
173:            }
174:
175:            public BTreeRange intersect(BTreeRange range) {
176:                if (null == range) {
177:                    throw new ArgumentNullException();
178:                }
179:                return new BTreeRangeSingleIntersect(this ).dispatch(range);
180:            }
181:
182:            public BTreeRange extendToLastOf(BTreeRange range) {
183:                BTreeRangeSingle rangeImpl = checkRangeArgument(range);
184:                return newBTreeRangeSingle(_first, rangeImpl._end);
185:            }
186:
187:            public String toString() {
188:                return "BTreeRangeSingle(first=" + _first + ", end=" + _end
189:                        + ")";
190:            }
191:
192:            private BTreeRangeSingle checkRangeArgument(BTreeRange range) {
193:                if (null == range) {
194:                    throw new ArgumentNullException();
195:                }
196:                BTreeRangeSingle rangeImpl = (BTreeRangeSingle) range;
197:                if (btree() != rangeImpl.btree()) {
198:                    throw new IllegalArgumentException();
199:                }
200:                return rangeImpl;
201:            }
202:
203:            public BTreePointer lastPointer() {
204:                if (_end == null) {
205:                    return btree().lastPointer(transaction());
206:                }
207:                return _end.previous();
208:            }
209:
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.