You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Eung-ju Park <co...@isoft.co.kr> on 2001/09/13 15:15:43 UTC

Why Version.equals( final Version other )?

Why use "boolean equals( final Version other )"
instead of "boolean equals( final Object other )"?

Test failed because of JUnit test with boolean equals( Object other ). 


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: Why Version.equals( final Version other )?

Posted by Sylvain Wallez <sy...@anyware-tech.com>.

Eung-ju Park a écrit :
> 
> Hmm...
> No problem with common usages.
> But may cause problem with collections.

...and all code that uses the "equals(Object)" method. "equals(Object)"
and "equals(Version)" have different signatures and are therefore
different methods.

This means for example it isn't possible to use Version objects as keys
of a HashMap and retrieve the values with new Version objects describing
the same version :
   map.put(new Version(1,0,0), "Description of version 1.0.0");
   map.get(new Version(1,0,0)) --> null !

Is is the intended contract for Version ?

> 
> ----- Original Message -----
> From: "Paulo Gaspar" <pa...@krankikom.de>
> To: "Avalon Development" <av...@jakarta.apache.org>
> Sent: Friday, September 14, 2001 10:13 PM
> Subject: RE: Why Version.equals( final Version other )?
> 
> > > Well I like the type safety, however you could also easily implement
> >
> > But Peter, since any class inherits a method
> >   boolean equals(Object obj)
> >
> > from Object, you still have no type safe equals() method just by
> > implementing
> >   boolean equals( final Version other )
> >
> > since any call with a non Version compatible argument can be handled
> > by the Object.equals() implementation.
> >
> >
> > Unless you use a different method name, what is the advantage of this
> > type-safe version?
> > Am I missing something?
> >
> >
> > Have fun,
> > Paulo Gaspar
> >
> > > -----Original Message-----
> > > From: Peter Donald [mailto:donaldp@apache.org]
> > > Sent: Thursday, September 13, 2001 3:17 PM
> > > To: Avalon Development
> > > Subject: Re: Why Version.equals( final Version other )?
> > >
> > >
> > > On Thu, 13 Sep 2001 23:15, Eung-ju Park wrote:
> > > > Why use "boolean equals( final Version other )"
> > > > instead of "boolean equals( final Object other )"?
> > >
> > > Well I like the type safety, however you could also easily implement
> > >
> > > public boolean equals( final Object other )
> > > {
> > >   if( other instanceof Version ) return equals( (Version)other );
> > >   else return false;
> > > }
> > >
> > > --
> > > Cheers,
> > >
> > > Pete
> > >
> > > "abandon all hope , ye who enter here" - dante, inferno
> > >

-- 
Sylvain Wallez
Anyware Technologies - http://www.anyware-tech.com

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: Why Version.equals( final Version other )?

Posted by Eung-ju Park <co...@isoft.co.kr>.
Hmm...
No problem with common usages.
But may cause problem with collections.

----- Original Message ----- 
From: "Paulo Gaspar" <pa...@krankikom.de>
To: "Avalon Development" <av...@jakarta.apache.org>
Sent: Friday, September 14, 2001 10:13 PM
Subject: RE: Why Version.equals( final Version other )?


> > Well I like the type safety, however you could also easily implement
> 
> But Peter, since any class inherits a method
>   boolean equals(Object obj)
> 
> from Object, you still have no type safe equals() method just by 
> implementing
>   boolean equals( final Version other )
> 
> since any call with a non Version compatible argument can be handled 
> by the Object.equals() implementation.
> 
> 
> Unless you use a different method name, what is the advantage of this
> type-safe version?
> Am I missing something?
> 
> 
> Have fun,
> Paulo Gaspar
> 
> > -----Original Message-----
> > From: Peter Donald [mailto:donaldp@apache.org]
> > Sent: Thursday, September 13, 2001 3:17 PM
> > To: Avalon Development
> > Subject: Re: Why Version.equals( final Version other )?
> >
> >
> > On Thu, 13 Sep 2001 23:15, Eung-ju Park wrote:
> > > Why use "boolean equals( final Version other )"
> > > instead of "boolean equals( final Object other )"?
> >
> > Well I like the type safety, however you could also easily implement
> >
> > public boolean equals( final Object other )
> > {
> >   if( other instanceof Version ) return equals( (Version)other );
> >   else return false;
> > }
> >
> > --
> > Cheers,
> >
> > Pete
> >
> > "abandon all hope , ye who enter here" - dante, inferno
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: Why Version.equals( final Version other )?

Posted by Eung-ju Park <co...@isoft.co.kr>.
Added.

boolean equals( final Object other )
{
    if ( other instanceof Version )
    {
        return equals( (Version)other );
    }
    else
    {
        return false;
    }
}

----- Original Message -----
From: "Paulo Gaspar" <pa...@krankikom.de>
To: "Avalon Development" <av...@jakarta.apache.org>
Sent: Saturday, September 15, 2001 3:27 AM
Subject: RE: Why Version.equals( final Version other )?


> Well, considering the default implementation of
>   boolean equals(Object obj)
>
> it will still all work properly anyway.
>
> Have fun,
> Paulo
>
> > -----Original Message-----
> > From: Peter Donald [mailto:donaldp@apache.org]
> > Sent: Friday, September 14, 2001 4:58 PM
> > To: Avalon Development
> > Subject: Re: Why Version.equals( final Version other )?
> >
> >
> > On Fri, 14 Sep 2001 23:13, Paulo Gaspar wrote:
> > > > Well I like the type safety, however you could also easily implement
> > >
> > > But Peter, since any class inherits a method
> > >   boolean equals(Object obj)
> > >
> > > from Object, you still have no type safe equals() method just by
> > > implementing
> > >   boolean equals( final Version other )
> >
> > true. I guess it is just a habit then ;)
> >
> > --
> > Cheers,
> >
> > Pete
> >
> > ------------------------------------------
> > I just hate 'yes' men, don't you Smithers?
> > ------------------------------------------
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


