1 // $Id: Modifier.java,v 1.4 2007-07-03 13:29:34 mike Exp $
3 package org.z3950.zing.cql;
5 import static org.z3950.zing.cql.Utils.*;
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,
13 * This class is used only by ModifierSet.
15 * @version $Id: Modifier.java,v 1.4 2007-07-03 13:29:34 mike Exp $
17 public class Modifier {
23 * Creates a new Modifier with the specified type, comparison
26 public Modifier(String type, String comparison, String value) {
28 this.comparison = comparison;
30 //System.err.println("Made new modifier with " + "type='" + type + "', " + "comparison='" + comparison + "', " + "value='" + value + "',\n");
34 * Creates a new Modifier with the specified type but no
35 * comparison or value.
37 public Modifier(String type) {
39 //System.err.println("Made new modifier of type '" + type + "'\n");
43 * Returns the type with which the Modifier was created.
45 public String getType() {
50 * Returns the comparison with which the Modifier was created.
52 public String getComparison() {
57 * Returns the value with which the Modifier was created.
59 public String getValue() {
63 public String toXCQL(int level, String relationElement) {
64 StringBuilder buf = new StringBuilder();
66 buf.append(indent(level)).append("<modifier>\n").
67 append(indent(level + 1)).append("<type>").
68 append(xq(type)).append("</type>\n");
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");
77 buf.append(indent(level)).append("</modifier>\n");
78 return buf.toString();
81 public String toCQL() {
82 StringBuilder buf = new StringBuilder(type);
84 buf.append(" ").append(comparison).append(" ").append(value);
85 return buf.toString();