Browse Source

More HashTable removal

Make the LoggingPlugin less stupid

Change-Id: I12b2ca7b6a3f61a20015cebbcd81f4efed34a83f
Reviewed-on: http://gerrit.dmdirc.com/1360
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
tags/0.6.4
Chris Smith 14 years ago
parent
commit
82c28d67d7

+ 10
- 20
src/com/dmdirc/addons/logging/LoggingPlugin.java View File

@@ -47,6 +47,7 @@ import com.dmdirc.parser.interfaces.ClientInfo;
47 47
 import com.dmdirc.parser.interfaces.Parser;
48 48
 import com.dmdirc.plugins.Plugin;
49 49
 import com.dmdirc.ui.messages.Styliser;
50
+import com.dmdirc.util.StreamUtil;
50 51
 
51 52
 import java.awt.Color;
52 53
 import java.io.BufferedWriter;
@@ -59,11 +60,11 @@ import java.security.MessageDigest;
59 60
 import java.security.NoSuchAlgorithmException;
60 61
 import java.text.DateFormat;
61 62
 import java.text.SimpleDateFormat;
63
+import java.util.Collections;
62 64
 import java.util.Date;
63
-import java.util.Hashtable;
65
+import java.util.HashMap;
64 66
 import java.util.Map;
65 67
 import java.util.Stack;
66
-
67 68
 import java.util.Timer;
68 69
 import java.util.TimerTask;
69 70
 
@@ -108,19 +109,13 @@ public class LoggingPlugin extends Plugin implements ActionListener,
108 109
     /** Timer used to close idle files */
109 110
     protected Timer idleFileTimer;
110 111
 
111
-    /** Hashtable of open files. */
112
-    protected final Map<String, OpenFile> openFiles = new Hashtable<String, OpenFile>();
112
+    /** Map of open files. */
113
+    protected final Map<String, OpenFile> openFiles
114
+            = Collections.synchronizedMap(new HashMap<String, OpenFile>());
113 115
 
114 116
     /** Date format used for "File Opened At" log. */
115 117
     final DateFormat openedAtFormat = new SimpleDateFormat("EEEE MMMM dd, yyyy - HH:mm:ss");
116 118
 
117
-    /**
118
-     * Creates a new instance of the Logging Plugin.
119
-     */
120
-    public LoggingPlugin() {
121
-        super();
122
-    }
123
-
124 119
     /** {@inheritDoc} */
125 120
     @Override
