01: /*
02: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: All rights reserved - see end of file.
04: $Id: MatchOrBind.java,v 1.4 2008/01/02 12:09:51 andy_seaborne Exp $
05: */
06: package com.hp.hpl.jena.mem;
07:
08: import com.hp.hpl.jena.graph.Triple;
09: import com.hp.hpl.jena.graph.query.Domain;
10: import com.hp.hpl.jena.graph.query.QueryNode;
11: import com.hp.hpl.jena.mem.faster.ProcessedTriple;
12:
13: public abstract class MatchOrBind {
14: public static MatchOrBind createSP(final ProcessedTriple Q) {
15: return new MatchOrBind() {
16: protected Domain d;
17: protected final QueryNode S = Q.S;
18: protected final QueryNode P = Q.P;
19:
20: public MatchOrBind reset(Domain d) {
21: this .d = d;
22: return this ;
23: }
24:
25: public boolean matches(Triple t) {
26: return S.matchOrBind(d, t.getSubject())
27: && P.matchOrBind(d, t.getPredicate());
28: }
29: };
30: }
31:
32: public static MatchOrBind createPO(final ProcessedTriple Q) {
33: return new MatchOrBind() {
34: protected Domain d;
35: protected final QueryNode P = Q.P;
36: protected final QueryNode O = Q.O;
37:
38: public MatchOrBind reset(Domain d) {
39: this .d = d;
40: return this ;
41: }
42:
43: public boolean matches(Triple t) {
44: return P.matchOrBind(d, t.getPredicate())
45: && O.matchOrBind(d, t.getObject());
46: }
47: };
48: }
49:
50: public abstract boolean matches(Triple t);
51:
52: public abstract MatchOrBind reset(Domain d);
53: }
54:
55: /*
56: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
57: * All rights reserved.
58: *
59: * Redistribution and use in source and binary forms, with or without
60: * modification, are permitted provided that the following conditions
61: * are met:
62: * 1. Redistributions of source code must retain the above copyright
63: * notice, this list of conditions and the following disclaimer.
64: * 2. Redistributions in binary form must reproduce the above copyright
65: * notice, this list of conditions and the following disclaimer in the
66: * documentation and/or other materials provided with the distribution.
67: * 3. The name of the author may not be used to endorse or promote products
68: * derived from this software without specific prior written permission.
69: *
70: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
71: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
72: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
73: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
74: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
75: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
76: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
77: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
78: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
79: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
80: */
|