Browse Source

Merge pull request #21 from csmith/master

Remove ActionListener.
pull/23/head
Greg Holmes 9 years ago
parent
commit
d07be1e77c

+ 9
- 47
src/com/dmdirc/actions/ActionManager.java View File

@@ -32,7 +32,6 @@ import com.dmdirc.events.DMDircEvent;
32 32
 import com.dmdirc.events.DisplayableEvent;
33 33
 import com.dmdirc.events.UserErrorEvent;
34 34
 import com.dmdirc.interfaces.ActionController;
35
-import com.dmdirc.interfaces.ActionListener;
36 35
 import com.dmdirc.interfaces.actions.ActionComparison;
37 36
 import com.dmdirc.interfaces.actions.ActionComponent;
38 37
 import com.dmdirc.interfaces.actions.ActionType;
@@ -50,6 +49,7 @@ import java.nio.file.Files;
50 49
 import java.nio.file.Path;
51 50
 import java.nio.file.Paths;
52 51
 import java.util.ArrayList;
52
+import java.util.Collection;
53 53
 import java.util.Collections;
54 54
 import java.util.HashMap;
55 55
 import java.util.List;
@@ -58,6 +58,7 @@ import java.util.Set;
58 58
 
59 59
 import javax.inject.Provider;
60 60
 
61
+import org.slf4j.Logger;
61 62
 import org.slf4j.LoggerFactory;
62 63
 
63 64
 import net.engio.mbassy.listener.Handler;
@@ -70,7 +71,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
70 71
  */
