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