1 // $Id: Modifier.java,v 1.4 2007-07-03 13:29:34 mike Exp $
3 package org.z3950.zing.cql;
4 import java.lang.StringBuffer;
7 * Represents a single modifier, consisting of three elements: a type,
8 * a comparision and a value. For example, "distance", "<", "3". The
9 * type is mandatory; either the comparison and value must both occur,
12 * This class is used only by ModifierSet.
14 * @version $Id: Modifier.java,v 1.4 2007-07-03 13:29:34 mike Exp $
16 public class Modifier {
22 * Creates a new Modifier with the specified type, comparison
25 public Modifier(String type, String comparison, String value) {
27 this.comparison = comparison;
29 //System.err.println("Made new modifier with " + "type='" + type + "', " + "comparison='" + comparison + "', " + "value='" + value + "',\n");
33 * Creates a new Modifier with the specified type but no
34 * comparison or value.
36 public Modifier(String type) {
38 //System.err.println("Made new modifier of type '" + type + "'\n");
42 * Returns the type with which the Modifier was created.
44 public String getType() {
49 * Returns the comparison with which the Modifier was created.
51 public String getComparison() {
56 * Returns the value with which the Modifier was created.
58 public String getValue() {
62 public String toXCQL(int level, String relationElement) {
63 StringBuffer buf = new StringBuffer();
65 buf.append(Utils.indent(level) + "<modifier>\n");
66 buf.append(Utils.indent(level+1) +
67 "<type>" + Utils.xq(type) + "</type>\n");
69 buf.append(Utils.indent(level+1) + "<" + relationElement + ">" +
70 Utils.xq(comparison) + "</" + relationElement + ">\n");
71 buf.append(Utils.indent(level+1) +
72 "<value>" + Utils.xq(value) + "</value>\n");
75 buf.append(Utils.indent(level) + "</modifier>\n");
76 return buf.toString();
79 public String toCQL() {
80 StringBuffer buf = new StringBuffer(type);
82 buf.append(" " + comparison + " " + value);
84 return buf.toString();