Remove generics in EventHandler
As part of implementing #1016 (closed), a problem that has some deep consequences appeared. As the EventHandler
interface is parameterized with the type of event detector, the signature of the getHandler
method depends on the handler. So there is a circular dependency, with the handler depending on the detector and the detector depending on the handler. I tried several approaches to solve this and failed miserably. It became more and more complex with things like
public interface EventDetector<D extends EventDetector<D, H>, H extends EventHandler<D, H>> {
...
}
public interface EventHandler<D extends EventDetector<D, H>, H extends EventHandler<D, H>> {
....
}
public abstract class AbstractDetector<T extends AbstractDetector<T, D, H>,
D extends EventDetector<D, H>,
H extends EventHandler<D, H>>
implements EventDetector<D, H> {
...
}
In some cases, at least in the tests, we sometime set up generic handlers (declared to implement EventHandler<EventDetector>
) to specific detectors. This is probably the reason why in some methods we have to make use of super in the signature. At other places, we have a roughly reversed use case, with generic detectors that could wrap other detectors (boolean detectors, shifter…). We also have an EventMultipleHandler
were one detector has several handlers.
I was not able to deal with all these uses cases and finally gave up.
Looking back at the root cause, it seems to be related to the event detector type in the signature of the init
, eventOccurred
and resetState
methods in the handler. In fact, all cases I have ever encountered fall in two categories only:
- general handlers that do not even use the detector passed as an argument
- highly specific handlers that work only with exactly one type and already know this type
The current API is devoted to this second case, and enforces the type in the signature. It does not address the first case at all.
This change intends to simplify the API and have EventHandler
made non-generic, use just EventDetector
in the signature of the methods, and let the implementation of the handler do a cast if required when it really needs to recover some data from the detector.
This change simplifies also a lot the API, mainly for people having to implement the create method from AbstractDetector
with its currently puzzling signature.