Browse Source

Tidy up icky method.

Change-Id: Icfb8b73ebd18e936523c291b6fc3ac0e9c1bb352
Reviewed-on: http://gerrit.dmdirc.com/3992
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
changes/92/3992/4
Chris Smith 9 years ago
parent
commit
d98a54ba5a

+ 14
- 34
windowstatus/src/com/dmdirc/addons/windowstatus/WindowStatusManager.java View File

40
 import com.dmdirc.parser.interfaces.ClientInfo;
40
 import com.dmdirc.parser.interfaces.ClientInfo;
41
 import com.dmdirc.plugins.PluginDomain;
41
 import com.dmdirc.plugins.PluginDomain;
42
 
42
 
43
-import java.util.HashMap;
44
-import java.util.Map;
45
 import java.util.concurrent.Callable;
43
 import java.util.concurrent.Callable;
46
 
44
 
47
 import javax.inject.Inject;
45
 import javax.inject.Inject;
164
     private String updateStatusChannel(final Channel frame) {
162
     private String updateStatusChannel(final Channel frame) {
165
         final StringBuilder textString = new StringBuilder();
163
         final StringBuilder textString = new StringBuilder();
166
         final ChannelInfo chan = frame.getChannelInfo();
164
         final ChannelInfo chan = frame.getChannelInfo();
167
-        final Map<Integer, String> names = new HashMap<>();
168
-        final Map<Integer, Integer> types = new HashMap<>();
169
 
165
 
170
         textString.append(chan.getName());
166
         textString.append(chan.getName());
171
         textString.append(" - Nicks: ");
167
         textString.append(" - Nicks: ");
172
         textString.append(chan.getChannelClientCount());
168
         textString.append(chan.getChannelClientCount());
173
         textString.append(" (");
169
         textString.append(" (");
174
 
170
 
171
+        final String channelUserModes = ' ' + chan.getParser().getChannelUserModes();
172
+        final int[] usersWithMode = new int[channelUserModes.length()];
175
         for (ChannelClientInfo client : chan.getChannelClients()) {
173
         for (ChannelClientInfo client : chan.getChannelClients()) {
176
-            String mode = client.getImportantModePrefix();
177
-            final Integer im = client.getClient().getParser()
178
-                    .getChannelUserModes().indexOf(mode);
179
-
180
-            if (!names.containsKey(im)) {
181
-                if (mode.isEmpty()) {
182
-                    if (shownone) {
183
-                        mode = nonePrefix;
184
-                    } else {
185
-                        continue;
186
-                    }
187
-                }
188
-                names.put(im, mode);
189
-            }
190
-
191
-            Integer count = types.get(im);
192
-
193
-            if (count == null) {
194
-                count = 1;
195
-            } else {
196
-                count++;
197
-            }
198
-            types.put(im, count);
174
+            final String mode = client.getImportantModePrefix();
175
+            final int index = channelUserModes.indexOf(mode);
176
+            usersWithMode[index]++;
199
         }
177
         }
200
 
178
 
201
         boolean isFirst = true;
179
         boolean isFirst = true;
202
-
203
-        for (Map.Entry<Integer, Integer> entry : types.entrySet()) {
204
-            if (isFirst) {
180
+        for (int i = channelUserModes.length() - 1; i >= 0; i--) {
181
+            final int count = usersWithMode[i];
182
+            if (count > 0 && (shownone || i > 0)) {
183
+                if (!isFirst) {
184
+                    textString.append(' ');
185
+                }
186
+                final String name = i > 0 ?
187
+                        Character.toString(channelUserModes.charAt(i)) : nonePrefix;
188
+                textString.append(count).append(name);
205
                 isFirst = false;
189
                 isFirst = false;
206
-            } else {
207
-                textString.append(' ');
208
             }
190
             }
209
-            textString.append(names.get(entry.getKey()));
210
-            textString.append(entry.getValue());
211
         }
191
         }
212
 
192
 
213
         textString.append(')');
193
         textString.append(')');

Loading…
Cancel
Save