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


001:        /*
002:          (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003:          [See end of file]
004:          $Id: QueryTestBase.java,v 1.9 2008/01/02 12:08:56 andy_seaborne Exp $
005:         */
006:
007:        package com.hp.hpl.jena.graph.query.test;
008:
009:        import java.util.List;
010:
011:        import com.hp.hpl.jena.graph.Node;
012:        import com.hp.hpl.jena.graph.query.*;
013:        import com.hp.hpl.jena.graph.test.GraphTestBase;
014:        import com.hp.hpl.jena.util.iterator.Map1;
015:
016:        /**
017:         Various things that are common to some of the query/expression
018:         tests, so pulled up here into a shared superclass.
019:        
020:         @author hedgehog
021:         */
022:        public abstract class QueryTestBase extends GraphTestBase {
023:            public QueryTestBase(String name) {
024:                super (name);
025:            }
026:
027:            /**
028:             	An expression that is true if x and y differ. Variable nodes
029:             	are treated as variables, non-variable nodes as constants.
030:             */
031:            protected Expression notEqual(Node x, Node y) {
032:                return new Dyadic(asExpression(x),
033:                        "http://jena.hpl.hp.com/constraints/NE",
034:                        asExpression(y)) {
035:                    public boolean evalBool(Object x, Object y) {
036:                        return !x.equals(y);
037:                    }
038:                };
039:            }
040:
041:            /**
042:             	An expression that is true if x and y are equal. Variable nodes
043:             	are treated as variables, non-variable nodes as constants.
044:             */
045:            protected Expression areEqual(Node x, Node y) {
046:                return new Dyadic(asExpression(x),
047:                        "http://jena.hpl.hp.com/constraints/EQ",
048:                        asExpression(y)) {
049:                    public boolean evalBool(Object x, Object y) {
050:                        return x.equals(y);
051:                    }
052:                };
053:            }
054:
055:            /**
056:             	An expression that is true if x and y "match", in the sense
057:             	that x contains y. Variable nodes are treated as variables, 
058:             	non-variable nodes as constants.
059:             */
060:            protected Expression matches(Node x, Node y) {
061:                return new Dyadic(asExpression(x),
062:                        "http://jena.hpl.hp.com/constraints/MATCHES",
063:                        asExpression(y)) {
064:                    public boolean evalBool(Object L, Object R) {
065:                        Node l = (Node) L, r = (Node) R;
066:                        return l.toString(false).indexOf(r.toString(false)) > -1;
067:                    }
068:                };
069:            }
070:
071:            /**
072:                Answer a filter that selects the <code>index</code>th element of the
073:                list it's given.
074:             */
075:            protected Map1 select(final int index) {
076:                return new Map1() {
077:                    public Object map1(Object o) {
078:                        return ((List) o).get(index);
079:                    }
080:                };
081:            }
082:
083:            /**
084:             	Answer an expression that evaluates the node <code>x</code>,
085:             	treating variable nodes as variables (<i>quelle surprise</i>) and other
086:             	nodes as constants.
087:             */
088:            public static Expression asExpression(final Node x) {
089:                if (x.isVariable())
090:                    return new Expression.Variable() {
091:                        public String getName() {
092:                            return x.getName();
093:                        }
094:
095:                        public Valuator prepare(VariableIndexes vi) {
096:                            return new SlotValuator(vi.indexOf(x.getName()));
097:                        }
098:                    };
099:                return new Expression.Fixed(x);
100:            }
101:
102:            /**
103:             	A Map1 (suitable for a .mapWith iterator conversion) which 
104:             	assumes the elements are lists and extracts their first elements.
105:             */
106:            protected static Map1 getFirst = new Map1() {
107:                public Object map1(Object x) {
108:                    return ((List) x).get(0);
109:                }
110:            };
111:
112:            /**
113:               An IndexValues with no elements - ever slot maps to null
114:             */
115:            protected static final IndexValues noIVs = new IndexValues() {
116:                public Object get(int i) {
117:                    return null;
118:                }
119:            };
120:
121:            /**
122:                 A mapping with no elements pre-defined
123:             */
124:            protected static final Mapping emptyMapping = new Mapping(
125:                    new Node[0]);
126:
127:            /**
128:             	A mapping from variables to their indexes where no variables
129:             	are defined (all names map to the non-existant slot -1).
130:             */
131:            protected VariableIndexes noVariables = new VariableIndexes() {
132:                public int indexOf(String name) {
133:                    return -1;
134:                }
135:            };
136:
137:            /**
138:             	A Node with spelling "X".
139:             */
140:            protected static final Node X = Query.X;
141:
142:            /**
143:            	A Node with spelling "Y".
144:             */
145:            protected static final Node Y = Query.Y;
146:
147:            /**
148:            	A Node with spelling "Z".
149:             */
150:            protected static final Node Z = Query.Z;
151:
152:            /**
153:                A convenient way to refer to Node.ANY
154:             */
155:            protected static final Node ANY = Node.ANY;
156:
157:            /**
158:             	An array containing just the node X.
159:             */
160:            protected final Node[] justX = new Node[] { X };
161:        }
162:
163:        /*
164:         (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
165:         All rights reserved.
166:        
167:         Redistribution and use in source and binary forms, with or without
168:         modification, are permitted provided that the following conditions
169:         are met:
170:        
171:         1. Redistributions of source code must retain the above copyright
172:         notice, this list of conditions and the following disclaimer.
173:        
174:         2. Redistributions in binary form must reproduce the above copyright
175:         notice, this list of conditions and the following disclaimer in the
176:         documentation and/or other materials provided with the distribution.
177:        
178:         3. The name of the author may not be used to endorse or promote products
179:         derived from this software without specific prior written permission.
180:        
181:         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
182:         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
183:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
184:         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
185:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
186:         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
187:         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
188:         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
189:         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
190:         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
191:         */
w__w___w__.___j_a__v___a2s___.c___o__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.