Commit 67d33bd9302bd6dad07d02b32918363491a6a650
1 parent
ba1cc312
HandlerList add OR_BREAK_ON_TRUE logic op - closes #62
Showing
1 changed file
with
36 additions
and
8 deletions
java/common/com/mumfrey/liteloader/core/event/HandlerList.java
@@ -47,31 +47,59 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T | @@ -47,31 +47,59 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T | ||
47 | /** | 47 | /** |
48 | * Logical OR applied between handlers, return FALSE unless one or more handlers returns TRUE | 48 | * Logical OR applied between handlers, return FALSE unless one or more handlers returns TRUE |
49 | */ | 49 | */ |
50 | - OR, | 50 | + OR(true, false), |
51 | + | ||
52 | + /** | ||
53 | + * Logical OR, returns TRUE at the first handler to return TRUE and doesn't process any further handlers | ||
54 | + */ | ||
55 | + OR_BREAK_ON_TRUE(true, true), | ||
51 | 56 | ||
52 | /** | 57 | /** |
53 | * Logical OR, but with the difference than an EMPTY handler list will return TRUE | 58 | * Logical OR, but with the difference than an EMPTY handler list will return TRUE |
54 | */ | 59 | */ |
55 | - OR_ASSUME_TRUE, | 60 | + OR_ASSUME_TRUE(true, false, true), |
56 | 61 | ||
57 | /** | 62 | /** |
58 | * Logical AND, returns TRUE if the list is empty or if all handlers return TRUE | 63 | * Logical AND, returns TRUE if the list is empty or if all handlers return TRUE |
59 | */ | 64 | */ |
60 | - AND, | 65 | + AND(false, false), |
61 | 66 | ||
62 | /** | 67 | /** |
63 | * Logical AND, returns FALSE at the first handler to return FALSE and doesn't process any further handlers | 68 | * Logical AND, returns FALSE at the first handler to return FALSE and doesn't process any further handlers |
64 | */ | 69 | */ |
65 | - AND_BREAK_ON_FALSE; | 70 | + AND_BREAK_ON_FALSE(false, true); |
71 | + | ||
72 | + private final boolean isOr; | ||
73 | + | ||
74 | + private final boolean breakOnMatch; | ||
75 | + | ||
76 | + private final boolean assumeTrue; | ||
77 | + | ||
78 | + private ReturnLogicOp(boolean isOr, boolean breakOnMatch) | ||
79 | + { | ||
80 | + this(isOr, breakOnMatch, false); | ||
81 | + } | ||
82 | + | ||
83 | + private ReturnLogicOp(boolean isOr, boolean breakOnMatch, boolean assumeTrue) | ||
84 | + { | ||
85 | + this.isOr = isOr; | ||
86 | + this.breakOnMatch = breakOnMatch; | ||
87 | + this.assumeTrue = assumeTrue; | ||
88 | + } | ||
66 | 89 | ||
67 | boolean isOr() | 90 | boolean isOr() |
68 | { | 91 | { |
69 | - return this == OR || this == OR_ASSUME_TRUE; | 92 | + return this.isOr; |
93 | + } | ||
94 | + | ||
95 | + public boolean breakOnMatch() | ||
96 | + { | ||
97 | + return this.breakOnMatch; | ||
70 | } | 98 | } |
71 | 99 | ||
72 | boolean assumeTrue() | 100 | boolean assumeTrue() |
73 | { | 101 | { |
74 | - return this == OR_ASSUME_TRUE; | 102 | + return this.assumeTrue; |
75 | } | 103 | } |
76 | } | 104 | } |
77 | 105 | ||
@@ -813,7 +841,7 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T | @@ -813,7 +841,7 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T | ||
813 | private void populateBooleanInvokationChain(ClassNode classNode, MethodNode method, Type[] args) | 841 | private void populateBooleanInvokationChain(ClassNode classNode, MethodNode method, Type[] args) |
814 | { | 842 | { |
815 | boolean isOrOperation = this.logicOp.isOr(); | 843 | boolean isOrOperation = this.logicOp.isOr(); |
816 | - boolean breakOnFalse = this.logicOp == ReturnLogicOp.AND_BREAK_ON_FALSE; | 844 | + boolean breakOnMatch = this.logicOp.breakOnMatch(); |
817 | int initialValue = isOrOperation && (!this.logicOp.assumeTrue() || this.size > 0) ? Opcodes.ICONST_0 : Opcodes.ICONST_1; | 845 | int initialValue = isOrOperation && (!this.logicOp.assumeTrue() || this.size > 0) ? Opcodes.ICONST_0 : Opcodes.ICONST_1; |
818 | int localIndex = this.getFirstLocalIndex(args); | 846 | int localIndex = this.getFirstLocalIndex(args); |
819 | 847 | ||
@@ -830,7 +858,7 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T | @@ -830,7 +858,7 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T | ||
830 | LabelNode lbl = new LabelNode(); | 858 | LabelNode lbl = new LabelNode(); |
831 | method.instructions.add(new JumpInsnNode(jumpCondition, lbl)); // jump over the set/return based on the condition | 859 | method.instructions.add(new JumpInsnNode(jumpCondition, lbl)); // jump over the set/return based on the condition |
832 | method.instructions.add(new InsnNode(semaphore)); // push TRUE or FALSE onto the stack | 860 | method.instructions.add(new InsnNode(semaphore)); // push TRUE or FALSE onto the stack |
833 | - method.instructions.add(breakOnFalse ? new InsnNode(Opcodes.IRETURN) : new VarInsnNode(Opcodes.ISTORE, localIndex)); // set local or return | 861 | + method.instructions.add(breakOnMatch ? new InsnNode(Opcodes.IRETURN) : new VarInsnNode(Opcodes.ISTORE, localIndex)); // set local or return |
834 | method.instructions.add(lbl); // jump here | 862 | method.instructions.add(lbl); // jump here |
835 | } | 863 | } |
836 | 864 |