X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fmkjsf%2Fpazpar2%2Fcommands%2FExpression.java;h=1961baeef111c2fa5ed27dabc2e2eeb72af2c435;hb=fc1ac55e0dd989bc3a5a023c5931e8f4e2774668;hp=f636f68a7a172abce519b4dccd26bc33fa731922;hpb=875d04a7c3120b7c4b3a412985957df15479ff81;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 f636f68..1961bae 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Expression.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Expression.java @@ -4,6 +4,22 @@ import java.io.Serializable; import org.apache.log4j.Logger; +/** + * 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:

+ * + * @author Niels Erik + * + */ public class Expression implements Serializable { private static final long serialVersionUID = -751704027842027769L; @@ -13,13 +29,31 @@ public class Expression implements Serializable { String rightEntity; String label; - public Expression (String leftEntity, String operator, String rightEntity, String label) { - this.leftEntity = leftEntity; + /** + * Instantiates an expression with a label + * + * @param leftEntity left-of-operator field name (or 'key') + * @param operator an equality operator + * @param rightEntity right-of-operator value + * @param label to be used for display, for instance in a UI control that adds or removes the expression + * from a command parameter + */ + public Expression (String field, String operator, String value, String label) { + this.leftEntity = field; this.operator = operator; - this.rightEntity = rightEntity; + this.rightEntity = value; this.label = label; } + /** + * Instantiates an expression by parsing the provided expression string, which must be + * on the form {name}({=}or{~}){value}. + *

+ * Currently only '=' and '~' are recognized as operators + *

+ * + * @param expressionString + */ public Expression (String expressionString) { String[] parts = expressionString.split("[=~]"); this.leftEntity = parts[0]; @@ -28,6 +62,11 @@ public class Expression implements Serializable { 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); @@ -37,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; }