blackboard.base
Class GenericFieldFilter

java.lang.Object
  extended by blackboard.base.ListFilter
      extended by blackboard.base.GenericFieldFilter

public class GenericFieldFilter
extends ListFilter

Filter implementation that allows objects in a list to be filtered based on the value of an attribute that they have in common. For example, a list of courses could be filtered by their availability, returned by course.getIsAvailable(). The comparison works for boolean, String, Calendar, or any data type that implements Comparable.

Note that this class is implemented using reflection.

Since:
Bb 6.0
Version:
$Revision: #1 $ $Date: 2005/06/27 $

Nested Class Summary
static class GenericFieldFilter.Comparison
           
 
Field Summary
 
Fields inherited from class blackboard.base.ListFilter
NOOP
 
Constructor Summary
GenericFieldFilter(java.lang.String fieldAccessorMethod, java.lang.Class targetClass, java.lang.Object targetForComparison, GenericFieldFilter.Comparison comparison)
          Constructs the filter to perform a comparison using a specific field accessor, to a specific value.
 
Method Summary
protected  int compareFields(java.lang.Object field1, java.lang.Object field2)
          Compare method allowing explicit support for comparing objects that don't implement Comparable.
protected  boolean passesFilter(java.lang.Object listElement)
          Returns true if the given element passes this filter's tests for inclusion in the sublist.
 
Methods inherited from class blackboard.base.ListFilter
addFilter, passesFilters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericFieldFilter

public GenericFieldFilter(java.lang.String fieldAccessorMethod,
                          java.lang.Class targetClass,
                          java.lang.Object targetForComparison,
                          GenericFieldFilter.Comparison comparison)
                   throws java.lang.IllegalArgumentException,
                          java.lang.SecurityException
Constructs the filter to perform a comparison using a specific field accessor, to a specific value.

Parameters:
fieldAccessMethod - the case-sensitive name of the accessor method defined in the target class that will be used to get the value that will in turn be used in the comparison process to determine if the object should "pass" the filter.
targetClass - a Class for the object which contains the accessor method. This can be a base class of the objects in a list or an interface that they all implement.
targetForComparison - an Object
comparison - a value as defined in GenericFieldFilter#Comparison that defines the criteria under which the vale should be compared to determine whether it passes the filter
Throws:
java.lang.IllegalArgumentException - if the target class does not contain a method called fieldAccessorMethod.
java.lang.SecurityException - if the caller does not have access to the specified method in the specified class.
Method Detail

passesFilter

protected boolean passesFilter(java.lang.Object listElement)
Returns true if the given element passes this filter's tests for inclusion in the sublist.

Specified by:
passesFilter in class ListFilter

compareFields

protected int compareFields(java.lang.Object field1,
                            java.lang.Object field2)
                     throws java.lang.IllegalArgumentException
Compare method allowing explicit support for comparing objects that don't implement Comparable. Base implementation provides support for String, Comparable, Boolean, Calendar. Note that blackboard.persist.Id and blackboard.base.BbEnum already implement Comparable. Subclasses can override this method to add support for additional non- comparable types, but be sure to call super.compareFields() if the objects are not of one of the target types being supported.

Note that ascending order for booleans is defined as false before true. Calendars are compared by the Dates returned by their getTime() methods. BbEnum elements are sorted by their external string representation in alphabetical order.

Throws:
java.lang.IllegalArgumentException - thrown if the _fieldAccessorMethod is not found, or does not return the appropriate type.


Copyright © 2003 Blackboard, Inc. All Rights Reserved.