Remove CVS expansions
[cql-java-moved-to-github.git] / src / main / java / org / z3950 / zing / cql / Modifier.java
1
2 package org.z3950.zing.cql;
3
4 /**
5  * Represents a single modifier, consisting of three elements: a type,
6  * a comparision and a value.  For example, "distance", "<", "3".  The
7  * type is mandatory; either the comparison and value must both occur,
8  * or neither must.
9  * <P>
10  * This class is used only by ModifierSet.
11  *
12  */
13 public class Modifier {
14     String type;
15     String comparison;
16     String value;
17
18     /**
19      * Creates a new Modifier with the specified type, comparison
20      * and value.
21      */
22     public Modifier(String type, String comparison, String value) {
23         this.type = type;
24         this.comparison = comparison;
25         this.value = value;
26         //System.err.println("Made new modifier with " + "type='" + type + "', " + "comparison='" + comparison + "', " + "value='" + value + "',\n");
27     }
28
29     /**
30      * Creates a new Modifier with the specified type but no
31      * comparison or value.
32      */
33     public Modifier(String type) {
34         this.type = type;
35         //System.err.println("Made new modifier of type '" + type + "'\n");
36     }
37
38     /**
39      * Returns the type with which the Modifier was created.
40      */
41     public String getType() {
42         return type;
43     }
44
45     /**
46      * Returns the comparison with which the Modifier was created.
47      */
48     public String getComparison() {
49         return comparison;
50     }
51
52     /**
53      * Returns the value with which the Modifier was created.
54      */
55     public String getValue() {
56         return value;
57     }
58
59     void toXCQLInternal(XCQLBuilder b, int level, String relationElement) {
60         b.indent(level).append("<modifier>\n");
61         b.indent(level + 1).append("<type>");
62         b.xq(type).append("</type>\n");
63         if (value != null) {
64             b.indent(level + 1).append("<").append(relationElement).append(">");
65             b.xq(comparison).append("</").append(relationElement).append(">\n");
66             b.indent(level + 1).append("<value>");
67             b.xq(value).append("</value>\n");
68         }
69         b.indent(level).append("</modifier>\n");
70     }
71
72     public String toCQL() {
73         StringBuilder buf = new StringBuilder(type);
74         if (value != null)
75             buf.append(" ").append(comparison).append(" ").append(value);
76         return buf.toString();
77     }
78 }