Handling specific types

The parser only supports directly the primitive java types. If a table contains a column whose type is not a primitive java type, it will be treated, in most cases, as a string. Obviously, this is not the case when the associated filter editor is a ChoiceFilterEditor, as then the parser is not used at all!

To handle specific types it is required the interface ITypeBuilder, which specifies how to build and object using its string representation. The IFilterTextParser interface supports for this purpose the method setTypeBuilder.

Types handled in this way should implement also the generic java interface Comparable, in order to use most of the comparison operands. Alternatively, the IFilterTextParser interface supports the method setComparator , requiring a valid Comparator instance for its associated type.

Handling dates

Until version 2.0, dates were not specifically supported in the library, so the user had to define its handling specifically.

Version 2.0 introduces a generic handling of dates: the type DateHandler implements the ITypeBuilder interface, and is automatically registered in the text parsers.

By default, the expected format is the one supplied by invoking

java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT)
that supports only dates -not included time-, in the default locale

This behaviour can be modified in multiple ways. The user can still specify its own ITypeBuilder as in previous versions. In addition, the user can define the property

net.coderazzi.filters.TextParser.DateFormat
to override the expected format. Although this second option is quite useful, the first option is required if the table or tables in the application use more than one date format

Comparing dates

The usage of dates in the filters can be quite troublesome. The normal date comparison method checks that two dates are equal, up to the milliseconds. However, if the table only renders the dates up to minutes -or even without time-, means that applying, for example, the filter 01/09/2009 to the date 01/09/2009 06:24 PM, which is, in fact, rendered as 01/09/2009, will show no matches at all!

The DateHandler class implements a dates comparator that takes in account only the rendered format. Please note that this comparison method can be quite slow. Library's users can enable it in two ways:

The usage and programming of this comparison can be checked on the example program AppTestMain. To check it, launch the example and press the Change table button, to have the extended table model, which includes dates. Then, change the filters to mode SLIM or BASIC, to use the filter parser. Then, setting dates in the associated column's filter will fail any matches unless the Exact dates checkbox is unset