File Source: CommandType.java
1 /*
2 * Copyright (c) 2006-2009 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
23 package com.dmdirc.commandparser;
24
25 import com.dmdirc.commandparser.commands.ChannelCommand;
26 import com.dmdirc.commandparser.commands.ChatCommand;
27 import com.dmdirc.commandparser.commands.Command;
28 import com.dmdirc.commandparser.commands.GlobalCommand;
29 import com.dmdirc.commandparser.commands.QueryCommand;
30 import com.dmdirc.commandparser.commands.ServerCommand;
31
32 /**
33 * Defines the possible targets for commands.
34 *
35 * @author chris
36 */
/*
P/P * Method: void com.dmdirc.commandparser.CommandType(String, int)
*/
37 public enum CommandType {
38
39 /** A global command, which may be executed anywhere. */
/*
P/P * Method: com.dmdirc.commandparser.CommandType__static_init
*
* Postconditions:
* $VALUES == &new CommandType[](CommandType__static_init#6)
* TYPE_CHANNEL == &new CommandType(CommandType__static_init#4)
* $VALUES[3] == &new CommandType(CommandType__static_init#4)
* TYPE_CHAT == &new CommandType(CommandType__static_init#3)
* $VALUES[2] == &new CommandType(CommandType__static_init#3)
* TYPE_GLOBAL == &new CommandType(CommandType__static_init#1)
* $VALUES[0] == &new CommandType(CommandType__static_init#1)
* TYPE_QUERY == &new CommandType(CommandType__static_init#5)
* $VALUES[4] == &new CommandType(CommandType__static_init#5)
* TYPE_SERVER == &new CommandType(CommandType__static_init#2)
* ...
*/
40 TYPE_GLOBAL,
41 /** A server command, which only makes sense in the context of a connection. */
42 TYPE_SERVER,
43 /** A chat command, which needs a MessageTarget to make sense. */
44 TYPE_CHAT,
45 /** A channel command. */
46 TYPE_CHANNEL,
47 /** A query command. */
48 TYPE_QUERY;
49
50 /**
51 * Looks up the command type for the specified command, by inspecting its
52 * class.
53 *
54 * @param command The command to look up
55 * @return The type of the specified command
56 */
57 public static CommandType fromCommand(final Command command) {
/*
P/P * Method: CommandType fromCommand(Command)
*
* Postconditions:
* return_value in Addr_Set{null,&new CommandType(CommandType__static_init#5),&new CommandType(CommandType__static_init#4),&new CommandType(CommandType__static_init#3),&new CommandType(CommandType__static_init#2),&new CommandType(CommandType__static_init#1)}
*/
58 if (command instanceof GlobalCommand) {
59 return TYPE_GLOBAL;
60 } else if (command instanceof ServerCommand) {
61 return TYPE_SERVER;
62 } else if (command instanceof ChatCommand) {
63 return TYPE_CHAT;
64 } else if (command instanceof ChannelCommand) {
65 return TYPE_CHANNEL;
66 } else if (command instanceof QueryCommand) {
67 return TYPE_QUERY;
68 } else {
69 return null;
70 }
71 }
72
73 /**
74 * Retrieves an array of component types that make up this command type.
75 * Generally this will only contain the type itself, but some commands may
76 * be registered in multiple queues (such as CHANNEL commands going into
77 * both CHAT and CHANNEL queues). Note that for obvious reasons there is
78 * no recursion done on the values returned here.
79 *
80 * @since 0.6.3m1
81 * @return An array of types which this type should be registered as.
82 */
83 public CommandType[] getComponentTypes() {
/*
P/P * Method: CommandType[] getComponentTypes()
*
* Postconditions:
* return_value in Addr_Set{&new CommandType[](getComponentTypes#2),&new CommandType[](getComponentTypes#1)}
* new CommandType[](getComponentTypes#1) num objects <= 1
* new CommandType[](getComponentTypes#1).length == 2
* new CommandType[](getComponentTypes#1)[0] == this
* new CommandType[](getComponentTypes#1)[0] != null
* new CommandType[](getComponentTypes#1)[1] == &new CommandType(CommandType__static_init#3)
* new CommandType[](getComponentTypes#2) num objects <= 1
* new CommandType[](getComponentTypes#2).length == 1
* new CommandType[](getComponentTypes#2)[0] == this
* new CommandType[](getComponentTypes#2)[0] != null
*/
84 if (this == TYPE_CHANNEL || this == TYPE_QUERY) {
85 return new CommandType[]{this, TYPE_CHAT};
86 } else {
87 return new CommandType[]{this};
88 }
89 }
90
91 /** {@inheritDoc} */
92 @Override
93 public String toString() {
/*
P/P * Method: String toString()
*
* Preconditions:
* (soft) init'ed(com.dmdirc.commandparser.CommandType$1__static_init.new int[](CommandType$1__static_init#1)[...])
*
* Presumptions:
* com.dmdirc.commandparser.CommandType:ordinal(...)@94 in {0..4}
* values(...).length - com.dmdirc.commandparser.CommandType:ordinal(...)@94 in range
*
* Postconditions:
* return_value in Addr_Set{&"Channel",&"Chat",&"Global",&"Query",&"Server",&"Unknown"}
*
* Test Vectors:
* com.dmdirc.commandparser.CommandType$1__static_init.new int[](CommandType$1__static_init#1)[...]: {1}, {2}, {3}, {4}, {5}, {-231..0, 6..232-1}
*/
94 switch (this) {
95 case TYPE_CHANNEL:
96 return "Channel";
97 case TYPE_CHAT:
98 return "Chat";
99 case TYPE_GLOBAL:
100 return "Global";
101 case TYPE_QUERY:
102 return "Query";
103 case TYPE_SERVER:
104 return "Server";
105 default:
106 return "Unknown";
107 }
108 }
109 }
SofCheck Inspector Build Version : 2.17854
| CommandType.java |
2009-Jun-25 01:54:24 |
| CommandType.class |
2009-Sep-02 17:04:12 |
| CommandType$1.class |
2009-Sep-02 17:04:12 |