001: /*
002: * DataRowExpression.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.storage.filter;
013:
014: import java.util.Iterator;
015: import java.util.Map;
016:
017: /**
018: * A class to define the filter criteria for all columns of a data row
019: * @author support@sql-workbench.net
020: */
021: public class DataRowExpression implements FilterExpression,
022: ExpressionValue {
023: private Object filterValue;
024: private ColumnComparator comparator;
025: private boolean ignoreCase;
026:
027: public DataRowExpression() {
028: }
029:
030: /**
031: * Define the filter for a complete row
032: * @param comparator the comparator to be used to compare the reference value against the actual values
033: * @param referenceValue the filter value to compare against the actual values
034: */
035: public DataRowExpression(ColumnComparator comparator,
036: Object referenceValue) {
037: setComparator(comparator);
038: setFilterValue(referenceValue);
039: }
040:
041: public Object getFilterValue() {
042: return filterValue;
043: }
044:
045: public void setFilterValue(Object value) {
046: this .filterValue = value;
047: }
048:
049: public ColumnComparator getComparator() {
050: return comparator;
051: }
052:
053: public void setComparator(ColumnComparator comp) {
054: this .comparator = comp;
055: }
056:
057: public boolean equals(Object other) {
058: try {
059: DataRowExpression def = (DataRowExpression) other;
060: if (this .filterValue == null || def.filterValue == null)
061: return false;
062: boolean result = this .filterValue.equals(def.filterValue);
063: if (result) {
064: result = this .comparator.equals(def.comparator);
065: }
066: return result;
067: } catch (Throwable th) {
068: return false;
069: }
070: }
071:
072: public boolean evaluate(Map<String, Object> columnValues) {
073: Iterator itr = columnValues.values().iterator();
074: while (itr.hasNext()) {
075: Object value = itr.next();
076: if (value != null) {
077: boolean result = comparator.evaluate(filterValue, value
078: .toString(), this .ignoreCase);
079: if (result)
080: return true;
081: }
082: }
083: return false;
084: }
085:
086: public String toString() {
087: return "[any column] " + this .comparator.getOperator() + " "
088: + comparator.getValueExpression(this .filterValue);
089: }
090:
091: public boolean isIgnoreCase() {
092: return ignoreCase;
093: }
094:
095: public void setIgnoreCase(boolean ignoreCase) {
096: this .ignoreCase = ignoreCase;
097: }
098:
099: public String getColumnName() {
100: return "*";
101: }
102:
103: public boolean isColumnSpecific() {
104: return false;
105: }
106:
107: }
|