KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > graph > query > Pattern


1 /*
2   (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: Pattern.java,v 1.10 2005/02/21 11:52:15 andy_seaborne Exp $
5 */

6
7 package com.hp.hpl.jena.graph.query;
8
9 import com.hp.hpl.jena.graph.*;
10
11 /**
12     A Pattern represents a matching triple; it is composed of S, P, and O Elements.
13     
14     @author hedgehog
15 */

16
17 public class Pattern
18     {
19     private Element S;
20     private Element P;
21     private Element O;
22     
23     public Pattern( Element S, Element P, Element O )
24         {
25         this.S = S;
26         this.P = P;
27         this.O = O;
28         }
29     
30     /**
31         Convert a Pattern into a TripleMatch by making a Triple who's Nodes are the
32         conversions of the constituent elements.
33     */

34     public TripleMatch asTripleMatch( Domain d )
35         {
36         return Triple.createMatch
37             ( S.asNodeMatch( d ), P.asNodeMatch( d ), O.asNodeMatch( d ) );
38         }
39     
40     /**
41         Answer true iff this pattern, given the values for variables as found in a given
42         Domain, matches the given triple; update the Domain with any variable bindings.
43         
44         @param d the Domain with the current bound variable values (and slots for the rest)
45         @param t the concrete triple to match
46         @return true iff this pattern matches the triple [and side-effects the domain]
47     */

48     public boolean match( Domain d, Triple t )
49         {
50         return S.match( d, t.getSubject() )
51             && P.match( d, t.getPredicate() )
52             && O.match( d, t.getObject() );
53         }
54
55      public String JavaDoc toString()
56         { return "<pattern " + S + " @" + P + " " + O + ">"; }
57     }
58
59 /*
60     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
61     All rights reserved.
62
63     Redistribution and use in source and binary forms, with or without
64     modification, are permitted provided that the following conditions
65     are met:
66
67     1. Redistributions of source code must retain the above copyright
68        notice, this list of conditions and the following disclaimer.
69
70     2. Redistributions in binary form must reproduce the above copyright
71        notice, this list of conditions and the following disclaimer in the
72        documentation and/or other materials provided with the distribution.
73
74     3. The name of the author may not be used to endorse or promote products
75        derived from this software without specific prior written permission.
76
77     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
78     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
79     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
80     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
81     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
82     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
83     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
84     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
85     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
86     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
87 */

88
Popular Tags