1 package com.indexdata.pz2utils4jsf.pazpar2;
\r
3 import java.io.Serializable;
\r
4 import java.io.UnsupportedEncodingException;
\r
5 import java.net.URLEncoder;
\r
6 import java.util.HashMap;
\r
7 import java.util.Map;
\r
9 import org.apache.log4j.Logger;
\r
11 import com.indexdata.pz2utils4jsf.pazpar2.CommandParameter;
\r
12 import com.indexdata.pz2utils4jsf.pazpar2.Expression;
\r
14 public class CommandParameter implements Serializable {
\r
16 private static Logger logger = Logger.getLogger(CommandParameter.class);
\r
18 private static final long serialVersionUID = 625502285668766749L;
\r
20 String operator = null;
\r
21 String value = null;
\r
22 Map<String,Expression> expressions = new HashMap<String,Expression>();
\r
24 public CommandParameter (String name) {
\r
25 logger.debug("Instantiating command parameter (1) " + name);
\r
29 public CommandParameter (String name, String operator, String value, Expression... expressions) {
\r
30 logger.debug("Instantiating command parameter (2) " + name + " with " + expressions);
\r
32 this.operator = operator;
\r
34 for (Expression expr : expressions) {
\r
35 this.expressions.put(expr.toString(), expr);
\r
39 public CommandParameter (String name, String operator, String value) {
\r
40 logger.debug("Instantiating command parameter (3) " + name + " ("+this+") with " + name + " and " + value);
\r
42 this.operator = operator;
\r
43 this.value = value;
\r
46 public CommandParameter (String name, String operator, int value) {
\r
47 logger.debug("Instantiating command parameter (4) " + name + " ("+this+") with " + name + " and " + value);
\r
49 this.operator = operator;
\r
50 this.value = value+"";
\r
54 public String getName () {
\r
58 public Map<String,Expression> getExpressions () {
\r
62 public void addExpression(Expression expression) {
\r
63 logger.debug("Adding expression [" + expression + "] to " + this.getName() + " ("+this+")");
\r
64 this.expressions.put(expression.toString(),expression);
\r
67 public void removeExpression(Expression expression) {
\r
68 this.expressions.remove(expression.toString());
\r
72 public boolean hasOperator() {
\r
73 return operator != null;
\r
76 public String getEncodedQueryString () {
\r
78 return name + operator + URLEncoder.encode(getValueWithExpressions(),"UTF-8");
\r
79 } catch (UnsupportedEncodingException e) {
\r
80 e.printStackTrace();
\r
85 public String getSimpleValue() {
\r
89 public String getValueWithExpressions () {
\r
90 StringBuilder completeValue = new StringBuilder((value==null ? "" : value));
\r
91 for (String key : expressions.keySet()) {
\r
92 completeValue.append(" and " + expressions.get(key));
\r
94 return completeValue.toString();
\r
99 public boolean equals (Object otherParameter) {
\r
101 ((otherParameter instanceof CommandParameter)
\r
102 && this.getValueWithExpressions().equals(((CommandParameter) otherParameter).getValueWithExpressions()));
\r
106 public int hashCode () {
\r
107 return getValueWithExpressions().hashCode();
\r
110 public String toString() {
\r
111 return getValueWithExpressions();
\r
114 public CommandParameter copy() {
\r
115 CommandParameter newParam = new CommandParameter(name);
\r
116 newParam.value = this.value;
\r
117 newParam.operator = this.operator;
\r
118 for (String key : expressions.keySet()) {
\r
119 newParam.addExpression(expressions.get(key).copy());
\r