At 10:40 PM 10/19/2003 -0700, Mark Womack wrote:
I just checked in some changes for plugins that I have been meaning to do
for some time.  Mainly, getting rid of the overriding of the equals() method
to determing if 2 instances of a plugin are equivalent.  Doing this is not
so great and has implications to override hashCode(), which requires a lot
more work than it was worth.  There is now an isEquivalent() method in the
Plugin interface that can be implemented to determine, to the degree the
developer wishes, if the plugins are equivalent.  The PluginRegistry uses
this to determine if a plugin being started is equivalent to a plugin
already running.  The idea is to maintain an already running plugin over
stopping it and starting the new one.  This avoids losing events during the
inbetween time.

Mark, I might be missing the point but you probably can simply stick your current implementation of isEquivalent() into equals.

Correctly implementing hashCode can be easy as :

public int hashCode() {
  return 1; // any other constant would do as well
}

another implementation which returns the same hash code for all
instances of the same class.

public int hashCode() {
  return this.getClass().hashCode();
}


The above is correct in the sense that it adheres to the hashCode contract.

The general contract of hashCode is (from the javadocs for Object class):

1) Whenever it is invoked on the same object more than once during an
execution of a Java application, the hashCode method must consistently
return the same integer, provided no information used in equals
comparisons on the object is modified. This integer need not remain
consistent from one execution of an application to another execution
of the same application.

2) If two objects are equal according to the equals(Object) method,
then calling the hashCode method on each of the two objects must
produce the same integer result.

3) It is not required that if two objects are unequal according to the
equals(java.lang.Object) method, then calling the hashCode method on
each of the two objects must produce distinct integer
results. However, the programmer should be aware that producing
distinct integer results for unequal objects may improve the
performance of hashtables.

Item 3 says that although not optional, unequal objects *may* return the
same hashCode.

I hope you find the above helpful.

-Mark

-- Ceki Gülcü

     For log4j documentation consider "The complete log4j manual"
     ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp

     import org.apache.Facetime;
     ApacheCon US 2003, 18-21 November http://apachecon.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to