Przeglądaj źródła

extract component methods

Patrick Glavin 6 lat temu
rodzic
commit
5963843660
1 zmienionych plików z 24 dodań i 14 usunięć
  1. 24
    14
      Client/src/main/java/MessageSender.java

+ 24
- 14
Client/src/main/java/MessageSender.java Wyświetl plik

@@ -1,9 +1,11 @@
1 1
 import java.util.List;
2 2
 
3 3
 public class MessageSender implements Runnable{
4
-    List<String> list;
5
-    User user;
6
-    YouAreEll webber;
4
+    private List<String> list;
5
+    private User user;
6
+    private YouAreEll webber;
7
+    private Message message;
8
+    private String sentence = "";
7 9
 
8 10
     public MessageSender(List<String> list, User user, YouAreEll webber) {
9 11
         this.list = list;
@@ -12,25 +14,33 @@ public class MessageSender implements Runnable{
12 14
     }
13 15
 
14 16
     public void run() {
15
-        Message message;
16
-        String sentence = "";
17
-        for (int i = 2; i < list.size(); i++) {
18
-            sentence += list.get(i) + " ";
17
+        buildSentence();
18
+        buildMessage();
19
+        String results = webber.send_message(message);
20
+        simulateLag();
21
+        SimpleShell.prettyPrintMessage(results);
22
+    }
23
+
24
+    private void simulateLag() {
25
+        try {
26
+            Thread.sleep(10000);
27
+        } catch (InterruptedException e){
28
+            e.printStackTrace();
19 29
         }
30
+    }
20 31
 
21
-        sentence = sentence.substring(0, sentence.length()-1);
32
+    private void buildMessage() {
22 33
         if (list.get(1).equalsIgnoreCase("group")){
23 34
             message = new Message(user.getGithub(), "", sentence);
24 35
         } else {
25 36
             message = new Message(user.getGithub(), list.get(1), sentence);
26 37
         }
38
+    }
27 39
 
28
-        String results = webber.send_message(message);
29
-        try {
30
-            Thread.sleep(10000);
31
-        } catch (InterruptedException e){
32
-            e.printStackTrace();
40
+    private void buildSentence() {
41
+        for (int i = 2; i < list.size(); i++) {
42
+            sentence += list.get(i) + " ";
33 43
         }
34
-        SimpleShell.prettyPrintMessage(results);
44
+        sentence = sentence.substring(0, sentence.length()-1);
35 45
     }
36 46
 }