-// $Id: ModifierSet.java,v 1.3 2002-11-06 00:05:58 mike Exp $
+// $Id: ModifierSet.java,v 1.8 2007-06-06 12:22:01 mike Exp $
package org.z3950.zing.cql;
import java.util.Vector;
* <P>
* 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.
+ * <P>
+ * A ModifierSet consists of a ``base'' string together with a set of
+ * zero or more <I>type</I>=<I>value</I> pairs, where both type and
+ * value are strings. Types may be null, values may not.
*
- * @version $Id: ModifierSet.java,v 1.3 2002-11-06 00:05:58 mike Exp $
+ * @version $Id: ModifierSet.java,v 1.8 2007-06-06 12:22:01 mike Exp $
*/
public class ModifierSet {
String base;
- Vector modifiers;
+ Vector<Vector> modifiers;
+ /**
+ * Creates a new ModifierSet with the specified base.
+ */
public ModifierSet(String base) {
this.base = base;
- modifiers = new Vector();
+ modifiers = new Vector<Vector>();
}
+ /**
+ * Returns the base string with which the ModifierSet was created.
+ */
public String getBase() {
return base;
}
+ /**
+ * Adds a modifier of the specified <TT>type</TT> and
+ * <TT>value</TT> to a ModifierSet.
+ */
public void addModifier(String type, String value) {
- Vector modifier = new Vector();
+ Vector<String> modifier = new Vector<String>();
modifier.add(type);
modifier.add(value);
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
+ * <TT>Vector</TT>, 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];