ActionHandler.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.handler;
  16. import java.util.Map;
  17. import javolution.util.FastMap;
  18. import com.l2jserver.gameserver.model.L2Object.InstanceType;
  19. public class ActionHandler
  20. {
  21. private final Map<InstanceType, IActionHandler> _actions;
  22. public static ActionHandler getInstance()
  23. {
  24. return SingletonHolder._instance;
  25. }
  26. private ActionHandler()
  27. {
  28. _actions = new FastMap<InstanceType, IActionHandler>();
  29. }
  30. public void registerHandler(IActionHandler handler)
  31. {
  32. _actions.put(handler.getInstanceType(), handler);
  33. }
  34. public IActionHandler getHandler(InstanceType iType)
  35. {
  36. IActionHandler result = null;
  37. for (InstanceType t = iType; t != null; t = t.getParent())
  38. {
  39. result = _actions.get(t);
  40. if (result != null)
  41. break;
  42. }
  43. return result;
  44. }
  45. public int size()
  46. {
  47. return _actions.size();
  48. }
  49. @SuppressWarnings("synthetic-access")
  50. private static class SingletonHolder
  51. {
  52. protected static final ActionHandler _instance = new ActionHandler();
  53. }
  54. }