cmu.survey.data
Class Filter<T>

java.lang.Object
  extended by cmu.survey.data.Filter<T>
All Implemented Interfaces:
HasBeenModified, HasID

public class Filter<T>
extends java.lang.Object
implements HasBeenModified, HasID

Show only rows matching certain criteria.
Used in DataTableModel for finding certain rows.
This is similar to a chunk of a "where" clause in SQL, or a find/search for a small chunk -- it "filters" the results down to a smaller subset, where a column matches or doesn't match criteria.
Some examples on how to use Filter:
new Filter(columnName="id", Filter.EQUALS, "10") -- show only rows in the table where the "id" column equals "10".
new Filter(columnName="startDate", Filter.GREATER_THAN_OR_EQUAL_TO, "2004-10-12") -- show only rows in the table where the "startDate" column (here we assume this is a date) is on 10/12/2004 or later.

See Also:
for more information about the comarators you can set and what's valid.

Field Summary
static java.lang.String EQUALS
           
static java.lang.String GREATER_THAN
           
static java.lang.String GREATER_THAN_OR_EQUAL_TO
           
static java.lang.String LESS_THAN
           
static java.lang.String LESS_THAN_OR_EQUAL_TO
           
static java.lang.String NOT_EQUAL
           
static java.lang.String[] POSSIBLE_COMPARATOR_STRINGS
           
 
Constructor Summary
Filter(StringDataBit columnName, StringDataBit comparator, DataBit<T> value, java.lang.Integer id)
           
Filter(java.lang.String columnName, java.lang.String comparator, java.util.Date value)
           
Filter(java.lang.String columnName, java.lang.String comparator, java.lang.Double value)
           
Filter(java.lang.String columnName, java.lang.String comparator, int value)
           
Filter(java.lang.String columnName, java.lang.String comparator, java.lang.Integer value)
           
Filter(java.lang.String columnName, java.lang.String comparator, java.lang.String value)
           
Filter(java.lang.String columnName, java.lang.String comparator, java.lang.String value, java.lang.Integer id)
           
 
Method Summary
 void addFilterChangeListener(FilterChangedListener listener)
           
 java.lang.String getColumnName()
           
 java.lang.String getComparator()
           
 boolean getHasBeenModified()
           
 java.lang.Integer getID()
          Optional Unique ID for loading/saving the filter.
 T getValue()
           
 DataBit<T> getValueDataBit()
           
 void removeFilterChangeListener(FilterChangedListener listener)
           
 void setColumnName(java.lang.String string)
           
 boolean setComparator(java.lang.String compString)
          Set the way to filter, the comparison technique.
 void setID(java.lang.Integer uniqueID)
          Optional Unique ID for loading/saving the filter.
 void setJustLoaded()
          call right after being loaded, when everything should be registered as fresh and not modified.
 void setValue(java.lang.String newValue)
           
 void setValue(T newValue)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EQUALS

public static final java.lang.String EQUALS
See Also:
Constant Field Values

NOT_EQUAL

public static final java.lang.String NOT_EQUAL
See Also:
Constant Field Values

LESS_THAN

public static final java.lang.String LESS_THAN
See Also:
Constant Field Values

GREATER_THAN

public static final java.lang.String GREATER_THAN
See Also:
Constant Field Values

LESS_THAN_OR_EQUAL_TO

public static final java.lang.String LESS_THAN_OR_EQUAL_TO
See Also:
Constant Field Values

GREATER_THAN_OR_EQUAL_TO

public static final java.lang.String GREATER_THAN_OR_EQUAL_TO
See Also:
Constant Field Values

POSSIBLE_COMPARATOR_STRINGS

public static final java.lang.String[] POSSIBLE_COMPARATOR_STRINGS
Constructor Detail

Filter

public Filter(java.lang.String columnName,
              java.lang.String comparator,
              java.lang.String value)
       throws java.lang.IllegalArgumentException
Parameters:
columnName - the name of the column to filter, as determined by DataTableModel.getColumnName(), etc.
comparator - @see setComparator
value -
Throws:
java.lang.IllegalArgumentException

Filter

