Parcourir la source

Add MutableAutoCommand.

pull/104/head
Greg Holmes il y a 9 ans
Parent
révision
3dfeba4a57

+ 13
- 11
src/com/dmdirc/commandparser/auto/AutoCommand.java Voir le fichier

@@ -22,9 +22,11 @@
22 22
 
23 23
 package com.dmdirc.commandparser.auto;
24 24
 
25
-import com.google.common.base.Objects;
25
+import com.google.common.base.MoreObjects;
26 26
 import com.google.common.base.Optional;
27 27
 
28
+import java.util.Objects;
29
+
28 30
 /**
29 31
  * Describes a command that is executed automatically in response to either the client opening, or a
30 32
  * server connecting.
@@ -32,13 +34,13 @@ import com.google.common.base.Optional;
32 34
 public class AutoCommand {
33 35
 
34 36
     /** The name of the server for connection events. */
35
-    private final Optional<String> server;
37
+    protected Optional<String> server;
36 38
     /** The name of the network for connection events. */
37
-    private final Optional<String> network;
39
+    protected Optional<String> network;
38 40
     /** The name of the profile for connection events. */
39
-    private final Optional<String> profile;
41
+    protected Optional<String> profile;
40 42
     /** The commands to execute. */
41
-    private final String response;
43
+    protected String response;
42 44
 
43 45
     public AutoCommand(
44 46
             final Optional<String> server,
@@ -76,21 +78,21 @@ public class AutoCommand {
76 78
             return false;
77 79
         }
78 80
         final AutoCommand command = (AutoCommand) object;
79
-        return  Objects.equal(server, command.getServer())
80
-                && Objects.equal(network, command.getNetwork())
81
-                && Objects.equal(profile, command.getProfile())
82
-                && Objects.equal(response, command.getResponse());
81
+        return  Objects.equals(server, command.getServer())
82
+                && Objects.equals(network, command.getNetwork())
83
+                && Objects.equals(profile, command.getProfile())
84
+                && Objects.equals(response, command.getResponse());
83 85
 
84 86
     }
85 87
 
86 88
     @Override
87 89
     public int hashCode() {
88
-        return Objects.hashCode(server, network, profile, response);
90
+        return Objects.hash(server, network, profile, response);
89 91
     }
90 92
 
91 93
     @Override
92 94
     public String toString() {
93
-        return Objects.toStringHelper(this)
95
+        return MoreObjects.toStringHelper(this)
94 96
                 .add("Connection", server)
95 97
                 .add("Network", network)
96 98
                 .add("Profile", profile)

+ 60
- 0
src/com/dmdirc/commandparser/auto/MutableAutoCommand.java Voir le fichier

@@ -0,0 +1,60 @@
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.commandparser.auto;
24
+
25
+import com.google.common.base.Optional;
26
+
27
+/**
28
+ * Mutable version of an {@link AutoCommand}.
29
+ */
30
+public class MutableAutoCommand extends AutoCommand {
31
+
32
+    public MutableAutoCommand(final Optional<String> server,
33
+            final Optional<String> network,
34
+            final Optional<String> profile,
35
+            final String response) {
36
+        super(server, network, profile, response);
37
+    }
38
+
39
+    public void setServer(final Optional<String> server) {
40
+        this.server = server;
41
+    }
42
+
43
+    public void setNetwork(final Optional<String> network) {
44
+        this.network = network;
45
+    }
46
+
47
+    public void setProfile(final Optional<String> profile) {
48
+        this.profile = profile;
49
+    }
50
+
51
+    /**
52
+     * Sets the response to this auto command. This can be multi line and should not include
53
+     * command characters before the commands.
54
+     *
55
+     * @param response New response to execute
56
+     */
57
+    public void setResponse(final String response) {
58
+        this.response = response;
59
+    }
60
+}

Chargement…
Annuler
Enregistrer