71 72
 public class ActionManager implements ActionController {
72 73
 
73
-    private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(ActionManager.class);
74
+    private static final Logger LOG = LoggerFactory.getLogger(ActionManager.class);
74 75
     /** The ActionManager Instance. */
75 76
     private static ActionManager me;
76 77
     /** The identity manager to load configuration from. */
@@ -82,11 +83,11 @@ public class ActionManager implements ActionController {
82 83
     /** Provider of an update manager. */
83 84
     private final Provider<UpdateManager> updateManagerProvider;
84 85
     /** A list of registered action types. */
85
-    private final List<ActionType> types = new ArrayList<>();
86
+    private final Collection<ActionType> types = new ArrayList<>();
86 87
     /** A list of registered action components. */
87
-    private final List<ActionComponent> components = new ArrayList<>();
88
+    private final Collection<ActionComponent> components = new ArrayList<>();
88 89
     /** A list of registered action comparisons. */
89
-    private final List<ActionComparison> comparisons = new ArrayList<>();
90
+    private final Collection<ActionComparison> comparisons = new ArrayList<>();
90 91
     /** A map linking types and a list of actions that're registered for them. */
91 92
     private final MapList<ActionType, Action> actions = new MapList<>();
92 93
     /** A map linking groups and a list of actions that're in them. */
@@ -95,8 +96,6 @@ public class ActionManager implements ActionController {
95 96
     private final Map<String, Object> locks = new HashMap<>();
96 97
     /** A map of the action type groups to the action types within. */
97 98
     private final MapList<String, ActionType> typeGroups = new MapList<>();
98
-    /** The listeners that we have registered. */
99
-    private final MapList<ActionType, ActionListener> listeners = new MapList<>();
100 99
     /** The global event bus to monitor. */
101 100
     private final DMDircMBassador eventBus;
102 101
     /** The directory to load and save actions in. */
@@ -367,24 +366,7 @@ public class ActionManager implements ActionController {
367 366
 
368 367
         LOG.trace("Calling listeners for event of type {}", type);
369 368
 
370
-        boolean res = false;
371
-
372
-        if (listeners.containsKey(type)) {
373
-            for (ActionListener listener : new ArrayList<>(listeners.get(type))) {
374
-                try {
375
-                    listener.processEvent(type, format, arguments);
376
-                } catch (Exception e) {
377
-                    eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM, e,
378
-                            "Error processing action: " + e.getMessage(), ""));
379
-                }
380
-            }
381
-        }
382
-
383
-        if (!killSwitch) {
384
-            res = triggerActions(type, format, arguments);
385
-        }
386
-
387
-        return !res;
369
+        return killSwitch || !triggerActions(type, format, arguments);
388 370
     }
389 371
 
390 372
     /**
@@ -402,10 +384,9 @@ public class ActionManager implements ActionController {
402 384
             final StringBuffer format, final Object... arguments) {
403 385
         checkNotNull(type);
404 386
 
405
-        boolean res = false;
406
-
407 387
         LOG.trace("Executing actions for event of type {}", type);
408 388
 
389
+        boolean res = false;
409 390
         if (actions.containsKey(type)) {
410 391
             for (Action action : new ArrayList<>(actions.get(type))) {
411 392
                 try {
@@ -495,7 +476,7 @@ public class ActionManager implements ActionController {
495 476
                 final Method method = methods[j];
496 477
                 if (method.getParameterTypes().length == 0
497 478
                         && method.getName().startsWith("get")
498
-                        && !method.getName().equals("getDisplayFormat")
479
+                        && !"getDisplayFormat".equals(method.getName())
499 480
                         && method.getReturnType().equals(target)
500 481
                         && Math.abs(j - i) < bestDistance) {
501 482
                     bestDistance = Math.abs(j - i);
@@ -687,23 +668,4 @@ public class ActionManager implements ActionController {
687 668
         Files.delete(path);
688 669
     }
689 670
 
690
-    @Override
691
-    public void registerListener(final ActionListener listener, final ActionType... types) {
692
-        for (ActionType type : types) {
693
-            listeners.add(type, listener);
694
-        }
695
-    }
696
-
697
-    @Override
698
-    public void unregisterListener(final ActionListener listener, final ActionType... types) {
699
-        for (ActionType type : types) {
700
-            listeners.remove(type, listener);
701
-        }
702
-    }
703
-
704
-    @Override
705
-    public void unregisterListener(final ActionListener listener) {
706
-        listeners.removeFromAll(listener);
707
-    }
708
-
709 671
 }

+ 0
- 23
src/com/dmdirc/interfaces/ActionController.java View File

@@ -192,14 +192,6 @@ public interface ActionController {
192 192
     @Precondition("None of the specified ActionComponents are null")
193 193
     void registerComponents(final ActionComponent[] comps);
194 194
 
195
-    /**
196
-     * Adds a new listener for the specified action type.
197
-     *
198
-     * @param types    The action types that are to be listened for
199
-     * @param listener The listener to be added
200
-     */
201
-    void registerListener(final ActionListener listener, final ActionType... types);
202
-
203 195
     /**
204 196
      * Registers the specified default setting for actions.
205 197
      *
@@ -253,19 +245,4 @@ public interface ActionController {
253 245
                     "ActionMetaType"})
254 246
     boolean triggerEvent(final ActionType type, final StringBuffer format, final Object... arguments);
255 247
 
256
-    /**
257
-     * Removes a listener for the specified action type.
258
-     *
259
-     * @param types    The action types that were being listened for
260
-     * @param listener The listener to be removed
261
-     */
262
-    void unregisterListener(final ActionListener listener, final ActionType... types);
263
-
264
-    /**
265
-     * Removes a listener for all action types.
266
-     *
267
-     * @param listener The listener to be removed
268
-     */
269
-    void unregisterListener(final ActionListener listener);
270
-
271 248
 }

+ 0
- 41
src/com/dmdirc/interfaces/ActionListener.java View File

@@ -1,41 +0,0 @@
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.interfaces;
24
-
25
-import com.dmdirc.interfaces.actions.ActionType;
26
-
27
-/**
28
- * Defines the method that has to be implemented by classes wanting to receive action events.
29
- */
30
-public interface ActionListener {
31
-
32
-    /**
33
-     * Processes an action of the specified type.
34
-     *
35
-     * @param type      The type of the event to process
36
-     * @param format    The format of the message that's going to be displayed for the event
37
-     * @param arguments The arguments for the event
38
-     */
39
-    void processEvent(ActionType type, StringBuffer format, Object... arguments);
40
-
41
-}

Loading…
Cancel
Save