Kaynağa Gözat

Add MutableAutoCommand.

pull/125/head
Greg Holmes 9 yıl önce
ebeveyn
işleme
9b69179b09

+ 4
- 1
src/com/dmdirc/commandparser/auto/AutoCommand.java Dosyayı Görüntüle

@@ -28,6 +28,8 @@ import com.google.common.base.MoreObjects;
28 28
 import java.util.Objects;
29 29
 import java.util.Optional;
30 30
 
31
+import javax.annotation.Nonnull;
32
+
31 33
 /**
32 34
  * Describes a command that is executed automatically in response to either the client opening, or a
33 35
  * server connecting.
@@ -47,7 +49,7 @@ public class AutoCommand {
47 49
             final Optional<String> server,
48 50
             final Optional<String> network,
49 51
             final Optional<String> profile,
50
-            final String response) {
52
+            @Nonnull final String response) {
51 53
         this.server = server;
52 54
         this.network = network;
53 55
         this.profile = profile;
@@ -66,6 +68,7 @@ public class AutoCommand {
66 68
         return profile;
67 69
     }
68 70
 
71
+    @Nonnull
69 72
     public String getResponse() {
70 73
         return response;
71 74
     }

+ 122
- 0
src/com/dmdirc/ui/core/autocommands/MutableAutoCommand.java Dosyayı Görüntüle

@@ -0,0 +1,122 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.ui.core.autocommands;
24
+
25
+import com.dmdirc.commandparser.auto.AutoCommand;
26
+
27
+import com.google.common.base.MoreObjects;
28
+
29
+import java.util.Objects;
30
+import java.util.Optional;
31
+
32
+import javax.annotation.Nonnull;
33
+
34
+/**
35
+ * Mutable version of an {@link AutoCommand}.
36
+ */
37
+public class MutableAutoCommand {
38
+
39
+    private Optional<String> server;
40
+    private Optional<String> network;
41
+    private Optional<String> profile;
42
+    private String response;
43
+
44
+    public MutableAutoCommand(
45
+            final Optional<String> server,
46
+            final Optional<String> network,
47
+            final Optional<String> profile,
48
+            @Nonnull final String response) {
49
+        this.server = server;
50
+        this.network = network;
51
+        this.profile = profile;
52
+        this.response = response;
53
+    }
54
+
55
+    public Optional<String> getServer() {
56
+        return server;
57
+    }
58
+
59
+    public void setServer(final Optional<String> server) {
60
+        this.server = server;
61
+    }
62
+
63
+    public Optional<String> getNetwork() {
64
+        return network;
65
+    }
66
+
67
+    public void setNetwork(final Optional<String> network) {
68
+        this.network = network;
69
+    }
70
+
71
+    public Optional<String> getProfile() {
72
+        return profile;
73
+    }
74
+
75
+    public void setProfile(final Optional<String> profile) {
76
+        this.profile = profile;
77
+    }
78
+
79
+    @Nonnull
80
+    public String getResponse() {
81
+        return response;
82
+    }
83
+
84
+    public void setResponse(@Nonnull final String response) {
85
+        this.response = response;
86
+    }
87
+
88
+    public AutoCommand getAutoCommand() {
89
+        return new AutoCommand(server, network, profile, response);
90
+    }
91
+
92
+    @Override
93
+    public boolean equals(final Object object) {
94
+        if (object == null) {
95
+            return false;
96
+        }
97
+        if (getClass() != object.getClass()) {
98
+            return false;
99
+        }
100
+        final MutableAutoCommand command = (MutableAutoCommand) object;
101
+        return  Objects.equals(server, command.getServer())
102
+                && Objects.equals(network, command.getNetwork())
103
+                && Objects.equals(profile, command.getProfile())
104
+                && Objects.equals(response, command.getResponse());
105
+
106
+    }
107
+
108
+    @Override
109
+    public int hashCode() {
110
+        return Objects.hash(server, network, profile, response);
111
+    }
112
+
113
+    @Override
114
+    public String toString() {
115
+        return MoreObjects.toStringHelper(this)
116
+                .add("Connection", server)
117
+                .add("Network", network)
118
+                .add("Profile", profile)
119
+                .add("Response", response)
120
+                .toString();
121
+    }
122
+}

Loading…
İptal
Kaydet