com.endeca.navigation.analytics
Class FilterCompare

java.lang.Object
  extended by com.endeca.navigation.analytics.FilterCompare
All Implemented Interfaces:
Filter, QueryNode

public class FilterCompare
extends Object
implements Filter

A FilterCompare is a type of Filter that performs a value comparison. The FilterCompare object is then set in a Statement object with the Statement.setHavingFilter(com.endeca.navigation.analytics.Filter) or Statement.setWhereFilter(com.endeca.navigation.analytics.Filter) methods.

A typical use of this class is to compare the value of an Endeca property or dimension to a specified literal value. This can be considered as a programmatic equivalent of the SQL HAVING and WHERE clauses. For example, this text-based syntax snippet:

RETURN Reps AS
WHERE Region = 'West'
can be expressed programmatically as:
Statement reps = new Statement();
reps.setName("Reps");
reps.setWhereFilter(new FilterCompare("Region", FilterCompare.EQ, "West"));

A FilterCompare can also be used to determine if the value of an Endeca property or dimension is null or non-null.


Nested Class Summary
static class FilterCompare.FilterCompareOp
          Enumeration of Endeca comparison operators.
 
Field Summary
static FilterCompare.FilterCompareOp DVAL
          DVAL operator.
static FilterCompare.FilterCompareOp EQ
          EQUAL TO operator.
static FilterCompare.FilterCompareOp GT
          GREATER THAN operator.
static FilterCompare.FilterCompareOp GTE
          GREATER THAN OR EQUAL TO operator.
static FilterCompare.FilterCompareOp IS_NOT_NULL
          NON-NULL operator.
static FilterCompare.FilterCompareOp IS_NULL
          NULL operator.
static FilterCompare.FilterCompareOp LT
          LESS THAN operator.
static FilterCompare.FilterCompareOp LTE
          LESS THAN OR EQUAL TO operator.
static FilterCompare.FilterCompareOp NEQ
          NOT EQUAL TO operator.
 
Constructor Summary
FilterCompare(String fieldName, FilterCompare.FilterCompareOp function, String value)
          Creates a new FilterCompare object.
 
Method Summary
 String getFieldName()
          Gets the fieldName for this FilterCompare.
 FilterCompare.FilterCompareOp getFunction()
          Gets the comparison function for this FilterCompare.
 String getValue()
          Gets the comparison value for this FilterCompare.
 void setFieldName(String fieldName)
          Sets the name of the Endeca property or dimension for this FilterCompare.
 void setFunction(FilterCompare.FilterCompareOp function)
          Sets the comparison function for this FilterCompare.
 void setValue(String value)
          Sets the comparison value for this FilterCompare.
 String toString()
          Returns the string form of this this FilterCompare.
 String toWire()
          Returns the wire form of this FilterCompare.
 void validateSyntax()
          Validates the syntax of this FilterCompare.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EQ

public static final FilterCompare.FilterCompareOp EQ
EQUAL TO operator. Determines if the value of fieldName is equal to the value of the value parameter.


NEQ

public static final FilterCompare.FilterCompareOp NEQ
NOT EQUAL TO operator. Determines if the value of fieldName is not equal to the value of the value parameter.


LT

public static final FilterCompare.FilterCompareOp LT
LESS THAN operator. Determines if the value of fieldName is less than the value of the value parameter.


LTE

public static final FilterCompare.FilterCompareOp LTE
LESS THAN OR EQUAL TO operator. Determines if the value of fieldName is less than or equal to the value of the value parameter.


GT

public static final FilterCompare.FilterCompareOp GT
GREATER THAN operator. Determines if the value of fieldName is greater than the value of the value parameter.


GTE

public static final FilterCompare.FilterCompareOp GTE
GREATER THAN OR EQUAL TO operator. Determines if the value of fieldName is greater than or equal to the value of the value parameter.


IS_NULL

public static final FilterCompare.FilterCompareOp IS_NULL
NULL operator. Determines if the fieldName is null. The value parameter is ignored.


IS_NOT_NULL

public static final FilterCompare.FilterCompareOp IS_NOT_NULL
NON-NULL operator. Determines if the fieldName is non-null. The value parameter is ignored.


DVAL

public static final FilterCompare.FilterCompareOp DVAL
DVAL operator. Used to filter records by a dimension value with an ID specified by the value parameter.

Constructor Detail

