Slide 57
Slide 57 text
Create the Mapple Decorator
@Decorator
@Priority(Interceptor.Priority.APPLICATION + 10)
public abstract class MapplePoliteDecorator implements ChatService {
static final Map DICTIONARY = new HashMap() {{
put("fuck", "duck");
put("crap", "trap");
put("idiots", "world");
put("cartman", "Stan");
}};
@Inject
@Delegate
private ChatService delegateService;
@Inject
@BadWord
private Event events;
@Override
public void processMessage(String message) {
String lmessage = message.toLowerCase();
String res = message;
for (String word : DICTIONARY.keySet())
if (lmessage.indexOf(word) > -1) {
res = res.replaceAll("(?i)" + word, DICTIONARY.get(word));
events.fire(word);
}
delegateService.processMessage(res);
}
}