Skip to content

Commit

Permalink
implemented equals and hashCode
Browse files Browse the repository at this point in the history
  • Loading branch information
cyklon73 committed Mar 17, 2024
1 parent 3f10d1c commit 1debeaf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/de/cyklon/jevent/MethodHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,14 @@ public static <D> Collection<MethodHandler<?>> getHandlers(@NotNull D listener)

return handlers;
}

@Override
public int hashCode() {
return handler.getMethod().hashCode();
}

@Override
public boolean equals(Object obj) {
return obj instanceof MethodHandler<?> mh && mh.handler.equals(this.handler);
}
}
12 changes: 12 additions & 0 deletions src/main/java/de/cyklon/jevent/RawHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,27 @@
*/
class RawHandler<T extends Event> extends Handler<T> {

private final long id;
private final Consumer<T> consumer;

public RawHandler(Class<T> eventType, Consumer<T> consumer, byte priority, boolean ignoreCancelled) {
super(eventType, priority, ignoreCancelled);
this.id = System.nanoTime();
this.consumer = consumer;
}

@Override
protected void invokeEvent(@NotNull EventManager manager, @NotNull T event) {
consumer.accept(event);
}

@Override
public int hashCode() {
return Long.hashCode(id);
}

@Override
public boolean equals(Object obj) {
return obj instanceof RawHandler<?> rh && rh.id==this.id;
}
}

0 comments on commit 1debeaf

Please sign in to comment.