RE: Why Version.equals( final Version other )?

Posted by Berin Loritsch <bl...@yahoo.com>.
The Version.equals(Version) method will continue to
work as expected as long as you are also implementing
the Version.equals(Object) method.

I like the type safety of everything, but you do need
to do something like this:

boolean Version.equals(Object obj)
{
    if ( obj instanceof Version)
    {
        return this.equals((Version) obj);
    }

    if ( obj instanceof String)
    {
        return this.equals((String) obj);
    }

    return false;
}

boolean Version.equals(String verString)
{
    return this.equals( new Version( verString ) );
}

....

That way, you can look up a version object through
the Collections enterfaces or anything that looks up
generic objects.

Also, it allows you to store things by Version, but
access them by String....


--- Paulo Gaspar <pa...@krankikom.de> wrote:
> Well, considering the default implementation of
>   boolean equals(Object obj)
> 
> it will still all work properly anyway.
> 
> Have fun,
> Paulo
> 
> > -----Original Message-----
> > From: Peter Donald [mailto:donaldp@apache.org]
> > Sent: Friday, September 14, 2001 4:58 PM
> > To: Avalon Development
> > Subject: Re: Why Version.equals( final Version
> other )?
> > 
> > 
> > On Fri, 14 Sep 2001 23:13, Paulo Gaspar wrote:
> > > > Well I like the type safety, however you could
> also easily implement
> > >
> > > But Peter, since any class inherits a method
> > >   boolean equals(Object obj)
> > >
> > > from Object, you still have no type safe
> equals() method just by
> > > implementing
> > >   boolean equals( final Version other )
> > 
> > true. I guess it is just a habit then ;)
> > 
> > -- 
> > Cheers,
> > 
> > Pete
> > 
> > ------------------------------------------
> > I just hate 'yes' men, don't you Smithers?
> > ------------------------------------------
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> avalon-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> avalon-dev-help@jakarta.apache.org
> > 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> avalon-dev-help@jakarta.apache.org
> 


__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


RE: Why Version.equals( final Version other )?

Posted by Paulo Gaspar <pa...@krankikom.de>.
Well, considering the default implementation of
  boolean equals(Object obj)

it will still all work properly anyway.

Have fun,
Paulo

> -----Original Message-----
> From: Peter Donald [mailto:donaldp@apache.org]
> Sent: Friday, September 14, 2001 4:58 PM
> To: Avalon Development
> Subject: Re: Why Version.equals( final Version other )?
> 
> 
> On Fri, 14 Sep 2001 23:13, Paulo Gaspar wrote:
> > > Well I like the type safety, however you could also easily implement
> >
> > But Peter, since any class inherits a method
> >   boolean equals(Object obj)
> >
> > from Object, you still have no type safe equals() method just by
> > implementing
> >   boolean equals( final Version other )
> 
> true. I guess it is just a habit then ;)
> 
> -- 
> Cheers,
> 
> Pete
> 
> ------------------------------------------
> I just hate 'yes' men, don't you Smithers?
> ------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: Why Version.equals( final Version other )?

Posted by Peter Donald <do...@apache.org>.
On Fri, 14 Sep 2001 23:13, Paulo Gaspar wrote:
> > Well I like the type safety, however you could also easily implement
>
> But Peter, since any class inherits a method
>   boolean equals(Object obj)
>
> from Object, you still have no type safe equals() method just by
> implementing
>   boolean equals( final Version other )

true. I guess it is just a habit then ;)

-- 
Cheers,

Pete

------------------------------------------
I just hate 'yes' men, don't you Smithers?
------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


RE: Why Version.equals( final Version other )?

Posted by Paulo Gaspar <pa...@krankikom.de>.
> Well I like the type safety, however you could also easily implement

But Peter, since any class inherits a method
  boolean equals(Object obj)

from Object, you still have no type safe equals() method just by 
implementing
  boolean equals( final Version other )

since any call with a non Version compatible argument can be handled 
by the Object.equals() implementation.


Unless you use a different method name, what is the advantage of this
type-safe version?
Am I missing something?


Have fun,
Paulo Gaspar

> -----Original Message-----
> From: Peter Donald [mailto:donaldp@apache.org]
> Sent: Thursday, September 13, 2001 3:17 PM
> To: Avalon Development
> Subject: Re: Why Version.equals( final Version other )?
>
>
> On Thu, 13 Sep 2001 23:15, Eung-ju Park wrote:
> > Why use "boolean equals( final Version other )"
> > instead of "boolean equals( final Object other )"?
>
> Well I like the type safety, however you could also easily implement
>
> public boolean equals( final Object other )
> {
>   if( other instanceof Version ) return equals( (Version)other );
>   else return false;
> }
>
> --
> Cheers,
>
> Pete
>
> "abandon all hope , ye who enter here" - dante, inferno
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: Why Version.equals( final Version other )?

Posted by Peter Donald <do...@apache.org>.
On Thu, 13 Sep 2001 23:15, Eung-ju Park wrote:
> Why use "boolean equals( final Version other )"
> instead of "boolean equals( final Object other )"?

Well I like the type safety, however you could also easily implement 

public boolean equals( final Object other )
{
  if( other instanceof Version ) return equals( (Version)other );
  else return false;
}

-- 
Cheers,

Pete

"abandon all hope , ye who enter here" - dante, inferno

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org