X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fmkjsf%2Fpazpar2%2Fcommands%2FExpression.java;h=1961baeef111c2fa5ed27dabc2e2eeb72af2c435;hb=86f289cd42ba95846c80d22129ed565e4e9d6dde;hp=3c377e28855ea0c155bb01c2a685e8735fd72361;hpb=31a027596723261b413d69c74428b176def3627f;p=mkjsf-moved-to-github.git diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Expression.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Expression.java index 3c377e2..1961bae 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Expression.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Expression.java @@ -1,12 +1,25 @@ package com.indexdata.mkjsf.pazpar2.commands; import java.io.Serializable; -import java.util.StringTokenizer; import org.apache.log4j.Logger; -import com.indexdata.mkjsf.pazpar2.commands.Expression; - +/** + * Represents a complex command parameter value, in form of an expression with + * an equality operator + *
+ * An expression consist of a left-of-operator field or key, an equality operator (= or ~), + * a right-of-operator value, and optionally a label describing the value for UI display. + *
+ *Examples:
+ *pz:id=1234
"My Target"category~libcatalog
"Library Catalogs"author="Steinbeck, John"
+ * Currently only '=' and '~' are recognized as operators + *
+ * + * @param expressionString + */ public Expression (String expressionString) { - StringTokenizer tokenizer = new StringTokenizer(expressionString,"="); - this.leftEntity = tokenizer.nextToken(); - this.operator = "="; - this.rightEntity = tokenizer.nextToken(); + String[] parts = expressionString.split("[=~]"); + this.leftEntity = parts[0]; + this.operator = expressionString.contains("=") ? "=" : "~"; + this.rightEntity = parts[1]; this.label=rightEntity; } + /** + * Clones the expression + * + * @return a clone of this expression + */ public Expression copy() { logger.trace("Copying " + this.toString()); return new Expression(leftEntity, operator, rightEntity, label); @@ -40,18 +76,39 @@ public class Expression implements Serializable { return leftEntity + operator + rightEntity; } + /** + * Returns the label describing the value of the expression or, + * if no label was provided, the value itself. + * + * @return label or right-of-operator value if no label provided + */ public String getLabel() { return label; } + /** + * Returns the left-of-operator field (or name or key). + * + * @return entity left of operator + */ public String getField () { return leftEntity; } + /** + * Returns the operator + * + * @return the operator of the expression + */ public String getOperator() { return operator; } + /** + * Returns the right-of-operator value of the expression + * + * @return entity right of operator + */ public String getValue() { return rightEntity; }