If you think the Android project libgdx-chat-example listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package org.stofkat.chat.server;
/*fromwww.java2s.com*/import java.util.List;
import java.util.Map;
import org.stofkat.chat.common.actions.Action;
import org.stofkat.chat.common.results.Result;
import com.google.inject.Singleton;
@Singleton
publicclass DefaultActionHandlerRegistry implements InstanceActionHandlerRegistry {
privatefinal Map<Class<? extends Action<?>>, ActionHandler<?, ?>> handlers;
public DefaultActionHandlerRegistry() {
handlers = new java.util.HashMap<Class<? extends Action<?>>, ActionHandler<?, ?>>( 100 );
}
publicvoid addHandler( ActionHandler<?, ?> handler ) {
handlers.put( handler.getActionType(), handler );
}
publicboolean removeHandler( ActionHandler<?, ?> handler ) {
return handlers.remove( handler.getActionType() ) != null;
}
@SuppressWarnings("unchecked")
public <A extends Action<R>, R extends Result> ActionHandler<A, R> findHandler( A action ) {
return (org.stofkat.chat.server.ActionHandler<A, R> ) handlers.get( action.getClass() );
}
/**
* Sets the specified <tt>actionHandlers</tt> as the only action handler held by this registry instance
*
* @param actionHandlers the list of action handler to set
*/publicvoid setActionHandlers(List<ActionHandler<?,?>> actionHandlers) {
clearHandlers();
for ( ActionHandler<?,?> actionHandler : actionHandlers )
addHandler(actionHandler);
}
publicvoid clearHandlers() {
handlers.clear();
}
}