FilterCompare

public FilterCompare(String fieldName,
                     FilterCompare.FilterCompareOp function,
                     String value)
Creates a new FilterCompare object. The FilterCompare compares the value for the Endeca property or dimension fieldName to the value specified by value using the function specified by function.

The filter evaluates to true for a given record if the specified comparison function evaluates to true when applied to the value for fieldName from the record (lhs) and the specified value (rhs). For example, if fieldName is "Price" and the record has a Price of 1.00, and the function is FilterCompare.LT and value is 2.00, then the filter would evaluate to true.

Parameters:
fieldName - the name of an Endeca property or dimension. The value of fieldName will be compared to the literal value of the value parameter. Note that this value is ignored for the FilterCompare.DVAL function.
function - a comparison function of type FilterCompare.FilterCompareOp. See the setFunction method for a list of the comparison function names.
value - a literal value to be compared to the value of fieldName. For the FilterCompare.DVAL function, this value specifies the ID of a dimension value. Note that this value is ignored for the FilterCompare.IS_NULL and FilterCompare.IS_NOT_NULL functions.
Method Detail

getFieldName

public String getFieldName()
Gets the fieldName for this FilterCompare.

Returns:
The name of an Endeca property or dimension that is the fieldName setting for this FilterCompare.

setFieldName

public void setFieldName(String fieldName)
Sets the name of the Endeca property or dimension for this FilterCompare. The value of this field will either be tested for a null value or will be compared to the value parameter. Note that this value is ignored for the FilterCompare.DVAL operator.

Parameters:
fieldName - the name of an Endeca property or dimension.

getFunction

public FilterCompare.FilterCompareOp getFunction()
Gets the comparison function for this FilterCompare.

Returns:
The comparison function (of type FilterCompare.FilterCompareOp) for this FilterCompare. See the setFunction method for a list of the comparison function names.

setFunction

public void setFunction(FilterCompare.FilterCompareOp function)
Sets the comparison function for this FilterCompare. Comparison functions specify the type of comparison to be performed on the fieldName or between the fieldName and the value parameters.

Note that the FilterCompare.DVAL operator is used to filter records that are tagged with a dimension value with an ID specified by the value parameter.

Parameters:
function - a comparison function (of type FilterCompare.FilterCompareOp) that specifies the type of comparison to be made. The comparison functions are: FilterCompare.EQ, FilterCompare.NEQ, FilterCompare.LT, FilterCompare.LTE, FilterCompare.GT, FilterCompare.GTE, FilterCompare.IS_NULL, FilterCompare.IS_NOT_NULL, and FilterCompare.DVAL.

getValue

public String getValue()
Gets the comparison value for this FilterCompare.

Returns:
The value to be compared.

setValue

public void setValue(String value)
Sets the comparison value for this FilterCompare. This value will be compared to the value of the fieldName, using the specified comparison function. For the FilterCompare.DVAL operator, value specifies the ID of the dimension value that will be used to filter records.

Note that this value is ignored for the FilterCompare.IS_NULL and FilterCompare.IS_NOT_NULL functions.

Parameters:
value - A literal value to be compared.

toString

public String toString()
Returns the string form of this this FilterCompare. These are of the format:
("fieldName" "compare-function" 'compare-value')
Note that compare-value is not returned for the FilterCompare.IS_NULL and FilterCompare.IS_NOT_NULL functions.

For the FilterCompare.DVAL function, the format is:

(DVAL("value")

For example:

("SalesTotal" "FilterCompare.GT" '10000')
is returned if the property name is "SalesTotal" and a GREATER THAN comparison is being made to the value of 10000.

Specified by:
toString in interface QueryNode
Overrides:
toString in class Object
Returns:
A string representation of this FilterCompare in the specified format.

toWire

public String toWire()
Returns the wire form of this FilterCompare. This method is not intended for public use because the wire format is subject to change.

Specified by:
toWire in interface QueryNode
Returns:
A wire format representation of this FilterCompare.

validateSyntax

public void validateSyntax()
                    throws SyntaxException
Validates the syntax of this FilterCompare. A FilterCompare is valid if the function is non-null and the fieldName and value are non-null and non-empty.

Specified by:
validateSyntax in interface QueryNode
Throws:
SyntaxException - if the syntax requirements are not satisfied.


2010 Endeca Technologies, Inc.
Endeca Confidential