Source Code Cross Referenced for TestHashedTripleBunch.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » mem » test » 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 » RSS RDF » Jena 2.5.5 » com.hp.hpl.jena.mem.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         	(c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003:         	All rights reserved - see end of file.
004:         	$Id: TestHashedTripleBunch.java,v 1.7 2008/02/01 11:28:50 chris-dollin Exp $
005:         */
006:
007:        package com.hp.hpl.jena.mem.test;
008:
009:        import com.hp.hpl.jena.graph.*;
010:        import com.hp.hpl.jena.mem.*;
011:
012:        public class TestHashedTripleBunch extends TestTripleBunch {
013:            public TestHashedTripleBunch(String name) {
014:                super (name);
015:            }
016:
017:            protected static class HTB extends HashedTripleBunch {
018:                public HTB(TripleBunch b) {
019:                    super (b);
020:                }
021:
022:                protected int improveHashCode(int hashCode) {
023:                    return hashCode;
024:                }
025:            }
026:
027:            public TripleBunch getBunch() {
028:                return new HashedTripleBunch(emptyBunch);
029:            }
030:
031:            HashedTripleBunch htb = new HTB(emptyBunch);
032:
033:            static class TripleWithHash extends Triple {
034:                final int hash;
035:
036:                TripleWithHash(int hash, Node s, Node p, Node o) {
037:                    super (s, p, o);
038:                    this .hash = hash;
039:                }
040:
041:                public static TripleWithHash create(int n, String s) {
042:                    Triple t = triple(s);
043:                    return new TripleWithHash(n, t.getSubject(), t
044:                            .getPredicate(), t.getObject());
045:                }
046:
047:                public int hashCode() {
048:                    return hash;
049:                }
050:            }
051:
052:            public void testHashcodeUsedAsIndex() {
053:                HashedTripleBunch htb = new HTB(emptyBunch);
054:                int limit = htb.currentCapacity();
055:                for (int i = 0; i < limit; i += 1) {
056:                    TripleWithHash t = TripleWithHash.create(i, "s p o");
057:                    htb.add(t);
058:                    assertSame(t, htb.getItemForTestingAt(i));
059:                }
060:            }
061:
062:            public void testRemovePerformsShiftFromTop() {
063:                int capacity = htb.currentCapacity();
064:                testRemovePerformsShift(capacity - 1, capacity);
065:            }
066:
067:            public void testRemovePerformsShiftFromMiddle() {
068:                int capacity = htb.currentCapacity();
069:                testRemovePerformsShift(capacity - 3, capacity);
070:            }
071:
072:            public void testRemovePerformsShiftWrappingLowestTwo() {
073:                int capacity = htb.currentCapacity();
074:                testRemovePerformsShift(0, capacity);
075:            }
076:
077:            public void testRemovePerformsShiftWrappingLowest() {
078:                int capacity = htb.currentCapacity();
079:                testRemovePerformsShift(1, capacity);
080:            }
081:
082:            private void testRemovePerformsShift(int most, int capacity) {
083:                int next = most - 1;
084:                if (next < 0)
085:                    next += capacity;
086:                int least = most - 2;
087:                if (least < 0)
088:                    least += capacity;
089:                TripleWithHash t1 = TripleWithHash.create(most, "s p o");
090:                TripleWithHash t2 = TripleWithHash.create(next, "a b c");
091:                TripleWithHash t3 = TripleWithHash.create(most, "x y z");
092:                htb.add(t1);
093:                htb.add(t2);
094:                htb.add(t3);
095:                assertSame(t1, htb.getItemForTestingAt(most));
096:                assertSame(t2, htb.getItemForTestingAt(next));
097:                assertSame(t3, htb.getItemForTestingAt(least));
098:                //
099:                htb.remove(t1);
100:                assertSame(t3, htb.getItemForTestingAt(most));
101:                assertSame(t2, htb.getItemForTestingAt(next));
102:                assertSame(null, htb.getItemForTestingAt(least));
103:            }
104:
105:            public void testIteratorRemovePerformsShiftAndDeliversElementFromTop() {
106:                int capacity = htb.currentCapacity();
107:                testIteratorRemovePerformsShiftAndDeliversElement(capacity - 1,
108:                        capacity);
109:            }
110:
111:            public void testIteratorRemovePerformsShiftAndDeliversElementFromMiddle() {
112:                int capacity = htb.currentCapacity();
113:                testIteratorRemovePerformsShiftAndDeliversElement(capacity - 3,
114:                        capacity);
115:            }
116:
117:            //    public void testIteratorRemovePerformsShiftAndDeliversElementWrappingLowest()
118:            //        {
119:            //        int capacity = htb.currentCapacity();
120:            //        testIteratorRemovePerformsShiftAndDeliversElement( 1, capacity );
121:            //        }
122:            //    
123:            //    public void testIteratorRemovePerformsShiftAndDeliversElementWrappingLowestTwo()
124:            //        {
125:            //        int capacity = htb.currentCapacity();
126:            //        testIteratorRemovePerformsShiftAndDeliversElement( 0, capacity );
127:            //        }
128:
129:            private void testIteratorRemovePerformsShiftAndDeliversElement(
130:                    int most, int capacity) {
131:                //        int next = most - 1; if (next < 0) next += capacity;
132:                //        int least = most - 2; if (least < 0) least += capacity;
133:                //        TripleWithHash t1 = TripleWithHash.create( most, "s p o" );
134:                //        TripleWithHash t2 = TripleWithHash.create( next, "a b c" );
135:                //        TripleWithHash t3 = TripleWithHash.create( most, "x y z" );
136:                //        htb.add( t1 );
137:                //        htb.add( t2 );
138:                //        htb.add( t3 );
139:                //        ExtendedIterator it = htb.iterator();
140:                //        assertSame( t1, it.next() );
141:                //        it.remove();
142:                //        assertSame( t3, it.next() );
143:                //        assertSame( t2, it.next() );
144:            }
145:        }
146:
147:        /*
148:         * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
149:         * All rights reserved.
150:         *
151:         * Redistribution and use in source and binary forms, with or without
152:         * modification, are permitted provided that the following conditions
153:         * are met:
154:         * 1. Redistributions of source code must retain the above copyright
155:         *    notice, this list of conditions and the following disclaimer.
156:         * 2. Redistributions in binary form must reproduce the above copyright
157:         *    notice, this list of conditions and the following disclaimer in the
158:         *    documentation and/or other materials provided with the distribution.
159:         * 3. The name of the author may not be used to endorse or promote products
160:         *    derived from this software without specific prior written permission.
161:         *
162:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
163:         * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
164:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
165:         * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
166:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
167:         * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
168:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
169:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
170:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
171:         * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
172:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.