1 20 package org.apache.mina.example.chat; 21 22 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 } 61 | Popular Tags |