8c69ecc11815321c5b6dbf1bf78b8c5c5fc1551d
[cql-java-moved-to-github.git] / src / org / z3950 / zing / cql / CQLProxNode.java
1 // $Id: CQLProxNode.java,v 1.2 2002-11-06 00:05:58 mike Exp $
2
3 package org.z3950.zing.cql;
4
5
6 /**
7  * Represents a proximity node in a CQL parse-tree.
8  * The left- and right-hand-sides must be satisfied by parts of the
9  * candidate records which are sufficiently close to each other, as
10  * specified by a set of proximity parameters.
11  *
12  * @version     $Id: CQLProxNode.java,v 1.2 2002-11-06 00:05:58 mike Exp $
13  */
14 public class CQLProxNode extends CQLBooleanNode {
15     ModifierSet ms;
16
17     /**
18      * Creates a new, <I>incomplete</I>, proximity node with the
19      * specified left-hand side.  No right-hand side is specified at
20      * this stage: that must be specified later, using the
21      * <TT>addSecondSubterm()</TT> method.  (That may seem odd, but
22      * it's just easier to write the parser that way.)
23      * <P>
24      * Proximity paramaters may be added at any time, before or after
25      * the right-hand-side sub-tree is added.
26      */
27     public CQLProxNode(CQLNode left) {
28         ms = new ModifierSet("prox");
29         this.left = left;
30         // this.right left unresolved for now ...
31     }
32
33     /**
34      * Sets the right-hand side of the proximity node whose
35      * left-hand-side was specified at creation time.
36      */
37     public void addSecondSubterm(CQLNode right) {
38         this.right = right;
39     }
40
41     String op() {
42         return ms.toCQL();
43     }
44
45     /**
46      * Adds a modifier of the specified <TT>type</TT> and
47      * <TT>value</TT> to a proximity node.  Valid types are
48      * <TT>relation</TT>, <TT>distance</TT>, <TT>unit</TT> and
49      * <TT>ordering</TT>.
50      * <P>
51      * For information on the semantics of these paramaters, see
52      * <A href="http://zing.z3950.org/cql/intro.html#3.1"
53      *  >section 3.1 (Proximity)</A> of
54      * <I>A Gentle Introduction to CQL</I></A>.
55      */
56     public void addModifier(String type, String value) {
57         ms.addModifier(type, value);
58     }
59
60     // ### should have a public method to retrieve all modifiers
61
62     String booleanXQL(int level) {
63         return ms.toXCQL(level, "boolean");
64     }
65 }