You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandType.java 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.commandparser;
  23. import com.dmdirc.commandparser.commands.ChannelCommand;
  24. import com.dmdirc.commandparser.commands.ChatCommand;
  25. import com.dmdirc.commandparser.commands.Command;
  26. import com.dmdirc.commandparser.commands.GlobalCommand;
  27. import com.dmdirc.commandparser.commands.QueryCommand;
  28. import com.dmdirc.commandparser.commands.ServerCommand;
  29. /**
  30. * Defines the possible targets for commands.
  31. *
  32. * @author chris
  33. */
  34. public enum CommandType {
  35. /** A global command, which may be executed anywhere. */
  36. TYPE_GLOBAL,
  37. /** A server command, which only makes sense in the context of a connection. */
  38. TYPE_SERVER,
  39. /** A chat command, which needs a MessageTarget to make sense. */
  40. TYPE_CHAT,
  41. /** A channel command. */
  42. TYPE_CHANNEL,
  43. /** A query command. */
  44. TYPE_QUERY;
  45. /**
  46. * Looks up the command type for the specified command, by inspecting its
  47. * class.
  48. *
  49. * @param command The command to look up
  50. * @return The type of the specified command
  51. */
  52. public static CommandType fromCommand(final Command command) {
  53. if (command instanceof GlobalCommand) {
  54. return TYPE_GLOBAL;
  55. } else if (command instanceof ServerCommand) {
  56. return TYPE_SERVER;
  57. } else if (command instanceof ChatCommand) {
  58. return TYPE_CHAT;
  59. } else if (command instanceof ChannelCommand) {
  60. return TYPE_CHANNEL;
  61. } else if (command instanceof QueryCommand) {
  62. return TYPE_QUERY;
  63. } else {
  64. return null;
  65. }
  66. }
  67. /** {@inheritDoc} */
  68. @Override
  69. public String toString() {
  70. switch (this) {
  71. case TYPE_CHANNEL:
  72. return "Channel";
  73. case TYPE_CHAT:
  74. return "Chat";
  75. case TYPE_GLOBAL:
  76. return "Global";
  77. case TYPE_QUERY:
  78. return "Query";
  79. case TYPE_SERVER:
  80. return "Server";
  81. default:
  82. return "Unknown";
  83. }
  84. }
  85. }