X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Forg%2Fz3950%2Fzing%2Fcql%2FModifierSet.java;h=66380ffc7110c555c751a1e45fd56ce74bb02ab0;hb=18405938a115378cc571d697060ac40775c62fb7;hp=18d8c9d749a26a5e2fb4e9df0754807b22e16ada;hpb=f8154c71944186a9b64ddb782082a2026c5a912f;p=cql-java-moved-to-github.git diff --git a/src/org/z3950/zing/cql/ModifierSet.java b/src/org/z3950/zing/cql/ModifierSet.java index 18d8c9d..66380ff 100644 --- a/src/org/z3950/zing/cql/ModifierSet.java +++ b/src/org/z3950/zing/cql/ModifierSet.java @@ -1,4 +1,4 @@ -// $Id: ModifierSet.java,v 1.1 2002-10-31 22:22:01 mike Exp $ +// $Id: ModifierSet.java,v 1.7 2002-11-20 17:56:22 mike Exp $ package org.z3950.zing.cql; import java.util.Vector; @@ -9,19 +9,37 @@ import java.lang.StringBuffer; *

* This class is used as a workhorse delegate by both CQLRelation and * CQLProxNode - two functionally very separate classes that happen to - * require the same data structures and functionality. + * require similar data structures and functionality. + *

+ * A ModifierSet consists of a ``base'' string together with a set of + * zero or more type=value pairs, where both type and + * value are strings. Types may be null, values may not. * - * @version $Id: ModifierSet.java,v 1.1 2002-10-31 22:22:01 mike Exp $ + * @version $Id: ModifierSet.java,v 1.7 2002-11-20 17:56:22 mike Exp $ */ public class ModifierSet { String base; Vector modifiers; + /** + * Creates a new ModifierSet with the specified base. + */ public ModifierSet(String base) { this.base = base; modifiers = new Vector(); } + /** + * Returns the base string with which the ModifierSet was created. + */ + public String getBase() { + return base; + } + + /** + * Adds a modifier of the specified type and + * value to a ModifierSet. + */ public void addModifier(String type, String value) { Vector modifier = new Vector(); modifier.add(type); @@ -29,6 +47,27 @@ public class ModifierSet { modifiers.add(modifier); } + /** + * Returns the value of the modifier in the specified ModifierSet + * that corresponds to the specified type. + */ + public String modifier(String type) { + int n = modifiers.size(); + for (int i = 0; i < n; i++) { + Vector pair = (Vector) modifiers.get(i); + if (pair.get(0).equals(type)) + return (String) pair.get(1); + } + return null; + } + + /** + * Returns an array of the modifiers in a ModifierSet. + * @return + * An array of modifiers, each represented by a two-element + * Vector, in which element 0 is the modifier type and + * element 1 is the associated value. + */ public Vector[] getModifiers() { int n = modifiers.size(); Vector[] res = new Vector[n]; @@ -50,18 +89,15 @@ public class ModifierSet { for (int i = 0; i < mods.length; i++) { Vector modifier = mods[i]; buf.append(Utils.indent(level+2)). - append("\n"); + append(""); if (modifier.get(0) != null) - buf.append(Utils.indent(level+3)). - append(""). + buf.append(""). append(Utils.xq((String) modifier.get(0))). - append("\n"); - buf.append(Utils.indent(level+3)); + append(""); buf.append(""). append(Utils.xq((String) modifier.get(1))). - append("\n"); - buf.append(Utils.indent(level+2)). - append("\n"); + append(""); + buf.append("\n"); } buf.append(Utils.indent(level+1) + "\n"); }