KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > rulesys > impl > ChoicePointFrame


1 /******************************************************************
2  * File: ChoicePointFrame.java
3  * Created by: Dave Reynolds
4  * Created on: 22-Jul-2003
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
7  * [See end of file]
8  * $Id: ChoicePointFrame.java,v 1.4 2005/02/21 12:17:40 andy_seaborne Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.reasoner.rulesys.impl;
11
12 import com.hp.hpl.jena.graph.Node;
13
14 import java.util.*;
15
16 /**
17  * Represents a single frame in the LP interpreter's choice point stack,
18  * represents the OR part of the search tree.
19  * <p>
20  * This is used in the inner loop of the interpreter and so is a pure data structure
21  * not an abstract data type and assumes privileged access to the interpreter state.
22  * </p>
23  *
24  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
25  * @version $Revision: 1.4 $ on $Date: 2005/02/21 12:17:40 $
26  */

27 public class ChoicePointFrame extends GenericChoiceFrame {
28
29     /** The set of argument variables for the call */
30     Node[] argVars = new Node[RuleClauseCode.MAX_ARGUMENT_VARS];
31
32     /** Iterator over the clauses being searched */
33     Iterator clauseIterator;
34     
35     /**
36      * Constructor.
37      * Initialize a choice point to preserve the current context of the given intepreter
38      * and then call the given set of predicates.
39      * @param interpreter the LPInterpreter whose state is to be preserved
40      * @param predicateClauses the list of predicates for this choice point
41      */

42     public ChoicePointFrame(LPInterpreter interpreter, List predicateClauses) {
43         init(interpreter, predicateClauses);
44     }
45
46     /**
47      * Initialize a choice point to preserve the current context of the given intepreter
48      * and then call the given set of predicates.
49      * @param interpreter the LPInterpreter whose state is to be preserved
50      * @param predicateClauses the list of predicates for this choice point
51      */

52     public void init(LPInterpreter interpreter, List predicateClauses) {
53         super.init(interpreter);
54         System.arraycopy(interpreter.argVars, 0, argVars, 0, argVars.length);
55         clauseIterator = predicateClauses.iterator();
56     }
57     
58     /**
59      * Is there another clause in the sequence?
60      */

61     public boolean hasNext() {
62         return clauseIterator.hasNext();
63     }
64     
65     /**
66      * Return the next clause in the sequence.
67      */

68     public RuleClauseCode nextClause() {
69         return (RuleClauseCode) clauseIterator.next();
70     }
71
72 }
73
74 /*
75     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
76     All rights reserved.
77
78     Redistribution and use in source and binary forms, with or without
79     modification, are permitted provided that the following conditions
80     are met:
81
82     1. Redistributions of source code must retain the above copyright
83        notice, this list of conditions and the following disclaimer.
84
85     2. Redistributions in binary form must reproduce the above copyright
86        notice, this list of conditions and the following disclaimer in the
87        documentation and/or other materials provided with the distribution.
88
89     3. The name of the author may not be used to endorse or promote products
90        derived from this software without specific prior written permission.
91
92     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
93     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
94     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
95     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
96     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
97     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
98     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
99     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
100     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
101     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
102 */
Popular Tags