From: mike Date: Wed, 27 Jun 2007 17:01:23 +0000 (+0000) Subject: New X-Git-Tag: v1.5~123 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=5b9190e42d439d7b1cf07d0ad09a30e1e4d3d143;p=cql-java-moved-to-github.git New --- diff --git a/src/org/z3950/zing/cql/Modifier.java b/src/org/z3950/zing/cql/Modifier.java new file mode 100644 index 0000000..00c1a89 --- /dev/null +++ b/src/org/z3950/zing/cql/Modifier.java @@ -0,0 +1,86 @@ +// $Id: Modifier.java,v 1.1 2007-06-27 17:01:23 mike Exp $ + +package org.z3950.zing.cql; +import java.util.Vector; +import java.lang.StringBuffer; + +/** + * Represents a single modifier, consisting of three elements: a type, + * a comparision and a value. For example, "distance", "<", "3". The + * type is mandatory; either the comparison and value must both occur, + * or neither must. + *

+ * This class is used only by ModifierSet. + * + * @version $Id: Modifier.java,v 1.1 2007-06-27 17:01:23 mike Exp $ + */ +public class Modifier { + String type; + String comparison; + String value; + + /** + * Creates a new Modifier with the specified type, comparison + * and value. + */ + public Modifier(String type, String comparison, String value) { + this.type = type; + this.comparison = comparison; + this.value = value; + } + + /** + * Creates a new Modifier with the specified value but no + * comparison or value. + */ + public Modifier(String value) { + this.value = value; + } + + /** + * Returns the type with which the Modifier was created. + */ + public String getType() { + return type; + } + + /** + * Returns the comparison with which the Modifier was created. + */ + public String getComparison() { + return comparison; + } + + /** + * Returns the value with which the Modifier was created. + */ + public String getValue() { + return value; + } + + public String toXCQL(int level, String relationElement) { + StringBuffer buf = new StringBuffer(); + + buf.append(Utils.indent(level) + "\n"); + buf.append(Utils.indent(level+1) + + "" + Utils.xq(type) + "\n"); + if (value != null) { + buf.append(Utils.indent(level+1) + "<" + relationElement + ">" + + Utils.xq(comparison) + "\n"); + buf.append(Utils.indent(level+1) + + "" + Utils.xq(value) + "\n"); + } + + buf.append(Utils.indent(level) + "\n"); + return buf.toString(); + } + + public String toCQL() { + StringBuffer buf = new StringBuffer(type); + + if (value != null) + buf.append(" " + comparison + " " + value); + + return buf.toString(); + } +}