Source Code Cross Referenced for TestHashCommon.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 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003:         	All rights reserved.
004:         	$Id: TestHashCommon.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 java.util.*;
010:
011:        import com.hp.hpl.jena.mem.HashCommon;
012:        import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
013:
014:        public class TestHashCommon extends ModelTestBase {
015:            protected static final Item item2X = new Item(2, "X");
016:            protected static final Item item1Y = new Item(1, "Y");
017:            protected static final Item item2Z = new Item(2, "Z");
018:
019:            public TestHashCommon(String name) {
020:                super (name);
021:            }
022:
023:            static class ProbeHashCommon extends HashCommon {
024:                protected ProbeHashCommon(int initialCapacity) {
025:                    super (initialCapacity);
026:                }
027:
028:                protected void set(int index, Item object) {
029:                    keys[index] = object;
030:                }
031:
032:                public Object removeFrom(int here) {
033:                    return super .removeFrom(here);
034:                }
035:
036:                public int top() {
037:                    return capacity - 1;
038:                }
039:
040:                public int capacity() {
041:                    return capacity;
042:                }
043:
044:                /*
045:                    Leaving the hashcode alone makes testing simpler. 
046:                 */
047:                protected int improveHashCode(int hashCode) {
048:                    return hashCode;
049:                }
050:            }
051:
052:            static class Item {
053:                protected final int n;
054:                protected final String s;
055:
056:                public Item(int n, String s) {
057:                    this .n = n;
058:                    this .s = s;
059:                }
060:
061:                public int hashCode() {
062:                    return n;
063:                }
064:
065:                public boolean equals(Object other) {
066:                    return other instanceof  Item && s.equals(((Item) other).s);
067:                }
068:
069:                public String toString() {
070:                    return s + "#" + n;
071:                }
072:            }
073:
074:            public void testSanityCheckTestDataConstruction() {
075:                ProbeHashCommon h = probeWith("1:2:x 4:7:y -1:5:z");
076:                assertEquals(new Item(2, "x"), h.getItemForTestingAt(1));
077:                assertEquals(new Item(7, "y"), h.getItemForTestingAt(4));
078:                assertEquals(new Item(5, "z"), h.getItemForTestingAt(h.top()));
079:            }
080:
081:            public void testHashcodeUsedAsIndex() {
082:                ProbeHashCommon htb = new ProbeHashCommon(10);
083:                int limit = htb.capacity();
084:                for (int i = 0; i < limit; i += 1) {
085:                    Item t = new Item(i, "s p o");
086:                    //            assertEquals( i, htb.)
087:                    //            assertSame( t, htb.getItemForTestingAt( i ) );
088:                }
089:            }
090:
091:            public void testRemoveNoMove() {
092:                ProbeHashCommon h = probeWith("1:1:Y 2:2:Z");
093:                Item moved = (Item) h.removeFrom(2);
094:                assertSame(null, moved);
095:                assertAlike(probeWith("1:1:Y"), h);
096:            }
097:
098:            public void testRemoveSimpleMove() {
099:                ProbeHashCommon h = probeWith("0:2:X 1:1:Y 2:2:Z");
100:                assertSame(null, (Item) h.removeFrom(1));
101:                assertAlike(probeWith("1:2:X 2:2:Z"), h);
102:            }
103:
104:            public void testRemoveCircularMove() {
105:                ProbeHashCommon h = probeWith("0:0:X 1:2:Y -1:2:Z");
106:                Item moved = (Item) h.removeFrom(1);
107:                assertAlike(probeWith("0:0:X 1:2:Z"), h);
108:                assertEquals(new Item(2, "Z"), moved);
109:            }
110:
111:            public void testKeyIterator() {
112:                ProbeHashCommon h = probeWith("0:0:X");
113:                Set elements = h.keyIterator().toSet();
114:                assertEquals(itemSet("0:X"), elements);
115:            }
116:
117:            /**
118:                Assert that the two probe HashCommon's are "alike", that is, that they
119:                have key arrays of equal size and are element-by-element equal. 
120:                Otherwise, fail (preferably with an appropriate message).
121:             */
122:            private void assertAlike(ProbeHashCommon desired,
123:                    ProbeHashCommon got) {
124:                assertEquals("capacities must be equal", desired.capacity(),
125:                        got.capacity());
126:                for (int i = 0; i < desired.capacity(); i += 1)
127:                    assertEquals(desired.getItemForTestingAt(i), got
128:                            .getItemForTestingAt(i));
129:            }
130:
131:            /**
132:                Answer a probe with the specified items. <code>items</code> is a
133:                space-separated string of item descriptions. Each description is a
134:                colon-separated sequence <code>index:hash:label</code>: the
135:                item <code>(hash, label)</code> will be placed at <code>index</code>.
136:                Negative index values are interpreted as indexs from the <i>end</code>
137:                of the key array, by adding the probe's capacity to them. 
138:             */
139:            protected ProbeHashCommon probeWith(String items) {
140:                ProbeHashCommon result = new ProbeHashCommon(10);
141:                StringTokenizer st = new StringTokenizer(items);
142:                while (st.hasMoreTokens()) {
143:                    String item = st.nextToken();
144:                    StringTokenizer itemElements = new StringTokenizer(item,
145:                            ":");
146:                    int index = Integer.parseInt(itemElements.nextToken());
147:                    int hash = Integer.parseInt(itemElements.nextToken());
148:                    String w = itemElements.nextToken();
149:                    result.set((index < 0 ? index + result.capacity() : index),
150:                            new Item(hash, w));
151:                }
152:                return result;
153:            }
154:
155:            protected Set itemSet(String items) {
156:                Set result = new HashSet();
157:                StringTokenizer st = new StringTokenizer(items);
158:                while (st.hasMoreTokens())
159:                    addItem(result, st.nextToken());
160:                return result;
161:            }
162:
163:            private void addItem(Set result, String item) {
164:                StringTokenizer itemElements = new StringTokenizer(item, ":");
165:                int hash = Integer.parseInt(itemElements.nextToken());
166:                String w = itemElements.nextToken();
167:                result.add(new Item(hash, w));
168:            }
169:        }
170:
171:        /*
172:         * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
173:         * All rights reserved.
174:         *
175:         * Redistribution and use in source and binary forms, with or without
176:         * modification, are permitted provided that the following conditions
177:         * are met:
178:         * 1. Redistributions of source code must retain the above copyright
179:         *    notice, this list of conditions and the following disclaimer.
180:         * 2. Redistributions in binary form must reproduce the above copyright
181:         *    notice, this list of conditions and the following disclaimer in the
182:         *    documentation and/or other materials provided with the distribution.
183:         * 3. The name of the author may not be used to endorse or promote products
184:         *    derived from this software without specific prior written permission.
185:         *
186:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
187:         * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
188:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
189:         * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
190:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
191:         * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
192:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
193:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
194:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
195:         * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
196:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.