commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henri Yandell <bay...@generationjava.com>
Subject Re: [beanutils] Question about BeanComparator
Date Thu, 26 Sep 2002 22:02:50 GMT

I concur with both Ola and Robert.

The Boolean aspect is just a single part of what I've been calling
ObjectComparator, a Comparator than can compare anything. It has big
issues in terms of having to delegate to various hard coded comparators,
and be pluggable with user's comparators.

There's nothing to stop you doing:

BeanComparator cmp = new BeanComparator("active", new BooleanComparator());

is there?

Hen

On Thu, 26 Sep 2002, robert burrell donkin wrote:

> 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, EPugh@upstate.com 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:commons-dev-unsubscribe@jakarta.apache.
> > org>
> > For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.
> > org>
> >
>
>
> --
> To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message