01: /*
02: * ComplexExpression.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.storage.filter;
13:
14: import java.util.LinkedList;
15: import java.util.List;
16: import java.util.Map;
17:
18: /**
19: * @author support@sql-workbench.net
20: */
21: public abstract class ComplexExpression implements FilterExpression {
22: protected List<FilterExpression> filter = new LinkedList<FilterExpression>();
23:
24: public ComplexExpression() {
25: }
26:
27: public void addExpression(FilterExpression expr) {
28: filter.add(expr);
29: }
30:
31: public void addColumnExpression(String colname,
32: ColumnComparator comp, Object refValue) {
33: addColumnExpression(colname, comp, refValue, comp
34: .supportsIgnoreCase());
35: }
36:
37: public void addColumnExpression(String colname,
38: ColumnComparator comp, Object refValue, boolean ignoreCase) {
39: ColumnExpression def = new ColumnExpression(colname, comp,
40: refValue);
41: if (comp.supportsIgnoreCase())
42: def.setIgnoreCase(ignoreCase);
43: addExpression(def);
44: }
45:
46: public boolean hasFilter() {
47: if (this .filter == null)
48: return false;
49: return (this .filter.size() > 0);
50: }
51:
52: public void removeExpression(FilterExpression expr) {
53: filter.remove(expr);
54: }
55:
56: /**
57: * Get the list of FilterExpression s that define this ComplexExpression
58: */
59: public List getExpressions() {
60: return filter;
61: }
62:
63: public void setExpressions(List<FilterExpression> l) {
64: this .filter = l;
65: }
66:
67: public boolean equals(Object other) {
68: try {
69: ComplexExpression o = (ComplexExpression) other;
70: return this .filter.equals(o.filter);
71: } catch (Throwable e) {
72: return false;
73: }
74: }
75:
76: public boolean isColumnSpecific() {
77: for (FilterExpression expr : filter) {
78: if (expr.isColumnSpecific())
79: return true;
80: }
81: return false;
82: }
83:
84: public abstract boolean evaluate(Map<String, Object> columnValues);
85: }
|