126 121
     public void domainUpdated() {
@@ -192,15 +187,10 @@ public class LoggingPlugin extends Plugin implements ActionListener,
192 187
         final long oldestTime = System.currentTimeMillis() - 3480000;
193 188
 
194 189
         synchronized (openFiles) {
195
-            for (String filename : (new Hashtable<String, OpenFile>(openFiles)).keySet()) {
196
-                OpenFile file = openFiles.get(filename);
197
-                if (file.lastUsedTime < oldestTime) {
198
-                    try {
199
-                        file.writer.close();
200
-                        openFiles.remove(filename);
201
-                    } catch (IOException e) {
202
-                        Logger.userError(ErrorLevel.LOW, "Unable to close idle file (File: " + filename + ")");
203
-                    }
190
+            for (Map.Entry<String, OpenFile> entry : openFiles.entrySet()) {
191
+                if (entry.getValue().lastUsedTime < oldestTime) {
192
+                    StreamUtil.close(entry.getValue().writer);
193
+                    openFiles.remove(entry.getKey());
204 194
                 }
205 195
             }
206 196
         }

+ 9
- 11
src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/ChannelModesPane.java View File

@@ -29,7 +29,7 @@ import com.dmdirc.addons.ui_swing.components.text.TextLabel;
29 29
 import com.dmdirc.parser.interfaces.Parser;
30 30
 
31 31
 import java.awt.Insets;
32
-import java.util.Hashtable;
32
+import java.util.HashMap;
33 33
 import java.util.Map;
34 34
 import java.util.TreeSet;
35 35
 
@@ -87,12 +87,10 @@ public final class ChannelModesPane extends JPanel {
87 87
 
88 88
         final String booleanModes = parser.getBooleanChannelModes();
89 89
         final String ourBooleanModes = channel.getChannelInfo().getModes();
90
-        final String paramModes =
91
-                parser.getParameterChannelModes() + parser.
92
-                getDoubleParameterChannelModes();
90
+        final String paramModes = parser.getParameterChannelModes()
91
+                + parser.getDoubleParameterChannelModes();
93 92
 
94
-        modeCheckBoxes =
95
-                new Hashtable<String, JCheckBox>();
93
+        modeCheckBoxes = new HashMap<String, JCheckBox>();
96 94
 
97 95
         // Lay out all the boolean mode checkboxes
98 96
         for (int i = 0; i < booleanModes.length(); i++) {
@@ -104,10 +102,10 @@ public final class ChannelModesPane extends JPanel {
104 102
             String text;
105 103
             String tooltip;
106 104
 
107
-            if (channel.getConfigManager().hasOptionString("server",
108
-                    "mode" + mode)) {
109
-                text = channel.getConfigManager().
110
-                        getOption("server", "mode" + mode) + " [+" + mode + "]";
105
+            if (channel.getConfigManager().hasOptionString("server", "mode"
106
+                    + mode)) {
107
+                text = channel.getConfigManager().getOption("server", "mode"
108
+                        + mode) + " [+" + mode + "]";
111 109
             } else {
112 110
                 text = "Mode " + mode;
113 111
             }
@@ -139,7 +137,7 @@ public final class ChannelModesPane extends JPanel {
139 137
         }
140 138
 
141 139
         // Lay out all the parameter-requiring modes
142
-        modeInputs = new Hashtable<String, ParamModePanel>();
140
+        modeInputs = new HashMap<String, ParamModePanel>();
143 141
 
144 142
         for (int i = 0; i < paramModes.length(); i++) {
145 143
             final String mode = paramModes.substring(i, i + 1);

+ 2
- 2
src/com/dmdirc/addons/ui_swing/dialogs/serversetting/UserModesPane.java View File

@@ -28,7 +28,7 @@ import com.dmdirc.addons.ui_swing.UIUtilities;
28 28
 import com.dmdirc.parser.interfaces.Parser;
29 29
 
30 30
 import java.awt.Insets;
31
-import java.util.Hashtable;
31
+import java.util.HashMap;
32 32
 import java.util.Map;
33 33
 import java.util.TreeSet;
34 34
 
@@ -85,7 +85,7 @@ public final class UserModesPane extends JPanel {
85 85
         final String userModes = parser.getUserModes();
86 86
         final String ourUserModes = parser.getLocalClient().getModes();
87 87
 
88
-        modeCheckBoxes = new Hashtable<String, JCheckBox>();
88
+        modeCheckBoxes = new HashMap<String, JCheckBox>();
89 89
 
90 90
         // Lay out all the boolean mode checkboxes
91 91
         for (int i = 0; i < userModes.length(); i++) {

+ 3
- 3
src/com/dmdirc/addons/windowstatus/WindowStatusPlugin.java View File

@@ -46,7 +46,7 @@ import com.dmdirc.plugins.Plugin;
46 46
 import com.dmdirc.ui.WindowManager;
47 47
 import com.dmdirc.util.ReturnableThread;
48 48
 
49
-import java.util.Hashtable;
49
+import java.util.HashMap;
50 50
 import java.util.Map;
51 51
 import java.util.Map.Entry;
52 52
 
@@ -148,8 +148,8 @@ public final class WindowStatusPlugin extends Plugin implements ActionListener,
148 148
         } else if (current instanceof Channel) {
149 149
             final Channel frame = (Channel) current;
150 150
             final ChannelInfo chan = frame.getChannelInfo();
151
-            final Map<Integer, String> names = new Hashtable<Integer, String>();
152
-            final Map<Integer, Integer> types = new Hashtable<Integer, Integer>();
151
+            final Map<Integer, String> names = new HashMap<Integer, String>();
152
+            final Map<Integer, Integer> types = new HashMap<Integer, Integer>();
153 153
 
154 154
             textString.append(chan.getName());
155 155
             textString.append(" - Nicks: " + chan.getChannelClientCount() + " (");

Loading…
Cancel
Save