@Override /** */ public String toString() { StringBuilder strBuilder = new StringBuilder(); if (this.getOperator().equals(Operator.NESTED)) { strBuilder.append('('); for (final QueryRule rule : this.getNestedRules()) { strBuilder.append(rule.toString()); } strBuilder.append(')'); } else { strBuilder.append(this.getField() == null ? " " : (this.getField() + " ")); strBuilder.append(this.getOperator()).append(value == null ? " " : " '" + value + "'"); } return strBuilder.toString(); }
/** * Create a {@link QueryRule} based on a jquery operator string, from the filter popup/dropdown in * the {@link JQGridRenderer} UI. Example: Supplying the arguments 'name', 'ne', 'Asia' creates a * QueryRule that filters for rows where the 'name' column does not equal 'Asia'. * * @param field The field to which to apply the operator * @param op The operator string (jquery syntax) * @param value The value (if any) for the right-hand side of the operator expression. * @return A new QueryRule that represents the supplied jquery expression. */ private static QueryRule convertOperator(JQGridRule jqGridRule) { // ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc'] QueryRule rule = new QueryRule(jqGridRule.field, QueryRule.Operator.EQUALS, jqGridRule.data); switch (jqGridRule.op) { case eq: rule.setOperator(QueryRule.Operator.EQUALS); return rule; case ne: rule.setOperator(QueryRule.Operator.EQUALS); return toNotRule(rule); case lt: rule.setOperator(QueryRule.Operator.LESS); return rule; case le: rule.setOperator(QueryRule.Operator.LESS_EQUAL); return rule; case gt: rule.setOperator(QueryRule.Operator.GREATER); return rule; case ge: rule.setOperator(QueryRule.Operator.GREATER_EQUAL); case bw: rule.setValue(jqGridRule.data + "%"); rule.setOperator(QueryRule.Operator.LIKE); return rule; case bn: // NOT rule.setValue(jqGridRule.data + "%"); rule.setOperator(QueryRule.Operator.LIKE); rule = toNotRule(rule); return rule; case in: rule.setOperator(QueryRule.Operator.IN); return rule; case ni: // NOT rule.setOperator(QueryRule.Operator.IN); rule = toNotRule(rule); return rule; case ew: rule.setValue("%" + jqGridRule.data); rule.setOperator(QueryRule.Operator.LIKE); return rule; case en: // NOT rule.setValue("%" + jqGridRule.data); rule.setOperator(QueryRule.Operator.LIKE); return toNotRule(rule); case cn: rule.setValue("%" + jqGridRule.data + "%"); rule.setOperator(QueryRule.Operator.LIKE); return rule; case nc: // NOT rule.setValue("%" + jqGridRule.data + "%"); rule.setOperator(QueryRule.Operator.LIKE); return toNotRule(rule); default: throw new IllegalArgumentException(String.format("Unkown Operator: %s", jqGridRule.op)); } }