|
@@ -30,23 +30,19 @@ |
30 |
30 |
|
* flattened array with an escape clause to handle the rare case where we have |
31 |
31 |
|
* more handlers then expected. |
32 |
32 |
|
*/ |
33 |
|
- |
class JsHandlerRegistry extends JavaScriptObject |
34 |
|
- |
{ |
|
33 |
+ |
class JsHandlerRegistry extends JavaScriptObject { |
35 |
34 |
|
|
36 |
|
- |
public static JsHandlerRegistry create() |
37 |
|
- |
{ |
|
35 |
+ |
public static JsHandlerRegistry create() { |
38 |
36 |
|
return (JsHandlerRegistry) JavaScriptObject.createObject(); |
39 |
37 |
|
} |
40 |
38 |
|
|
41 |
39 |
|
/** |
42 |
40 |
|
* Required constructor. |
43 |
41 |
|
*/ |
44 |
|
- |
protected JsHandlerRegistry() |
45 |
|
- |
{ |
|
42 |
+ |
protected JsHandlerRegistry() { |
46 |
43 |
|
} |
47 |
44 |
|
|
48 |
|
- |
public final void addHandler( AbstractEvent.Type eventKey, EventHandler handler ) |
49 |
|
- |
{ |
|
45 |
+ |
public final void addHandler( AbstractEvent.Type eventKey, EventHandler handler ) { |
50 |
46 |
|
// The base is the equivalent to a c pointer into the flattened handler data |
51 |
47 |
|
// structure. |
52 |
48 |
|
int base = eventKey.hashCode(); |
|
@@ -54,16 +50,14 @@ |
54 |
50 |
|
|
55 |
51 |
|
// If we already have the maximum number of handlers we can store in the |
56 |
52 |
|
// flattened data structure, store the handlers in an external list instead. |
57 |
|
- |
if ( count == HandlerManager.EXPECTED_HANDLERS && isFlattened( base ) ) |
58 |
|
- |
{ |
|
53 |
+ |
if ( count == HandlerManager.EXPECTED_HANDLERS && isFlattened( base ) ) { |
59 |
54 |
|
unflatten( base ); |
60 |
55 |
|
} |
61 |
56 |
|
setHandler( base, count, handler, isFlattened( base ) ); |
62 |
57 |
|
setCount( base, count + 1 ); |
63 |
58 |
|
} |
64 |
59 |
|
|
65 |
|
- |
public final void clearHandlers( Type<?, ?> type ) |
66 |
|
- |
{ |
|
60 |
+ |
public final void clearHandlers( Type<?, ?> type ) { |
67 |
61 |
|
int base = type.hashCode(); |
68 |
62 |
|
// Clearing handlers is relatively unusual, so the cost of unflattening the |
69 |
63 |
|
// handler list is justified by the smaller code. |
|
@@ -74,15 +68,13 @@ |
74 |
68 |
|
setCount( base, 0 ); |
75 |
69 |
|
} |
76 |
70 |
|
|
77 |
|
- |
public final void fireEvent( AbstractEvent event ) |
78 |
|
- |
{ |
|
71 |
+ |
public final void fireEvent( AbstractEvent event ) { |
79 |
72 |
|
Type type = event.getType(); |
80 |
73 |
|
int base = type.hashCode(); |
81 |
74 |
|
int count = getCount( base ); |
82 |
75 |
|
boolean isFlattened = isFlattened( base ); |
83 |
76 |
|
|
84 |
|
- |
for ( int i = 0; i < count; i++ ) |
85 |
|
- |
{ |
|
77 |
+ |
for ( int i = 0; i < count; i++ ) { |
86 |
78 |
|
// Gets the given handler to fire. |
87 |
79 |
|
EventHandler handler = getHandler( base, i, isFlattened ); |
88 |
80 |
|
|
|
@@ -91,30 +83,25 @@ |
91 |
83 |
|
} |
92 |
84 |
|
} |
93 |
85 |
|
|
94 |
|
- |
public final EventHandler getHandler( AbstractEvent.Type eventKey, int index ) |
95 |
|
- |
{ |
|
86 |
+ |
public final EventHandler getHandler( AbstractEvent.Type eventKey, int index ) { |
96 |
87 |
|
int base = eventKey.hashCode(); |
97 |
88 |
|
int count = getCount( base ); |
98 |
|
- |
if ( index >= count ) |
99 |
|
- |
{ |
|
89 |
+ |
if ( index >= count ) { |
100 |
90 |
|
throw new IndexOutOfBoundsException( "index: " + index ); |
101 |
91 |
|
} |
102 |
92 |
|
return getHandler( base, index, isFlattened( base ) ); |
103 |
93 |
|
} |
104 |
94 |
|
|
105 |
|
- |
public final int getHandlerCount( AbstractEvent.Type eventKey ) |
106 |
|
- |
{ |
|
95 |
+ |
public final int getHandlerCount( AbstractEvent.Type eventKey ) { |
107 |
96 |
|
return getCount( eventKey.hashCode() ); |
108 |
97 |
|
} |
109 |
98 |
|
|
110 |
|
- |
public final void removeHandler( AbstractEvent.Type eventKey, EventHandler handler ) |
111 |
|
- |
{ |
|
99 |
+ |
public final void removeHandler( AbstractEvent.Type eventKey, EventHandler handler ) { |
112 |
100 |
|
int base = eventKey.hashCode(); |
113 |
101 |
|
|
114 |
102 |
|
// Removing a handler is unusual, so smaller code is preferable then |
115 |
103 |
|
// handling both flat and dangling list of pointers. |
116 |
|
- |
if ( isFlattened( base ) ) |
117 |
|
- |
{ |
|
104 |
+ |
if ( isFlattened( base ) ) { |
118 |
105 |
|
unflatten( base ); |
119 |
106 |
|
} |
120 |
107 |
|
boolean result = removeHelper( base, handler ); |