I have a class to process events to broadcast
Public void processEvents(Event e) {
saveEvent(e);
broadcast(e);
}
However a requirement comes up that certain events (foo, bar, baz) should not be broadcasted. However this list should be configurable as tomorrow we may need to prevent ‘foobar’ from being broadcasted
To filter them I created a static initializer block:
Private static final Set<Events> filter = new HashSet<>();
Static {
Filter.put(“foo”);
Filter.put(“bar”);
Filter.put(“baz”);
}
Public void processEvents(Event e) {
saveEvent(e);
if (!filter.contains(e)) {
broadcast(e);
}
}
- Is this a valid / common use of static intializaer block ?
- Is there any better / other common way of creating such a configurable filter.
Aucun commentaire:
Enregistrer un commentaire