public Filter(java.lang.String columnName,
              java.lang.String comparator,
              java.lang.Integer value)
       throws java.lang.IllegalArgumentException
Parameters:
columnName - the name of the column to filter, as determined by DataTableModel.getColumnName(), etc.
comparator - @see setComparator
value -
Throws:
java.lang.IllegalArgumentException

Filter

public Filter(java.lang.String columnName,
              java.lang.String comparator,
              java.util.Date value)
       throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

Filter

public Filter(java.lang.String columnName,
              java.lang.String comparator,
              java.lang.Double value)
       throws java.lang.IllegalArgumentException
Parameters:
columnName - the name of the column to filter, as determined by DataTableModel.getColumnName(), etc.
comparator - @see setComparator
value -
Throws:
java.lang.IllegalArgumentException

Filter

public Filter(java.lang.String columnName,
              java.lang.String comparator,
              int value)
       throws java.lang.IllegalArgumentException
Parameters:
columnName - the name of the column to filter, as determined by DataTableModel.getColumnName(), etc.
comparator - @see setComparator
value -
Throws:
java.lang.IllegalArgumentException

Filter

public Filter(java.lang.String columnName,
              java.lang.String comparator,
              java.lang.String value,
              java.lang.Integer id)
       throws java.lang.IllegalArgumentException
Parameters:
columnName -
comparator - @see setComparator
value -
id - the ID of this filter. This is extra, non-used info, for filters that need unique ids for loading/saving them. Only use this if you need it for unique identification of this filter.
Throws:
java.lang.IllegalArgumentException

Filter

public Filter(StringDataBit columnName,
              StringDataBit comparator,
              DataBit<T> value,
              java.lang.Integer id)
Parameters:
columnName -
comparator -
value -
id - the ID of this filter. This is extra, non-used info, for filters that need unique ids for loading/saving them. Only use this if you need it for unique identification of this filter.
Method Detail

getColumnName

public java.lang.String getColumnName()

getValue

public T getValue()

getValueDataBit

public DataBit<T> getValueDataBit()

setColumnName

public void setColumnName(java.lang.String string)

setValue

public void setValue(T newValue)

setValue

public void setValue(java.lang.String newValue)

addFilterChangeListener

public void addFilterChangeListener(FilterChangedListener listener)

removeFilterChangeListener

public void removeFilterChangeListener(FilterChangedListener listener)

setComparator

public boolean setComparator(java.lang.String compString)
                      throws java.lang.IllegalArgumentException
Set the way to filter, the comparison technique. Pass in one of Filter.EQUALS, Filter.NOT_EQUAL, Filter.LESS_THAN, Filter.GREATER_THAN, Filter.LESS_THAN_OR_EQUAL_TO, Filter.GREATER_THAN_OR_EQUAL_TO

Parameters:
comparator - as a string
Returns:
true if comparator changed, false if it did not change.
Throws:
java.lang.IllegalArgumentException - if the compString is not one of the Filter.* comparators (all options are listed in Filter.POSSIBLE_COMPARATOR_STRINGS

getComparator

public java.lang.String getComparator()

getID

public java.lang.Integer getID()
Optional Unique ID for loading/saving the filter. This is not used by Filter. If you're not loading and saving the Filter, you can ignore the "id" fields -- use only the 3-parameter contstructors and ignore getID() and setID(). Those are only needed when the filter is loaded from a file and needs a unique id for comparison and saving.

Specified by:
getID in interface HasID
Returns:
Returns the uniqueID.

setID

public void setID(java.lang.Integer uniqueID)
Optional Unique ID for loading/saving the filter. This is not used by Filter. If you're not loading and saving the Filter, you can ignore the "id" fields -- use only the 3-parameter contstructors and ignore getID() and setID(). Those are only needed when the filter is loaded from a file and needs a unique id for comparison and saving.

Parameters:
uniqueID - The uniqueID to set.

setJustLoaded

public void setJustLoaded()
call right after being loaded, when everything should be registered as fresh and not modified.


getHasBeenModified

public boolean getHasBeenModified()
Specified by:
getHasBeenModified in interface HasBeenModified

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object