fix event bus priority (it was inconsistent with equals)

the ordering was correct, but it sometimes returned 0 even when not equal
This commit is contained in:
Daniella / Tove 2024-05-30 22:12:43 +02:00
parent 2c524fa90a
commit 0a4f25f244
Signed by: TudbuT
GPG key ID: B3CF345217F202D3

View file

@ -1,7 +1,6 @@
package com.baseband.client.event;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@ -25,11 +24,15 @@ public class EventManager {
subscriberMethods.add(new SubscriberMethod(subscriber, method));
subscriberMethods.sort((o1, o2) -> {
if (o1.method.isAnnotationPresent(Priority.class) && o2.method.isAnnotationPresent(Priority.class)) {
return o1.method.getAnnotation(Priority.class).priority() < o2.method.getAnnotation(Priority.class).priority() ? -1 : 1;
} else {
return 0;
int p1 = 0;
int p2 = 0;
if (o1.method.isAnnotationPresent(Priority.class)) {
p1 = o1.method.getDeclaredAnnotation(Priority.class).priority();
}
if (o2.method.isAnnotationPresent(Priority.class)) {
p2 = o2.method.getDeclaredAnnotation(Priority.class).priority();
}
return Integer.compare(p1, p2);
});
}
}