hi eric
1. i do think that an intelligent bean comparator would be cool and
plug-ins seem like the right way to do it.
2. just FYI we're pushing towards a beanutils release very soon now so be
careful about committing any signatures that might need to be changed
later.
- robert
On Thursday, September 26, 2002, at 10:24 PM, [EMAIL PROTECTED] wrote:
> Hi,
>
> This question is mostly focused for Henri, but anyone can comment. I am
> working on a testcase for BeanComparator, and one that comes up is if I
> try
> and compare two Boolean objects. Because Boolean doesn't support
> Comparable, they crash. I change BeanComparator to have a makeComparable
> method:
>
> private Comparable makeComparable( Object o )
> throws ClassCastException {
> Comparable value = null;
> if ( o == null ) {
> value = new String( "" );
> }
> else if ( o instanceof Boolean ) {
> Boolean b = (Boolean) o;
> if ( b.booleanValue() ) {
> value = new Integer( "1" );
> }
> else {
> value = new Integer( "0" );
> }
> }
> else if ( o instanceof Comparable ) {
> value = (Comparable) o;
> }
> else {
> throw new ClassCastException( "Object " + o.getClass().getName()
> + "
> is not a comparable datatype, or convertable." );
> }
> return value;
> }
>
> Now, I know that this means that as various datatypes are introduced, then
> this needs to be changed. What I am wondering though is that being able
> to
> compare booleans is pretty basic. However, I was also thinking that I
> would
> create SafeComparator that would be smart enough to make nulls into blank
> strings, booleans into 1 and 0 etc...? Heck, if you got crazy, it could
> be
> pluggable similar to the transformer stuff so that any datatype could be
> made a comparable object. What are your opinions? I at least want to get
> my first cut of unit tests into CVS.
>
> Eric Pugh
>
> --
> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED].
> org>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED].
> org>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>