diff options
Diffstat (limited to 'guava/src/com/google/common/eventbus/EventHandler.java')
-rw-r--r-- | guava/src/com/google/common/eventbus/EventHandler.java | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/guava/src/com/google/common/eventbus/EventHandler.java b/guava/src/com/google/common/eventbus/EventHandler.java index 45efa80..be89973 100644 --- a/guava/src/com/google/common/eventbus/EventHandler.java +++ b/guava/src/com/google/common/eventbus/EventHandler.java @@ -16,15 +16,10 @@ package com.google.common.eventbus; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.common.base.Preconditions; - import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import javax.annotation.Nullable; - /** * Wraps a single-argument 'handler' method on a specific object. * @@ -65,11 +60,10 @@ class EventHandler { * * @param event event to handle * @throws InvocationTargetException if the wrapped method throws any - * {@link Throwable} that is not an {@link Error} ({@code Error} instances are + * {@link Throwable} that is not an {@link Error} ({@code Error}s are * propagated as-is). */ public void handleEvent(Object event) throws InvocationTargetException { - checkNotNull(event); try { method.invoke(target, new Object[] { event }); } catch (IllegalArgumentException e) { @@ -90,18 +84,25 @@ class EventHandler { @Override public int hashCode() { final int PRIME = 31; - return (PRIME + method.hashCode()) * PRIME - + System.identityHashCode(target); + return (PRIME + method.hashCode()) * PRIME + target.hashCode(); } - @Override public boolean equals(@Nullable Object obj) { - if (obj instanceof EventHandler) { - EventHandler that = (EventHandler) obj; - // Use == so that different equal instances will still receive events. - // We only guard against the case that the same object is registered - // multiple times - return target == that.target && method.equals(that.method); + @Override public boolean equals(Object obj) { + if(this == obj) { + return true; + } + + if(obj == null) { + return false; } - return false; + + if(getClass() != obj.getClass()) { + return false; + } + + final EventHandler other = (EventHandler) obj; + + return method.equals(other.method) && target == other.target; } + } |