01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *
19: */
20: package org.apache.mina.example.chat;
21:
22: /**
23: * Encapsulates a chat command. Use {@link #valueOf(String)} to create an
24: * instance given a command string.
25: *
26: * @author The Apache MINA Project (dev@mina.apache.org)
27: * @version $Rev$, $Date$
28: */
29: public class ChatCommand {
30: public static final int LOGIN = 0;
31:
32: public static final int QUIT = 1;
33:
34: public static final int BROADCAST = 2;
35:
36: private final int num;
37:
38: private ChatCommand(int num) {
39: this .num = num;
40: }
41:
42: public int toInt() {
43: return num;
44: }
45:
46: public static ChatCommand valueOf(String s) {
47: s = s.toUpperCase();
48: if ("LOGIN".equals(s)) {
49: return new ChatCommand(LOGIN);
50: }
51: if ("QUIT".equals(s)) {
52: return new ChatCommand(QUIT);
53: }
54: if ("BROADCAST".equals(s)) {
55: return new ChatCommand(BROADCAST);
56: }
57:
58: throw new IllegalArgumentException("Unrecognized command: " + s);
59: }
60: }
|