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:
parent
2c524fa90a
commit
0a4f25f244
1 changed files with 8 additions and 5 deletions
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue