Skip to content

Commit fb176f0

Browse files
RequestSender
1 parent 3941b24 commit fb176f0

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package Client;
2+
3+
import Client.Exception.ConnectionException;
4+
import Common.Data.Worker;
5+
import Common.Parser.UserInputParser;
6+
import Common.Request;
7+
import Server.Server;
8+
9+
import java.io.ByteArrayInputStream;
10+
import java.io.ByteArrayOutputStream;
11+
import java.io.IOException;
12+
import java.io.ObjectOutputStream;
13+
import java.net.InetSocketAddress;
14+
import java.nio.channels.SocketChannel;
15+
import java.util.Scanner;
16+
17+
/**
18+
* Created by IntelliJ IDEA.
19+
*
20+
* @author Behruz Mansurov
21+
*/
22+
public class RequestSender {
23+
private boolean exit = false;
24+
private final Client sender;
25+
public RequestSender(int PORT) {
26+
sender = new Client(PORT);
27+
}
28+
29+
public void parser() {
30+
String command;
31+
String[] userCommand;
32+
Scanner scanner = new Scanner(System.in);
33+
UserInputParser userInputParser = new UserInputParser();
34+
while (!exit) {
35+
System.out.println("Введите команду:");
36+
command = scanner.nextLine();
37+
userCommand = command.trim().split(" ", 2);
38+
try {
39+
switch (userCommand[0]) {
40+
case "help":
41+
case "info":
42+
case "show":
43+
case "clear":
44+
case "remove_first":
45+
case "remove_last":
46+
case "shuffle":
47+
case "max_by_id":
48+
sender.sendRequest(new Request(userCommand[0]));
49+
break;
50+
case "add":
51+
Worker worker = new Worker(userInputParser.inputName(), userInputParser.inputCoordinates(), userInputParser.inputSalary(), userInputParser.inputStartDate(), userInputParser.inputEndDate(), userInputParser.inputStatus(), userInputParser.inputOrganization());
52+
sender.sendRequest(new Request(userCommand[0], worker));
53+
break;
54+
// case "update_by_id":
55+
// workerManager.updateById(userInputParser.inputId(), userInputParser.inputId());
56+
// break;
57+
case "remove_by_id":
58+
sender.sendRequest(new Request(userCommand[0], userInputParser.inputId()));
59+
break;
60+
case "exit":
61+
exit = true;
62+
break;
63+
case "remove_any_by_start_date":
64+
sender.sendRequest(new Request(userCommand[0],userInputParser.inputStartDate()));
65+
break;
66+
case "count_less_than_organization":
67+
sender.sendRequest(new Request(userCommand[0],userInputParser.inputOrganization()));
68+
break;
69+
default:
70+
System.out.println("Введите правельную команду");
71+
break;
72+
}
73+
} catch (ArrayIndexOutOfBoundsException ex) {
74+
System.out.println("Отсутствует аргумент");
75+
}
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)