Bläddra i källkod

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 år sedan
förälder
incheckning
d98a54ba5a
1 ändrade filer med 14 tillägg och 34 borttagningar
  1. 14
    34
      windowstatus/src/com/dmdirc/addons/windowstatus/WindowStatusManager.java

+ 14
- 34
windowstatus/src/com/dmdirc/addons/windowstatus/WindowStatusManager.java Visa fil

@@ -40,8 +40,6 @@ import com.dmdirc.parser.interfaces.ChannelInfo;
40 40
 import com.dmdirc.parser.interfaces.ClientInfo;
41 41
 import com.dmdirc.plugins.PluginDomain;
42 42
 
43
-import java.util.HashMap;
44
-import java.util.Map;
45 43
 import java.util.concurrent.Callable;
46 44
 
47 45
 import javax.inject.Inject;
@@ -164,50 +162,32 @@ public class WindowStatusManager implements ConfigChangeListener, SelectionListe
164 162
     private String updateStatusChannel(final Channel frame) {
165 163
         final StringBuilder textString = new StringBuilder();
166 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 166
         textString.append(chan.getName());
171 167
         textString.append(" - Nicks: ");
172 168
         textString.append(chan.getChannelClientCount());
173 169
         textString.append(" (");
174 170
 
171
+        final String channelUserModes = ' ' + chan.getParser().getChannelUserModes();
172
+        final int[] usersWithMode = new int[channelUserModes.length()];
175 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 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 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 193
         textString.append(')');

Laddar…
Avbryt
Spara