-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProtocol.java
70 lines (60 loc) · 1.34 KB
/
Protocol.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.StringTokenizer;
/**
* Protocol handles all the handshaking between Hosts and Client
*
* @author Jerrett Fowler
* @version 1.0 (September 2013)
*/
public class Protocol
{
private CommandWords commands;
/**
* Constructor for objects of class Protocol
*/
public Protocol()
{
commands = new CommandWords();
}
/**
* Get commands for protocol
*/
public Command getCommand(String input)
{
input = "";
String w1;
String w2;
String w3;
StringTokenizer tokenizer = new StringTokenizer(input);
if(tokenizer.hasMoreTokens())
{
w1 = tokenizer.nextToken(); //Word 1
}
else
{
w1 = null;
}
if(tokenizer.hasMoreTokens())
{
w2 = tokenizer.nextToken(); //Word 2
}
else
{
w2 = null;
}
if(tokenizer.hasMoreTokens())
{
w3 = tokenizer.nextToken(); //Word 3
}
else
{
w3 = null;
}
Command command = commands.getCommand(w1);
if(command != null)
{
command.setSecondWord(w2);
command.setThirdWord(w3);
}
return command;
}
}