Bladeren bron

extract component methods

Patrick Glavin 6 jaren geleden
bovenliggende
commit
5963843660
1 gewijzigde bestanden met toevoegingen van 24 en 14 verwijderingen
  1. 24
    14
      Client/src/main/java/MessageSender.java

+ 24
- 14
Client/src/main/java/MessageSender.java Bestand weergeven

1
 import java.util.List;
1
 import java.util.List;
2
 
2
 
3
 public class MessageSender implements Runnable{
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
     public MessageSender(List<String> list, User user, YouAreEll webber) {
10
     public MessageSender(List<String> list, User user, YouAreEll webber) {
9
         this.list = list;
11
         this.list = list;
12
     }
14
     }
13
 
15
 
14
     public void run() {
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
         if (list.get(1).equalsIgnoreCase("group")){
33
         if (list.get(1).equalsIgnoreCase("group")){
23
             message = new Message(user.getGithub(), "", sentence);
34
             message = new Message(user.getGithub(), "", sentence);
24
         } else {
35
         } else {
25
             message = new Message(user.getGithub(), list.get(1), sentence);
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
 }